Skip to content

Commit

Permalink
Fix markup (and therefore styling) of RTL history mode banner
Browse files Browse the repository at this point in the history
Right-to-left languages were displaying the government name in
an unusual way, treating the government name as translated text
even though it is still English. This commit fixes the text
direction, as well as setting the correct language for the text
snippet.

Before:
![to 2024 Sunak Conservative government 2022](https://github.com/user-attachments/assets/999781ba-8f6e-4c03-8f6d-00d9b8921c4c)

After:
![2022 to 2024 Sunak Conservative government](https://github.com/user-attachments/assets/d94c7979-03f3-46ca-bc97-4a86951a8b31)
  • Loading branch information
ChrisBAshton committed Oct 1, 2024
1 parent 8113059 commit d6fa599
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/presenters/content_item/political.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ def historically_political?
end

def publishing_government
content_item.dig(
str = content_item.dig(
"links", "government", 0, "title"
)
"<span lang='en' dir='ltr'>#{str}</span>"
end

private
Expand Down
5 changes: 4 additions & 1 deletion app/views/shared/_history_notice.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<% if content_item.historically_political? %>
<%= render "govuk_publishing_components/components/notice", {
title: t("shared.historically_political", government: content_item.publishing_government),
title: sanitize(
t("shared.historically_political", government: content_item.publishing_government),
attributes: %w(lang dir),
),
} %>
<% end %>
8 changes: 8 additions & 0 deletions test/integration/news_article_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ class NewsArticleTest < ActionDispatch::IntegrationTest
end
end

test "marks up government name correctly" do
setup_and_visit_content_item("news_article_history_mode_translated_arabic")

within ".govuk-notification-banner__content" do
assert page.has_css?("span[lang='en'][dir='ltr']", text: "2022 to 2024 Sunak Conservative government")
end
end

test "does not render with the single page notification button" do
setup_and_visit_content_item("news_article")
assert_not page.has_css?(".gem-c-single-page-notification-button")
Expand Down
2 changes: 1 addition & 1 deletion test/presenters/detailed_guide_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def schema_name
end

test "presents the title of the publishing government" do
assert_equal schema_item["details"]["government"]["title"], presented_item.publishing_government
assert_equal "<span lang='en' dir='ltr'>#{schema_item['details']['government']['title']}", presented_item.publishing_government
end

test "content can be historically political" do
Expand Down
2 changes: 1 addition & 1 deletion test/presenters/publication_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def schema_name
end

test "presents the title of the publishing government" do
assert_equal schema_item["links"]["government"][0]["title"], presented_item.publishing_government
assert_equal "<span lang='en' dir='ltr'>#{schema_item['links']['government'][0]['title']}</span>", presented_item.publishing_government
end

test "content can be historically political" do
Expand Down
2 changes: 1 addition & 1 deletion test/presenters/statistical_data_set_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def presented

test "presents the political fields" do
assert_equal expected["details"]["political"], presented.historically_political?
assert_equal expected["details"]["government"]["title"], presented.publishing_government
assert_equal "<span lang='en' dir='ltr'>#{expected['details']['government']['title']}</span>", presented.publishing_government
end
end
end

0 comments on commit d6fa599

Please sign in to comment.