-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3409 from alphagov/unsubscribe_button
Unsubscribe button on document collection pages
- Loading branch information
Showing
5 changed files
with
90 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
test/integration/document_collection/email_notifications_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters