diff --git a/app/assets/stylesheets/sdg/tag_list.scss b/app/assets/stylesheets/sdg/tag_list.scss index f242300df..2a0018a1f 100644 --- a/app/assets/stylesheets/sdg/tag_list.scss +++ b/app/assets/stylesheets/sdg/tag_list.scss @@ -11,18 +11,23 @@ .sdg-target-tag-list { @extend %tags; - a:not(.more-targets) { + a:not(.more-targets), + span { color: $white; } @each $code, $color in $sdg-colors { - [data-code^="#{$code}"] { + a[data-code^="#{$code}"] { background-color: $color; &:hover { background-color: darken($color, 10%); } } + + span[data-code^="#{$code}"] { + background-color: $color; + } } } } diff --git a/app/components/sdg/tag_list_component.html.erb b/app/components/sdg/tag_list_component.html.erb index 54f477b4c..3c9a5d7b5 100644 --- a/app/components/sdg/tag_list_component.html.erb +++ b/app/components/sdg/tag_list_component.html.erb @@ -1,4 +1,4 @@
diff --git a/app/components/sdg/tag_list_component.rb b/app/components/sdg/tag_list_component.rb index 95d15a542..55b72c833 100644 --- a/app/components/sdg/tag_list_component.rb +++ b/app/components/sdg/tag_list_component.rb @@ -1,8 +1,27 @@ class SDG::TagListComponent < ApplicationComponent - attr_reader :record, :limit + attr_reader :record, :limit, :linkable - def initialize(record, limit: nil) + def initialize(record, limit: nil, linkable: true) @record = record @limit = limit + @linkable = linkable end + + private + + def goals_list + if linkable + render SDG::Goals::TagListComponent.new(record, limit: limit) + else + render SDG::Goals::PlainTagListComponent.new(record, limit: limit) + end + end + + def targets_list + if linkable + render SDG::Targets::TagListComponent.new(record, limit: limit) + else + render SDG::Targets::PlainTagListComponent.new(record, limit: limit) + end + end end diff --git a/spec/components/sdg/tag_list_component_spec.rb b/spec/components/sdg/tag_list_component_spec.rb new file mode 100644 index 000000000..7267f5efc --- /dev/null +++ b/spec/components/sdg/tag_list_component_spec.rb @@ -0,0 +1,39 @@ +require "rails_helper" + +describe SDG::TagListComponent, type: :component do + let(:debate) do + create(:debate, + sdg_goals: [SDG::Goal[3]], + sdg_targets: [SDG::Target[3.2], create(:sdg_local_target, code: "3.2.1")] + ) + end + let(:component) { SDG::TagListComponent.new(debate) } + + before do + Setting["feature.sdg"] = true + Setting["sdg.process.debates"] = true + end + + it "renders tags list with links" do + render_inline component + + expect(page).to have_link "3. Good Health and Well-Being" + expect(page).to have_link "target 3.2" + expect(page).to have_link "target 3.2.1" + end + + context "when linkable is false" do + let(:component) { SDG::TagListComponent.new(debate, linkable: false) } + + it "renders plain tags list" do + render_inline component + + expect(page.find(".sdg-goal-icon")[:alt]).to eq "3. Good Health and Well-Being" + expect(page).to have_content "target 3.2" + expect(page).to have_content "target 3.2.1" + expect(page).not_to have_link "3. Good Health and Well-Being" + expect(page).not_to have_link "target 3.2" + expect(page).not_to have_link "target 3.2.1" + end + end +end