diff --git a/app/presenters/content_item/single_page_notification_button.rb b/app/presenters/content_item/single_page_notification_button.rb
index a048e1f8c..d7d10e6b1 100644
--- a/app/presenters/content_item/single_page_notification_button.rb
+++ b/app/presenters/content_item/single_page_notification_button.rb
@@ -8,8 +8,12 @@ module SinglePageNotificationButton
5f9c6c15-7631-11e4-a3cb-005056011aef
].freeze
- def has_single_page_notifications?
- !EXEMPTION_LIST.include? content_item["content_id"]
+ def page_is_on_exemption_list?
+ EXEMPTION_LIST.include? content_item["content_id"]
+ end
+
+ def display_single_page_notification_button?
+ !page_is_on_exemption_list? && I18n.locale == :en
end
end
end
diff --git a/app/presenters/content_item_presenter.rb b/app/presenters/content_item_presenter.rb
index 1d1a7187c..848b58773 100644
--- a/app/presenters/content_item_presenter.rb
+++ b/app/presenters/content_item_presenter.rb
@@ -47,7 +47,7 @@ def requesting_a_service_sign_in_page?
false
end
- def has_single_page_notifications?
+ def display_single_page_notification_button?
false
end
diff --git a/app/presenters/document_collection/signup_link.rb b/app/presenters/document_collection/signup_link.rb
new file mode 100644
index 000000000..e6b509551
--- /dev/null
+++ b/app/presenters/document_collection/signup_link.rb
@@ -0,0 +1,11 @@
+module DocumentCollection
+ module SignupLink
+ def show_email_signup_link?
+ taxonomy_topic_email_override_base_path.present? && I18n.locale == :en
+ end
+
+ def taxonomy_topic_email_override_base_path
+ content_item.dig("links", "taxonomy_topic_email_override", 0, "base_path")
+ end
+ end
+end
diff --git a/app/presenters/document_collection_presenter.rb b/app/presenters/document_collection_presenter.rb
index d94fb03b1..67440920c 100644
--- a/app/presenters/document_collection_presenter.rb
+++ b/app/presenters/document_collection_presenter.rb
@@ -5,6 +5,7 @@ class DocumentCollectionPresenter < ContentItemPresenter
include ContentItem::TitleAndContext
include ContentItem::ContentsList
include ContentItem::SinglePageNotificationButton
+ include DocumentCollection::SignupLink
def contents_items
groups.map do |group|
@@ -54,10 +55,6 @@ def group_heading(group)
)
end
- def taxonomy_topic_email_override_base_path
- content_item.dig("links", "taxonomy_topic_email_override", 0, "base_path")
- end
-
private
def group_document_link_public_updated_at(link)
diff --git a/app/views/shared/_document_collections_email_signup.html.erb b/app/views/shared/_document_collections_email_signup.html.erb
index df50c701c..136912b68 100644
--- a/app/views/shared/_document_collections_email_signup.html.erb
+++ b/app/views/shared/_document_collections_email_signup.html.erb
@@ -1,4 +1,4 @@
-<% if @content_item.taxonomy_topic_email_override_base_path.present? %>
+<% if @content_item.show_email_signup_link? %>
-<% else %>
+<% elsif @content_item.display_single_page_notification_button? %>
<%= render 'shared/single_page_notification_button', {
content_item: @content_item,
skip_account: @has_govuk_account ? "false" : "true"
diff --git a/app/views/shared/_published_dates_with_notification_button.html.erb b/app/views/shared/_published_dates_with_notification_button.html.erb
index 96937c742..1d6f4a336 100644
--- a/app/views/shared/_published_dates_with_notification_button.html.erb
+++ b/app/views/shared/_published_dates_with_notification_button.html.erb
@@ -10,7 +10,7 @@
- <% if @content_item.has_single_page_notifications? %>
+ <% if @content_item.display_single_page_notification_button? %>
<%= I18n.t("common.email_and_print_link") %>
<% else %>
<%= I18n.t("common.print_link") %>
@@ -33,7 +33,7 @@
section: "Footer"
}
}
- } if @content_item.has_single_page_notifications? %>
+ } if @content_item.display_single_page_notification_button? %>
<%= render "govuk_publishing_components/components/print_link", {
margin_top: 0,
margin_bottom: 8,
diff --git a/app/views/shared/_single_page_notification_button.html.erb b/app/views/shared/_single_page_notification_button.html.erb
index 64be0a5a1..9ec9afdba 100644
--- a/app/views/shared/_single_page_notification_button.html.erb
+++ b/app/views/shared/_single_page_notification_button.html.erb
@@ -1,24 +1,26 @@
-<%
- default_ga4_data_attributes = {
- module: "ga4-link-tracker",
- ga4_link: {
- event_name: "navigation",
- type: "subscribe",
- index_link: 1,
- index_total: 2,
- section: "Top"
+<% if @content_item.display_single_page_notification_button? %>
+ <%
+ default_ga4_data_attributes = {
+ module: "ga4-link-tracker",
+ ga4_link: {
+ event_name: "navigation",
+ type: "subscribe",
+ index_link: 1,
+ index_total: 2,
+ section: "Top"
+ }
}
- }
-%>
+ %>
-<% ga4_data_attributes = ga4_data_attributes || default_ga4_data_attributes %>
-<% skip_account = skip_account || "false" %>
+ <% ga4_data_attributes = ga4_data_attributes || default_ga4_data_attributes %>
+ <% skip_account = skip_account || "false" %>
-<%= render 'govuk_publishing_components/components/single_page_notification_button', {
- base_path: @content_item.base_path,
- js_enhancement: @has_govuk_account,
- ga4_data_attributes: ga4_data_attributes,
- margin_bottom: 6,
- button_location: "top",
- skip_account: skip_account,
-} if @content_item.has_single_page_notifications? %>
+ <%= render 'govuk_publishing_components/components/single_page_notification_button', {
+ base_path: @content_item.base_path,
+ js_enhancement: @has_govuk_account,
+ ga4_data_attributes: ga4_data_attributes,
+ margin_bottom: 6,
+ button_location: "top",
+ skip_account: skip_account,
+ } %>
+<% end %>
diff --git a/test/integration/call_for_evidence_test.rb b/test/integration/call_for_evidence_test.rb
index da0bb628b..8ba4e56b1 100644
--- a/test/integration/call_for_evidence_test.rb
+++ b/test/integration/call_for_evidence_test.rb
@@ -371,11 +371,16 @@ def teardown
assert page.has_css?("a", text: "Twitter")
end
- test "renders with the single page notification button" do
+ test "renders with the single page notification button on English language pages" do
setup_and_visit_content_item("open_call_for_evidence")
assert page.has_css?(".gem-c-single-page-notification-button")
end
+ test "does not render the single page notification button on foreign language pages" do
+ setup_and_visit_content_item("open_call_for_evidence", "locale" => "cy")
+ assert_not page.has_css?(".gem-c-single-page-notification-button")
+ end
+
test "does not render the single page notification button on exempt pages" do
setup_and_visit_notification_exempt_page("open_call_for_evidence")
assert_not page.has_css?(".gem-c-single-page-notification-button")
diff --git a/test/integration/consultation_test.rb b/test/integration/consultation_test.rb
index f54d2ee72..895a3d3d9 100644
--- a/test/integration/consultation_test.rb
+++ b/test/integration/consultation_test.rb
@@ -372,7 +372,7 @@ class ConsultationTest < ActionDispatch::IntegrationTest
assert page.has_css?("a", text: "Twitter")
end
- test "renders with the single page notification button" do
+ test "renders with the single page notification button on English language pages" do
setup_and_visit_content_item("open_consultation")
assert page.has_css?(".gem-c-single-page-notification-button")
@@ -391,4 +391,9 @@ class ConsultationTest < ActionDispatch::IntegrationTest
setup_and_visit_notification_exempt_page("open_consultation")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
+
+ test "does not render the single page notification button on foreign language pages" do
+ setup_and_visit_notification_exempt_page("open_consultation", "locale" => "cy")
+ assert_not page.has_css?(".gem-c-single-page-notification-button")
+ end
end
diff --git a/test/integration/detailed_guide_test.rb b/test/integration/detailed_guide_test.rb
index e46d662bc..be34f53fd 100644
--- a/test/integration/detailed_guide_test.rb
+++ b/test/integration/detailed_guide_test.rb
@@ -82,7 +82,7 @@ class DetailedGuideTest < ActionDispatch::IntegrationTest
assert_not_equal faq_schema["mainEntity"], []
end
- test "renders with the single page notification button" do
+ test "renders with the single page notification button on English language pages" do
setup_and_visit_content_item("detailed_guide")
assert page.has_css?(".gem-c-single-page-notification-button")
@@ -101,4 +101,9 @@ class DetailedGuideTest < ActionDispatch::IntegrationTest
setup_and_visit_notification_exempt_page("detailed_guide")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
+
+ test "does not render the single page notification button on foreign language pages" do
+ setup_and_visit_notification_exempt_page("detailed_guide", "locale" => "cy")
+ assert_not page.has_css?(".gem-c-single-page-notification-button")
+ end
end
diff --git a/test/integration/document_collection/email_notifications_test.rb b/test/integration/document_collection/email_notifications_test.rb
index b2d272dbe..b716c8fd1 100644
--- a/test/integration/document_collection/email_notifications_test.rb
+++ b/test/integration/document_collection/email_notifications_test.rb
@@ -20,8 +20,9 @@ def email_alert_frontend_signup_endpoint_enforce_account
"/email/subscriptions/single-page/new"
end
- test "renders a signup link if the document collection has a taxonomy topic email override" do
+ test "renders a signup link if the document collection has a taxonomy topic email override and the page is in English" do
content_item = get_content_example("document_collection")
+ content_item["locale"] = "en"
content_item["links"]["taxonomy_topic_email_override"] = [{ "base_path" => taxonomy_topic_base_path.to_s }]
stub_content_store_has_item(content_item["base_path"], content_item)
visit_with_cachebust(content_item["base_path"])
@@ -31,7 +32,7 @@ def email_alert_frontend_signup_endpoint_enforce_account
end
test "renders the single page notification button with a form action of email-alert-frontend's non account signup endpoint" do
- setup_and_visit_content_item("document_collection")
+ setup_and_visit_content_item("document_collection", "locale" => "en")
form = page.find("form.gem-c-single-page-notification-button")
assert_match(email_alert_frontend_signup_endpoint_no_account, form["action"])
@@ -55,7 +56,7 @@ def email_alert_frontend_signup_endpoint_enforce_account
# Need to use Rack as Selenium, the default driver, doesn't provide header access, and we need to set a govuk_account_session header
Capybara.current_driver = :rack_test
mock_logged_in_session
- setup_and_visit_content_item("document_collection")
+ setup_and_visit_content_item("document_collection", "locale" => "en")
form = page.find("form.gem-c-single-page-notification-button")
assert_match(email_alert_frontend_signup_endpoint_enforce_account, form["action"])
@@ -78,5 +79,19 @@ def email_alert_frontend_signup_endpoint_enforce_account
# reset back to default driver
Capybara.use_default_driver
end
+
+ test "does not render the single page notification button if the page is in a foreign language" do
+ setup_and_visit_content_item("document_collection", "locale" => "cy")
+ assert_not page.has_css?(".gem-c-single-page-notification-button")
+ end
+
+ test "does not render the email signup link if the page is in a foreign language" do
+ content_item = get_content_example("document_collection")
+ content_item["links"]["taxonomy_topic_email_override"] = [{ "base_path" => taxonomy_topic_base_path.to_s }]
+ content_item["locale"] = "cy"
+ stub_content_store_has_item(content_item["base_path"], content_item)
+ visit_with_cachebust(content_item["base_path"])
+ assert_not page.has_css?(".gem-c-signup-link")
+ end
end
end
diff --git a/test/integration/publication_test.rb b/test/integration/publication_test.rb
index f67875101..35a621d9e 100644
--- a/test/integration/publication_test.rb
+++ b/test/integration/publication_test.rb
@@ -269,7 +269,7 @@ class PublicationTest < ActionDispatch::IntegrationTest
])
end
- test "renders with the single page notification button" do
+ test "renders with the single page notification button on English language pages" do
setup_and_visit_content_item("publication")
assert page.has_css?(".gem-c-single-page-notification-button")
@@ -289,6 +289,11 @@ class PublicationTest < ActionDispatch::IntegrationTest
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
+ test "does not render the single page notification button on foreign language pages" do
+ setup_and_visit_content_item("publication", "locale" => "cy")
+ assert_not page.has_css?(".gem-c-single-page-notification-button")
+ end
+
test "adds the noindex meta tag to '/government/publications/pension-credit-claim-form--2'" do
overrides = { "base_path" => "/government/publications/pension-credit-claim-form--2" }
setup_and_visit_content_item("publication-with-featured-attachments", overrides)
diff --git a/test/presenters/call_for_evidence_presenter_test.rb b/test/presenters/call_for_evidence_presenter_test.rb
index fa8eb6834..ca80f8919 100644
--- a/test/presenters/call_for_evidence_presenter_test.rb
+++ b/test/presenters/call_for_evidence_presenter_test.rb
@@ -152,11 +152,22 @@ def schema_name
assert_equal "https://twitter.com/share?url=https%3A%2F%2Fwww.test.gov.uk%2Fgovernment%2Fcall_for_evidence%2Fyouth-vaping-call-for-evidence&text=Youth%20Vaping", presented_item("open_call_for_evidence").share_links[1][:href]
end
- test "presents the single page notification button" do
- schema = schema_item("open_call_for_evidence")
- presented = presented_item("open_call_for_evidence", schema)
+ test "displays the single page notification button on English pages" do
+ I18n.with_locale("en") do
+ schema = schema_item("open_call_for_evidence")
+ presented = presented_item("open_call_for_evidence", schema)
+
+ assert presented.display_single_page_notification_button?
+ end
+ end
+
+ test "does not display the single page notification button on foreign language pages" do
+ I18n.with_locale("fr") do
+ schema = schema_item("open_call_for_evidence")
+ presented = presented_item("open_call_for_evidence", schema)
- assert presented.has_single_page_notifications?
+ assert_not presented.display_single_page_notification_button?
+ end
end
end
end
diff --git a/test/presenters/consultation_presenter_test.rb b/test/presenters/consultation_presenter_test.rb
index 2de445a3c..630b620e5 100644
--- a/test/presenters/consultation_presenter_test.rb
+++ b/test/presenters/consultation_presenter_test.rb
@@ -171,11 +171,20 @@ def schema_name
assert_equal "https://twitter.com/share?url=https%3A%2F%2Fwww.test.gov.uk%2Fgovernment%2Fconsultations%2Fpostgraduate-doctoral-loans&text=Postgraduate%20doctoral%20loans", presented_item("open_consultation").share_links[1][:href]
end
- test "presents the single page notification button" do
- schema = schema_item("open_consultation")
- presented = presented_item("open_consultation", schema)
-
- assert presented.has_single_page_notifications?
+ test "displays the single page notification button on English pages" do
+ I18n.with_locale("en") do
+ schema = schema_item("open_consultation")
+ presented = presented_item("open_consultation", schema)
+ assert presented.display_single_page_notification_button?
+ end
+ end
+
+ test "does not display the single page notification button on foreign language pages" do
+ I18n.with_locale("fr") do
+ schema = schema_item("open_consultation")
+ presented = presented_item("open_consultation", schema)
+ assert_not presented.display_single_page_notification_button?
+ end
end
end
end
diff --git a/test/presenters/detailed_guide_presenter_test.rb b/test/presenters/detailed_guide_presenter_test.rb
index 439e6dd66..26d384318 100644
--- a/test/presenters/detailed_guide_presenter_test.rb
+++ b/test/presenters/detailed_guide_presenter_test.rb
@@ -84,8 +84,17 @@ def schema_name
assert_equal presented.logo, expected
end
- test "presents the single page notification button" do
- presented = presented_item("national_applicability_detailed_guide")
- assert presented.has_single_page_notifications?
+ test "displays the single page notification button on English pages" do
+ I18n.with_locale("en") do
+ presented = presented_item("national_applicability_detailed_guide")
+ assert presented.display_single_page_notification_button?
+ end
+ end
+
+ test "does not display the single page notification button on foreign language pages" do
+ I18n.with_locale("fr") do
+ presented = presented_item("national_applicability_detailed_guide")
+ assert_not presented.display_single_page_notification_button?
+ end
end
end
diff --git a/test/presenters/document_collection/signup_link_test.rb b/test/presenters/document_collection/signup_link_test.rb
new file mode 100644
index 000000000..30f8acdb2
--- /dev/null
+++ b/test/presenters/document_collection/signup_link_test.rb
@@ -0,0 +1,47 @@
+require "test_helper"
+
+class DocumentCollectionSignupLinkTest < ActiveSupport::TestCase
+ class DummyContentItem
+ include DocumentCollection::SignupLink
+ attr_accessor :content_item
+
+ def initialize
+ @content_item = {}
+ @content_item["links"] = {}
+ end
+ end
+
+ test "taxonomy_topic_email_override_base_path returns nil if field is empty" do
+ item = DummyContentItem.new
+ assert_nil item.taxonomy_topic_email_override_base_path
+ end
+
+ test "show_email_signup_link? returns false if there is no linked taxonomy_topic_email_override" do
+ item = DummyContentItem.new
+ assert_equal false, item.show_email_signup_link?
+ end
+
+ test "show_email_signup_link? returns false if the locale is not en" do
+ I18n.with_locale("fr") do
+ item = DummyContentItem.new
+ item.content_item["links"]["taxonomy_topic_email_override"] = [
+ {
+ "base_path" => "/a-taxonomy-topic",
+ },
+ ]
+ assert_equal false, item.show_email_signup_link?
+ end
+ end
+
+ test "show_email_signup_link? returns true if there is a linked taxonomy_topic_email_override and the locale is en" do
+ I18n.with_locale("en") do
+ item = DummyContentItem.new
+ item.content_item["links"]["taxonomy_topic_email_override"] = [
+ {
+ "base_path" => "/a-taxonomy-topic",
+ },
+ ]
+ assert item.show_email_signup_link?
+ end
+ end
+end
diff --git a/test/presenters/document_collection_presenter_test.rb b/test/presenters/document_collection_presenter_test.rb
index 35d5c13f2..efe9d7cd2 100644
--- a/test/presenters/document_collection_presenter_test.rb
+++ b/test/presenters/document_collection_presenter_test.rb
@@ -119,6 +119,18 @@ class PresentedDocumentCollection < TestCase
assert_nil nil, public_updated_at
end
end
+
+ test "displays the single page notification button on English pages" do
+ I18n.with_locale("en") do
+ assert presented_item.display_single_page_notification_button?
+ end
+ end
+
+ test "does not display the single page notification button on foreign language pages" do
+ I18n.with_locale("fr") do
+ assert_not presented_item.display_single_page_notification_button?
+ end
+ end
end
class GroupWithMissingDocument < TestCase
diff --git a/test/presenters/publication_presenter_test.rb b/test/presenters/publication_presenter_test.rb
index 7f0f99f34..2a85d1414 100644
--- a/test/presenters/publication_presenter_test.rb
+++ b/test/presenters/publication_presenter_test.rb
@@ -74,9 +74,18 @@ def schema_name
assert_equal(presented.national_applicability[:wales][:alternative_url], "http://wales.gov.uk/topics/statistics/headlines/housing2012/121025/?lang=en")
end
- test "presents the single page notification button" do
- presented = presented_item("statistics_publication")
- assert presented.has_single_page_notifications?
+ test "displays the single page notification button on English pages" do
+ I18n.with_locale("en") do
+ presented = presented_item("statistics_publication")
+ assert presented.display_single_page_notification_button?
+ end
+ end
+
+ test "does not display the single page notification button on foreign language pages" do
+ I18n.with_locale("fr") do
+ presented = presented_item("statistics_publication")
+ assert_not presented.display_single_page_notification_button?
+ end
end
test "hide_from_search_engines? returns false" do
diff --git a/test/test_helper.rb b/test/test_helper.rb
index f036dc4d0..4d24c0ee4 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -194,8 +194,9 @@ def setup_and_visit_content_item_with_taxonomy_topic_email_override(name)
end
end
- def setup_and_visit_notification_exempt_page(name)
+ def setup_and_visit_notification_exempt_page(name, overrides = {})
@content_item = get_content_example(name).tap do |item|
+ item.deep_merge(overrides)
item["content_id"] = ContentItem::SinglePageNotificationButton::EXEMPTION_LIST[0]
stub_content_store_has_item(item["base_path"], item.to_json)
visit_with_cachebust((item["base_path"]).to_s)