From 391d1083e4229d4c79829dadf5651762b2a51d5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 3 Jul 2021 20:47:07 +0200 Subject: [PATCH] Don't render empty SDG tag list div The same way we don't render empty regular tags since commit 4d27bbeba. This way we avoid adding an empty `
` tag, which might have associated styles (in custom CONSUL installation styles, for instance) and thus break the layout --- app/components/sdg/tag_list_component.rb | 4 ++++ spec/components/sdg/tag_list_component_spec.rb | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/app/components/sdg/tag_list_component.rb b/app/components/sdg/tag_list_component.rb index 55b72c833..72b5b828e 100644 --- a/app/components/sdg/tag_list_component.rb +++ b/app/components/sdg/tag_list_component.rb @@ -7,6 +7,10 @@ class SDG::TagListComponent < ApplicationComponent @linkable = linkable end + def render? + record.sdg_goals.any? || record.sdg_targets.any? + end + private def goals_list diff --git a/spec/components/sdg/tag_list_component_spec.rb b/spec/components/sdg/tag_list_component_spec.rb index 723fdef4a..c262250c1 100644 --- a/spec/components/sdg/tag_list_component_spec.rb +++ b/spec/components/sdg/tag_list_component_spec.rb @@ -22,6 +22,14 @@ describe SDG::TagListComponent do expect(page).to have_link "target 3.2.1" end + it "does not render when there are no tags" do + record = build(:debate, sdg_goals: [], sdg_targets: []) + + render_inline SDG::TagListComponent.new(record) + + expect(page.native.inner_html).to be_empty + end + context "when linkable is false" do let(:component) { SDG::TagListComponent.new(debate, linkable: false) }