From dae4aae32878c2b5329e437d251e0315a32ea4f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 6 May 2021 20:24:21 +0200 Subject: [PATCH] Avoid rendenring an empty list in top links MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We've had an accessibility error reported by the Spanish "Portal Administración electrónica" (PAe). While I can't find any accessibility rule saying empty lists should be avoided, it looks like some screen readers report finding lists with 0 items, which is annoying. --- .../layout/top_links_component.html.erb | 2 +- app/components/layout/top_links_component.rb | 10 ++++++++++ .../layout/top_links_component_spec.rb | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 spec/components/layout/top_links_component_spec.rb diff --git a/app/components/layout/top_links_component.html.erb b/app/components/layout/top_links_component.html.erb index 7a5445ffc..0cc91b000 100644 --- a/app/components/layout/top_links_component.html.erb +++ b/app/components/layout/top_links_component.html.erb @@ -1,3 +1,3 @@ diff --git a/app/components/layout/top_links_component.rb b/app/components/layout/top_links_component.rb index 6d03e4430..ad45468c5 100644 --- a/app/components/layout/top_links_component.rb +++ b/app/components/layout/top_links_component.rb @@ -1,3 +1,13 @@ class Layout::TopLinksComponent < ApplicationComponent delegate :content_block, to: :helpers + + def render? + top_links_content_block.present? + end + + private + + def top_links_content_block + content_block("top_links", I18n.locale) + end end diff --git a/spec/components/layout/top_links_component_spec.rb b/spec/components/layout/top_links_component_spec.rb new file mode 100644 index 000000000..734258129 --- /dev/null +++ b/spec/components/layout/top_links_component_spec.rb @@ -0,0 +1,19 @@ +require "rails_helper" + +describe Layout::TopLinksComponent, type: :component do + describe "#render?" do + it "renders when a content block is defined" do + create(:site_customization_content_block, name: "top_links") + + render_inline Layout::TopLinksComponent.new + + expect(page).to have_css "ul" + end + + it "does not render when no content block is defined" do + render_inline Layout::TopLinksComponent.new + + expect(page).not_to have_css "ul" + end + end +end