Create SDG goal component to render plain tags

This commit is contained in:
Senén Rodero Rodríguez
2021-01-28 11:53:09 +01:00
committed by taitus
parent 458e795ad4
commit 54843c1e53
3 changed files with 96 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
<% if tags.any? %>
<ul class="sdg-goal-tag-list">
<% tags.each do |tag| %>
<li><%= tag %></li>
<% end %>
</ul>
<% end %>

View File

@@ -0,0 +1,33 @@
class SDG::Goals::PlainTagListComponent < ApplicationComponent
include SDG::TagList
private
def record
record_or_name
end
def tags
[*goal_tags, see_more_link].compact
end
def see_more_link
options = super(goals)
link_to(*options) if options.present?
end
def goal_tags
goals.order(:code).limit(limit).map do |goal|
render SDG::Goals::IconComponent.new(goal)
end
end
def goals
record.sdg_goals
end
def i18n_namespace
"goals"
end
end

View File

@@ -0,0 +1,56 @@
require "rails_helper"
describe SDG::Goals::PlainTagListComponent, type: :component do
let(:debate) { create(:debate, sdg_goals: [SDG::Goal[1], SDG::Goal[3]]) }
let(:component) { SDG::Goals::PlainTagListComponent.new(debate) }
before do
Setting["feature.sdg"] = true
Setting["sdg.process.debates"] = true
end
it "does not render when the feature is disabled" do
Setting["feature.sdg"] = false
render_inline component
expect(page).not_to have_css "li"
end
it "does not render when the SDG process feature is disabled" do
Setting["sdg.process.debates"] = false
render_inline component
expect(page).not_to have_css "li"
end
it "renders a list of goals" do
render_inline component
expect(page).to have_css "li", count: 2
end
it "renders icons for each goal" do
render_inline component
expect(page).to have_selector ".sdg-goal-icon", count: 2
end
it "orders goals by code" do
render_inline component
expect(page.first(".sdg-goal-icon")[:alt]).to eq "1. No Poverty"
end
it "renders a link for more goals when out of limit" do
component = SDG::Goals::PlainTagListComponent.new(debate, limit: 1)
render_inline component
expect(page).to have_selector ".sdg-goal-icon"
expect(page).to have_link "1+",
title: "One more goal",
href: "/debates/#{debate.to_param}"
end
end