Skip to content

Commit

Permalink
Merge pull request #2899 from alphagov/enable-taxonomy-signup-for-doc…
Browse files Browse the repository at this point in the history
…ument-collection

Enable taxonomy email signup for document collection
  • Loading branch information
catalinailie authored Aug 31, 2023
2 parents 5ce9aed + 930513d commit 6374a53
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/presenters/document_collection_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion app/views/content_items/document_collection.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
</div>

<%= 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 %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
Expand Down
17 changes: 17 additions & 0 deletions app/views/shared/_taxon_signup_link.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div
data-module="ga4-link-tracker"
data-ga4-link='{ "event_name": "navigation", "type": "subscribe", "index": { "index_link": 1 }, "index_total": 1, "section": "Top" }'
data-ga4-track-links-only
>
<%= 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
} %>
</div>
6 changes: 6 additions & 0 deletions test/integration/document_collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 6374a53

Please sign in to comment.