Fix exception using locales with no help images
In commit 905ac48bb we activated exceptions when assets were not found,
in order to detect places where we were trying to load non-existent
images.
We got an exception for that reason: we were loading images based on the
current locale, but for some locales there was no images.
We're now using fallbacks and loading another image when the original
one isn't available.
Note we're copying the English images to images with a generic name for
the case where there's no fallback with an image. We're copying the
files instead of using symbolic links to make sure they can be
overwritten independently in other CONSUL installations.
Also note we're updating the HTML so the section gets the ID instead of
the header. That way the system test is simple.
This commit is contained in:
BIN
app/assets/images/help/budgets.png
Normal file
BIN
app/assets/images/help/budgets.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
BIN
app/assets/images/help/proposals.png
Normal file
BIN
app/assets/images/help/proposals.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
@@ -1,8 +1,6 @@
|
||||
<div class="row section-content">
|
||||
<div class="small-12 column">
|
||||
<h3 id="<%= section %>" data-magellan-target="<%= section %>">
|
||||
<%= t("pages.help.#{section}.title") %>
|
||||
</h3>
|
||||
<div class="small-12 column" id="<%= section %>" data-magellan-target="<%= section %>">
|
||||
<h3><%= t("pages.help.#{section}.title") %></h3>
|
||||
|
||||
<%= content %>
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= render Pages::Help::SectionComponent.new("budgets", "help/budgets_#{I18n.locale}.png") do %>
|
||||
<%= render Pages::Help::SectionComponent.new("budgets") do %>
|
||||
<p>
|
||||
<%= sanitize(t("pages.help.budgets.description",
|
||||
link: link_to(t("pages.help.budgets.link"), budgets_path))) %>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= render Pages::Help::SectionComponent.new("debates", "help/debates.png") do %>
|
||||
<%= render Pages::Help::SectionComponent.new("debates") do %>
|
||||
<p>
|
||||
<%= sanitize(t("pages.help.debates.description",
|
||||
org: setting["org_name"],
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= render Pages::Help::SectionComponent.new("processes", nil) do %>
|
||||
<%= render Pages::Help::SectionComponent.new("processes") do %>
|
||||
<p>
|
||||
<% link = link_to(t("pages.help.processes.link"), legislation_processes_path) %>
|
||||
<%= sanitize(t("pages.help.processes.description", link: link)) %>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= render Pages::Help::SectionComponent.new("proposals", "help/proposals_#{I18n.locale}.png") do %>
|
||||
<%= render Pages::Help::SectionComponent.new("proposals") do %>
|
||||
<p>
|
||||
<%= sanitize(t("pages.help.proposals.description",
|
||||
link: link_to(t("pages.help.proposals.link"), proposals_path))) %>
|
||||
|
||||
43
spec/components/pages/help/section_component_spec.rb
Normal file
43
spec/components/pages/help/section_component_spec.rb
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user