From 7a8ca46b503953f13928f5a3f03c37eba8f3a030 Mon Sep 17 00:00:00 2001 From: Alex Whitehead-Smith Date: Wed, 22 Dec 2021 15:15:40 +0000 Subject: [PATCH] Add 'already subscribed' email flash banner Handle the new flash message variation added in https://github.com/alphagov/email-alert-frontend/pull/1223 which should be shown when a user clicks the button to subscribe to email alerts about a page, but is already subscribed. --- .../shared/_email_subscribe_unsubscribe_flash.html.erb | 10 ++++++++++ config/locales/en.yml | 1 + test/controllers/content_items_controller_test.rb | 8 ++++++++ 3 files changed, 19 insertions(+) diff --git a/app/views/shared/_email_subscribe_unsubscribe_flash.html.erb b/app/views/shared/_email_subscribe_unsubscribe_flash.html.erb index ffb331cf6..88c9480be 100644 --- a/app/views/shared/_email_subscribe_unsubscribe_flash.html.erb +++ b/app/views/shared/_email_subscribe_unsubscribe_flash.html.erb @@ -18,4 +18,14 @@ } %> +<% elsif @account_flash.include?("email-subscribe-already-subscribed") %> +
+
+ <%= render "govuk_publishing_components/components/success_alert", { + message: sanitize(t("email.already_subscribed_title")), + description: sanitize(t("email.description_html")), + margin_bottom: 0, + } %> +
+
<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 6eddaca39..3b0abf1c7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -296,6 +296,7 @@ en: description_html:

Go to your GOV.UK account to see and manage all your GOV.UK email subscriptions.

subscribe_title: You’ve subscribed to emails about this page unsubscribe_title: You’ve unsubscribed from emails about this page + already_subscribed_title: You’re already getting emails about this page fatality_notice: alt_text: Ministry of Defence crest field_of_operation: Field of operation diff --git a/test/controllers/content_items_controller_test.rb b/test/controllers/content_items_controller_test.rb index a68a230cf..8f6baa115 100644 --- a/test/controllers/content_items_controller_test.rb +++ b/test/controllers/content_items_controller_test.rb @@ -389,6 +389,14 @@ class ContentItemsControllerTest < ActionController::TestCase assert response.body.include?("unsubscribed from emails about this page") end + test "displays the already subscribed success banner when the 'email-subscribe-already-subscribed' flash is present" do + content_item = content_store_has_schema_example("publication", "publication") + + request.headers["GOVUK-Account-Session"] = GovukPersonalisation::Flash.encode_session("session-id", %w[email-subscribe-already-subscribed]) + get :show, params: { path: path_for(content_item) } + assert response.body.include?("already getting emails about this page") + end + def path_for(content_item, locale = nil) base_path = content_item["base_path"].sub(/^\//, "") base_path.gsub!(/\.#{locale}$/, "") if locale