From b58beb46b355595fc67a8b168c3444ab9f56566a Mon Sep 17 00:00:00 2001 From: Simon Hughesdon Date: Tue, 6 Oct 2020 17:11:18 +0100 Subject: [PATCH] Test alternative text for Transition navigation We want to test whether changing the text on the banner navigation improves click through rate. We want to keep the test simple, so we've just chosen a [single, high traffic page](https://www.gov.uk/visit-europe-1-january-2021) as victim. The displayed navigation is determined in govuk_publishing_components, however we know how it works. If a certain taxonomy content_id is found in the taxon links of a content item, then a step by step banner (colloquially a "super breadcrumb") will be displayed using the title of the taxon. If we intercept the content item before it is passed to the component, then we can tweak what is displayed. https://trello.com/c/igPWXPvz/482-put-new-transition-taxon-live --- app/controllers/content_items_controller.rb | 19 ++++++++++++++ test/integration/guide_test.rb | 29 +++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/app/controllers/content_items_controller.rb b/app/controllers/content_items_controller.rb index 3e1eb83c8..63ecf2a98 100644 --- a/app/controllers/content_items_controller.rb +++ b/app/controllers/content_items_controller.rb @@ -92,6 +92,10 @@ def load_content_item content_item["links"]["ordered_related_items"] = content_item["links"].fetch("suggested_ordered_related_items", []) end + if update_brexit_navigation?(content_item) + content_item["links"]["taxons"] = taxons_updated_for_brexit_test(content_item) + end + @content_item = PresenterBuilder.new( content_item, content_item_path, @@ -99,6 +103,21 @@ def load_content_item ).presenter end + def update_brexit_navigation?(content_item) + content_item["content_id"] == "7a616597-c921-47ba-bd50-7e73449e140b" # /visit-europe-1-january-2021 + end + + def taxons_updated_for_brexit_test(content_item) + content_item["links"]["taxons"].map do |taxon| + taxon["title"] = "The UK and EU transition: new rules for 2021" if brexit_taxon?(taxon) + taxon + end + end + + def brexit_taxon?(taxon) + taxon["content_id"] == "d6c2de5d-ef90-45d1-82d4-5f2438369eea" + end + def format_banner_links(links, type) links.each.with_index(1).map do |(title, base_path), index| view_context.link_to( diff --git a/test/integration/guide_test.rb b/test/integration/guide_test.rb index 47cbd75b9..2435a8ff5 100644 --- a/test/integration/guide_test.rb +++ b/test/integration/guide_test.rb @@ -112,6 +112,35 @@ class GuideTest < ActionDispatch::IntegrationTest assert_nil faq_schema end + test "a specific guide has tweaked Brexit navigation" do + visit_europe_guide_id = "7a616597-c921-47ba-bd50-7e73449e140b" + setup_and_visit_a_guide_with_the_brexit_taxon(visit_europe_guide_id) + + assert page.has_css?(".gem-c-step-nav-header__title", text: "The UK and EU transition: new rules for 2021") + end + + test "a normal Brexit guide has normal Brexit navigation" do + setup_and_visit_a_guide_with_the_brexit_taxon + + assert page.has_css?(".gem-c-step-nav-header__title", text: "Brexit things") + end + + def setup_and_visit_a_guide_with_the_brexit_taxon(content_id = nil) + @content_item = get_content_example("guide").tap do |item| + item["content_id"] = content_id if content_id.present? + item["links"]["taxons"] = [brexit_taxon] + stub_content_store_has_item(item["base_path"], item.to_json) + visit_with_cachebust(item["base_path"]) + end + end + + def brexit_taxon + @brexit_taxon ||= GovukSchemas::Example.find("taxon", example_name: "taxon").tap do |taxon| + taxon["title"] = "Brexit things" + taxon["content_id"] = "d6c2de5d-ef90-45d1-82d4-5f2438369eea" # the real Brexit taxon ID + end + end + def setup_and_visit_part_in_guide @content_item = get_content_example("guide").tap do |item| chapter_path = "#{item['base_path']}/key-stage-1-and-2"