Skip to content

Commit

Permalink
Merge pull request #3467 from alphagov/remove_email_signup_button
Browse files Browse the repository at this point in the history
Hide email signup button from pages that do not have an :en locale
  • Loading branch information
hannako authored Dec 10, 2024
2 parents 2372672 + 61e9074 commit aa2639f
Show file tree
Hide file tree
Showing 19 changed files with 202 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/presenters/content_item_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions app/presenters/document_collection/signup_link.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 1 addition & 4 deletions app/presenters/document_collection_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions app/views/shared/_document_collections_email_signup.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% if @content_item.taxonomy_topic_email_override_base_path.present? %>
<% if @content_item.show_email_signup_link? %>
<div
data-module="ga4-link-tracker"
data-ga4-link='{ "event_name": "navigation", "type": "subscribe", "index_link": 1, "index_total": 1, "section": "Top" }'
Expand All @@ -10,7 +10,7 @@
margin_bottom: 6
} %>
</div>
<% 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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<div class="published-dates-button-group">
<h2 class="govuk-visually-hidden">
<% 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") %>
Expand All @@ -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,
Expand Down
44 changes: 23 additions & 21 deletions app/views/shared/_single_page_notification_button.html.erb
Original file line number Diff line number Diff line change
@@ -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 %>
7 changes: 6 additions & 1 deletion test/integration/call_for_evidence_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 6 additions & 1 deletion test/integration/consultation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
7 changes: 6 additions & 1 deletion test/integration/detailed_guide_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
21 changes: 18 additions & 3 deletions test/integration/document_collection/email_notifications_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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"])
Expand All @@ -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"])
Expand All @@ -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
7 changes: 6 additions & 1 deletion test/integration/publication_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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)
Expand Down
19 changes: 15 additions & 4 deletions test/presenters/call_for_evidence_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 14 additions & 5 deletions test/presenters/consultation_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 12 additions & 3 deletions test/presenters/detailed_guide_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
47 changes: 47 additions & 0 deletions test/presenters/document_collection/signup_link_test.rb
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit aa2639f

Please sign in to comment.