diff --git a/app/assets/images/help/budgets.png b/app/assets/images/help/budgets.png new file mode 100644 index 000000000..1c1002145 Binary files /dev/null and b/app/assets/images/help/budgets.png differ diff --git a/app/assets/images/help/proposals.png b/app/assets/images/help/proposals.png new file mode 100644 index 000000000..60357f222 Binary files /dev/null and b/app/assets/images/help/proposals.png differ diff --git a/app/components/pages/help/section_component.html.erb b/app/components/pages/help/section_component.html.erb index a577d8026..d21f31333 100644 --- a/app/components/pages/help/section_component.html.erb +++ b/app/components/pages/help/section_component.html.erb @@ -1,8 +1,6 @@
-
-

- <%= t("pages.help.#{section}.title") %> -

+
+

<%= t("pages.help.#{section}.title") %>

<%= content %> diff --git a/app/components/pages/help/section_component.rb b/app/components/pages/help/section_component.rb index 3d15072c0..fed9ce2a9 100644 --- a/app/components/pages/help/section_component.rb +++ b/app/components/pages/help/section_component.rb @@ -1,8 +1,19 @@ class Pages::Help::SectionComponent < ApplicationComponent - attr_reader :section, :image_path + attr_reader :section - def initialize(section, image_path = nil) + def initialize(section) @section = section - @image_path = image_path + end + + def image_path + locale_with_image = Array(I18n.fallbacks[I18n.locale]).find do |locale| + AssetFinder.find_asset("help/#{section}_#{locale}.png") + end + + if locale_with_image + "help/#{section}_#{locale_with_image}.png" + elsif AssetFinder.find_asset("help/#{section}.png") + "help/#{section}.png" + end end end diff --git a/app/views/pages/help/_budgets.html.erb b/app/views/pages/help/_budgets.html.erb index 00f086054..21d8c53d0 100644 --- a/app/views/pages/help/_budgets.html.erb +++ b/app/views/pages/help/_budgets.html.erb @@ -1,4 +1,4 @@ -<%= render Pages::Help::SectionComponent.new("budgets", "help/budgets_#{I18n.locale}.png") do %> +<%= render Pages::Help::SectionComponent.new("budgets") do %>

<%= sanitize(t("pages.help.budgets.description", link: link_to(t("pages.help.budgets.link"), budgets_path))) %> diff --git a/app/views/pages/help/_debates.html.erb b/app/views/pages/help/_debates.html.erb index ebc3800d0..db380a20e 100644 --- a/app/views/pages/help/_debates.html.erb +++ b/app/views/pages/help/_debates.html.erb @@ -1,4 +1,4 @@ -<%= render Pages::Help::SectionComponent.new("debates", "help/debates.png") do %> +<%= render Pages::Help::SectionComponent.new("debates") do %>

<%= sanitize(t("pages.help.debates.description", org: setting["org_name"], diff --git a/app/views/pages/help/_processes.html.erb b/app/views/pages/help/_processes.html.erb index 388048a79..18178f385 100644 --- a/app/views/pages/help/_processes.html.erb +++ b/app/views/pages/help/_processes.html.erb @@ -1,4 +1,4 @@ -<%= render Pages::Help::SectionComponent.new("processes", nil) do %> +<%= render Pages::Help::SectionComponent.new("processes") do %>

<% link = link_to(t("pages.help.processes.link"), legislation_processes_path) %> <%= sanitize(t("pages.help.processes.description", link: link)) %> diff --git a/app/views/pages/help/_proposals.html.erb b/app/views/pages/help/_proposals.html.erb index fd9cf18bc..ef6875e67 100644 --- a/app/views/pages/help/_proposals.html.erb +++ b/app/views/pages/help/_proposals.html.erb @@ -1,4 +1,4 @@ -<%= render Pages::Help::SectionComponent.new("proposals", "help/proposals_#{I18n.locale}.png") do %> +<%= render Pages::Help::SectionComponent.new("proposals") do %>

<%= sanitize(t("pages.help.proposals.description", link: link_to(t("pages.help.proposals.link"), proposals_path))) %> diff --git a/spec/components/pages/help/section_component_spec.rb b/spec/components/pages/help/section_component_spec.rb new file mode 100644 index 000000000..f116f9579 --- /dev/null +++ b/spec/components/pages/help/section_component_spec.rb @@ -0,0 +1,43 @@ +require "rails_helper" + +describe Pages::Help::SectionComponent, type: :component do + describe "#image_path" do + it "returns the image for the first fallback language with an image" do + allow(I18n).to receive(:fallbacks).and_return({ en: [:es, :de] }) + + component = Pages::Help::SectionComponent.new("proposals") + + expect(component.image_path).to eq "help/proposals_es.png" + end + + it "returns the default image when no fallback language has an image" do + allow(I18n).to receive(:fallbacks).and_return({}) + + component = Pages::Help::SectionComponent.new("proposals") + + expect(component.image_path).to eq "help/proposals.png" + end + + it "returns nil when there is no image" do + component = Pages::Help::SectionComponent.new("polls") + + expect(component.image_path).to be nil + end + end + + describe "image tag" do + it "renders an image on sections with an image" do + render_inline Pages::Help::SectionComponent.new("debates") + + expect(page).to have_selector "img" + expect(page).to have_selector "figure" + end + + it "does not render an image tag when there is no image" do + render_inline Pages::Help::SectionComponent.new("processes") + + expect(page).not_to have_selector "img" + expect(page).not_to have_selector "figure" + end + end +end diff --git a/spec/system/help_page_spec.rb b/spec/system/help_page_spec.rb index 7c721ec41..5b1a365a7 100644 --- a/spec/system/help_page_spec.rb +++ b/spec/system/help_page_spec.rb @@ -26,6 +26,14 @@ describe "Help page" do end end + scenario "renders the default image for locales with no images" do + Setting["feature.help_page"] = true + + visit help_path(locale: :de) + + within("#proposals") { expect(page).to have_css "img" } + end + scenario "renders the SDG help page link when the feature is enabled" do Setting["feature.help_page"] = true Setting["feature.sdg"] = true