From 930513d64b3aa81cbb09336d3f7349a914a2b8f9 Mon Sep 17 00:00:00 2001 From: Catalina Ilie Date: Tue, 15 Aug 2023 15:33:45 +0100 Subject: [PATCH] Enable taxonomy email signup for document collection Allow users to sign up to a mapped taxonomy topic email subscription from some document collection pages if taxonomy_topic_email_override is present. --- app/presenters/document_collection_presenter.rb | 4 ++++ .../content_items/document_collection.html.erb | 6 +++++- app/views/shared/_taxon_signup_link.html.erb | 17 +++++++++++++++++ test/integration/document_collection_test.rb | 6 ++++++ test/test_helper.rb | 10 ++++++++++ 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 app/views/shared/_taxon_signup_link.html.erb diff --git a/app/presenters/document_collection_presenter.rb b/app/presenters/document_collection_presenter.rb index ac977202c..def96cd3d 100644 --- a/app/presenters/document_collection_presenter.rb +++ b/app/presenters/document_collection_presenter.rb @@ -63,6 +63,10 @@ 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_documents(group) diff --git a/app/views/content_items/document_collection.html.erb b/app/views/content_items/document_collection.html.erb index 7f3e398e2..5c1a80072 100644 --- a/app/views/content_items/document_collection.html.erb +++ b/app/views/content_items/document_collection.html.erb @@ -22,7 +22,11 @@ <%= render 'shared/publisher_metadata_with_logo' %> -<%= render 'shared/single_page_notification_button', content_item: @content_item, skip_account: "true" %> +<% if @content_item.taxonomy_topic_email_override_base_path.present? %> + <%= render 'shared/taxon_signup_link', base_path: @content_item.taxonomy_topic_email_override_base_path %> +<% else %> + <%= render 'shared/single_page_notification_button', content_item: @content_item %> +<% end %>
diff --git a/app/views/shared/_taxon_signup_link.html.erb b/app/views/shared/_taxon_signup_link.html.erb new file mode 100644 index 000000000..d7770b048 --- /dev/null +++ b/app/views/shared/_taxon_signup_link.html.erb @@ -0,0 +1,17 @@ +
+ <%= render "govuk_publishing_components/components/signup_link", { + link_text: "Get emails about this topic", + link_href: "/email-signup/?link=#{base_path}", + data: { + "module": "gem-track-click", + "track-category": "emailAlertLinkClicked", + "track-action": base_path, + "track-label": "" + }, + margin_bottom: 6 + } %> +
diff --git a/test/integration/document_collection_test.rb b/test/integration/document_collection_test.rb index fdacbab3c..b77e93023 100644 --- a/test/integration/document_collection_test.rb +++ b/test/integration/document_collection_test.rb @@ -158,4 +158,10 @@ class DocumentCollectionTest < ActionDispatch::IntegrationTest setup_and_visit_content_item("document_collection") assert page.has_css?(".gem-c-single-page-notification-button") 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_not page.has_css?(".gem-c-single-page-notification-button") + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index e4e6f9b1c..aba36990a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -195,6 +195,16 @@ def setup_and_visit_content_item_with_taxons(name, taxons) end end + def setup_and_visit_content_item_with_taxonomy_topic_email_override(name) + @content_item = get_content_example(name).tap do |item| + item["links"]["taxonomy_topic_email_override"] = [{ + "base_path": "test", + }] + stub_content_store_has_item(item["base_path"], item.to_json) + visit_with_cachebust(item["base_path"]) + end + end + def setup_and_visit_notification_exempt_page(name) @content_item = get_content_example(name).tap do |item| item["content_id"] = ContentItem::SinglePageNotificationButton::EXEMPTION_LIST[0]