Merge pull request #4305 from consul/sdg_icons_in_index

Add SDG icons to related records
This commit is contained in:
Javi Martín
2021-01-11 13:07:11 +01:00
committed by GitHub
266 changed files with 353 additions and 51 deletions

View File

@@ -0,0 +1,25 @@
require "rails_helper"
describe SDG::Goals::FilterLinksComponent, type: :component do
before do
Setting["feature.sdg"] = true
Setting["sdg.process.debates"] = true
Setting["sdg.process.proposals"] = true
end
it "renders a title" do
component = SDG::Goals::FilterLinksComponent.new("Debate")
render_inline component
expect(page).to have_content "Filters by SDG"
end
it "renders all goals" do
component = SDG::Goals::FilterLinksComponent.new("Proposal")
render_inline component
expect(page).to have_css ".sdg-goal-icon", count: 17
end
end

View File

@@ -0,0 +1,19 @@
require "rails_helper"
describe SDG::Goals::IconComponent do
describe "#image_path" do
let(:component) { SDG::Goals::IconComponent.new(SDG::Goal[8]) }
it "returns icons for the first fallback language with icons" do
allow(I18n).to receive(:fallbacks).and_return({ en: [:es, :de] })
expect(component.image_path).to eq "sdg/es/goal_8.png"
end
it "returns the default icons when no fallback language has icons" do
allow(I18n).to receive(:fallbacks).and_return({})
expect(component.image_path).to eq "sdg/default/goal_8.png"
end
end
end

View File

@@ -0,0 +1,75 @@
require "rails_helper"
describe SDG::Goals::TagListComponent, type: :component do
let(:debate) { create(:debate, sdg_goals: [SDG::Goal[1], SDG::Goal[3]]) }
let(:component) { SDG::Goals::TagListComponent.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 links for each goal" do
render_inline component
expect(page).to have_selector "a", count: 2
expect(page).to have_link "1. No Poverty",
title: "See all Debates related to goal 1",
href: "/debates?advanced_search#{CGI.escape("[goal]")}=1"
expect(page).to have_link "3. Good Health and Well-Being",
title: "See all Debates related to goal 3",
href: "/debates?advanced_search#{CGI.escape("[goal]")}=3"
end
it "orders goals by code" do
render_inline component
expect(page.first("a")[:title]).to end_with "goal 1"
end
it "renders a link for more goals when out of limit" do
component = SDG::Goals::TagListComponent.new(debate, limit: 1)
render_inline component
expect(page).to have_selector "a", count: 2
expect(page).to have_link "1. No Poverty"
expect(page).to have_link "1+",
title: "One more goal",
href: "/debates/#{debate.to_param}"
end
context "given a class name" do
let(:component) { SDG::Goals::TagListComponent.new("Debate") }
it "renders all goals ordered by code" do
render_inline component
expect(page).to have_selector "li", count: 17
expect(page.first("a")[:title]).to end_with "goal 1"
expect(page.all("a").last[:title]).to end_with "goal 17"
end
end
end

View File

@@ -4,6 +4,7 @@ describe SDGManagement::MenuComponent, type: :component do
let(:component) { SDGManagement::MenuComponent.new }
before do
Setting["feature.sdg"] = true
Setting["sdg.process.budgets"] = true
Setting["sdg.process.debates"] = true
Setting["sdg.process.legislation"] = true