From dbb589261a7aded797c4888cc59127b42f5cd3c5 Mon Sep 17 00:00:00 2001 From: Jessica Jones Date: Tue, 12 Nov 2024 13:15:29 +0000 Subject: [PATCH 1/2] Add flash success banner to document collection pages This was missing from https://github.com/alphagov/government-frontend/pull/2535 --- app/views/content_items/document_collection.html.erb | 3 +++ test/controllers/content_items_controller_test.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/views/content_items/document_collection.html.erb b/app/views/content_items/document_collection.html.erb index 97f92a238..3fa950e6f 100644 --- a/app/views/content_items/document_collection.html.erb +++ b/app/views/content_items/document_collection.html.erb @@ -3,6 +3,9 @@ schema: :article ) %> <% end %> + +<%= render 'shared/email_subscribe_unsubscribe_flash', { title: @content_item.title_and_context[:title] } %> + <%= render 'shared/intervention_banner' %>
diff --git a/test/controllers/content_items_controller_test.rb b/test/controllers/content_items_controller_test.rb index 8cd57808a..5ad576330 100644 --- a/test/controllers/content_items_controller_test.rb +++ b/test/controllers/content_items_controller_test.rb @@ -310,7 +310,7 @@ class ContentItemsControllerTest < ActionController::TestCase assert response.headers["Vary"].include?("GOVUK-Account-Session-Flash") end - %w[publication consultation detailed_guide call_for_evidence].each do |schema_name| + %w[publication consultation detailed_guide call_for_evidence document_collection].each do |schema_name| test "#{schema_name} displays the subscription success banner when the 'email-subscription-success' flash is present" do example_name = %w[consultation call_for_evidence].include?(schema_name) ? "open_#{schema_name}" : schema_name content_item = content_store_has_schema_example(schema_name, example_name) From c53a9076621824936caea4c7c779df23a2706851 Mon Sep 17 00:00:00 2001 From: Jessica Jones Date: Thu, 11 Jan 2024 08:55:47 +0000 Subject: [PATCH 2/2] Use govuk_account_session header to toggle email signup route Document collection email subscriptions are complicated[1] The expected behaviour is: If a document collection has a taxonomy topic email override in its links, render the signup link component, and subscribe the user to the taxonomy topic instead of to the document collection itself. In all other cases, render a single page notification button. The button is a gem component, and it uses the value of the attribute `skip_account` to determine the form action of this button[2] - If the user has an active govuk-account session, the button should post to email-alert-frontend's /email/subscriptions/single-page/new endpoint. This endpoint enforces the gov.uk account[3]. - If the user is not logged into their account (or they don't have an account) then the button should post to email-alert-api's magic link endpoint, /email-signup instead. This endpoint does not enforce the govuk account. Current behaviour: Prior to this commit, we were passing skip_account = "true" to the button component on all document collection pages, and therefore hardcoding the button to post to the account free endpoint regardless of whether or not they were logged into their account. New behaviour: What this commit does, is to only set the value of skip_account to "true" for users without an active govuk-account session. Why are we making this change? For users with an existing subscription returning to a document collection page, the single page notification button doesn't allow them to unsubscribe. The button text is "Stop getting emails about this page", but instead of posting to email/subscriptions/single-page/new, which supports both subscribing AND unsubscribing[4] it is hardcoded to post to /email-signup which supports sign up only. This means they must log into their govuk accounts in order to manage their subscriptions. [1] https://docs.publishing.service.gov.uk/manual/document-collection-emails-a-special-case.html [2] https://github.com/alphagov/govuk_publishing_components/blob/main/lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb#L58-L64 [3] https://github.com/alphagov/email-alert-frontend/blob/main/app/controllers/govuk_account_signups_controller.rb#L15-L17 [4] https://github.com/alphagov/email-alert-frontend/blob/main/app/controllers/govuk_account_signups_controller.rb#L27-L34 --- ...document_collections_email_signup.html.erb | 5 +- .../email_notifications_test.rb | 82 +++++++++++++++++++ test/integration/document_collection_test.rb | 13 --- 3 files changed, 86 insertions(+), 14 deletions(-) create mode 100644 test/integration/document_collection/email_notifications_test.rb diff --git a/app/views/shared/_document_collections_email_signup.html.erb b/app/views/shared/_document_collections_email_signup.html.erb index ca877ccc4..df50c701c 100644 --- a/app/views/shared/_document_collections_email_signup.html.erb +++ b/app/views/shared/_document_collections_email_signup.html.erb @@ -11,5 +11,8 @@ } %>
<% else %> - <%= render 'shared/single_page_notification_button', content_item: @content_item, skip_account: "true" %> + <%= render 'shared/single_page_notification_button', { + content_item: @content_item, + skip_account: @has_govuk_account ? "false" : "true" + } %> <% end %> diff --git a/test/integration/document_collection/email_notifications_test.rb b/test/integration/document_collection/email_notifications_test.rb new file mode 100644 index 000000000..b2d272dbe --- /dev/null +++ b/test/integration/document_collection/email_notifications_test.rb @@ -0,0 +1,82 @@ +require "test_helper" + +module DocumentCollection + class EmailNotificationsTest < ActionDispatch::IntegrationTest + include GovukPersonalisation::TestHelpers::Features + + def schema_type + "document_collection" + end + + def taxonomy_topic_base_path + "/taxonomy_topic_base_path" + end + + def email_alert_frontend_signup_endpoint_no_account + "/email-signup" + end + + 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 + content_item = get_content_example("document_collection") + 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"]) + assert page.has_css?(".gem-c-signup-link") + assert page.has_link?(href: "/email-signup/confirm?topic=#{taxonomy_topic_base_path}") + assert_not page.has_css?(".gem-c-single-page-notification-button") + 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") + + form = page.find("form.gem-c-single-page-notification-button") + assert_match(email_alert_frontend_signup_endpoint_no_account, form["action"]) + + button = page.find(:button, class: "gem-c-single-page-notification-button__submit") + + expected_tracking = { + "event_name" => "navigation", + "type" => "subscribe", + "index_link" => 1, + "index_total" => 2, + "section" => "Top", + "url" => email_alert_frontend_signup_endpoint_no_account, + } + actual_tracking = JSON.parse(button["data-ga4-link"]) + + assert_equal expected_tracking, actual_tracking + end + + test "renders the single page notification button with a form action of EmailAlertAPI's account-only endpoint for users logged into their gov.uk account" do + # 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") + + form = page.find("form.gem-c-single-page-notification-button") + assert_match(email_alert_frontend_signup_endpoint_enforce_account, form["action"]) + + button = page.find(:button, class: "gem-c-single-page-notification-button__submit") + + expected_tracking = { + "event_name" => "navigation", + "type" => "subscribe", + "index_link" => 1, + "index_total" => 2, + "section" => "Top", + "url" => "/email/subscriptions/single-page/new", + } + + actual_tracking = JSON.parse(button["data-ga4-link"]) + + assert_equal expected_tracking, actual_tracking + + # reset back to default driver + Capybara.use_default_driver + end + end +end diff --git a/test/integration/document_collection_test.rb b/test/integration/document_collection_test.rb index f14d1449a..d3c4e27d3 100644 --- a/test/integration/document_collection_test.rb +++ b/test/integration/document_collection_test.rb @@ -132,17 +132,4 @@ class DocumentCollectionTest < ActionDispatch::IntegrationTest assert page.has_text?("This was published under the 2010 to 2015 Conservative and Liberal Democrat coalition government") end end - - test "renders with the single page notification button" do - setup_and_visit_content_item("document_collection") - assert page.has_css?(".gem-c-single-page-notification-button") - assert_not page.has_css?(".gem-c-signup-link") - end - - test "renders with the taxonomy subscription button" do - setup_and_visit_content_item_with_taxonomy_topic_email_override("document_collection") - assert page.has_css?(".gem-c-signup-link") - assert page.has_link?(href: "/email-signup/confirm?topic=/testpath") - assert_not page.has_css?(".gem-c-single-page-notification-button") - end end