Skip to content

Commit

Permalink
Test alternative text for Transition navigation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sihugh committed Oct 6, 2020
1 parent 7862e9f commit b58beb4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,32 @@ 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,
view_context,
).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(
Expand Down
29 changes: 29 additions & 0 deletions test/integration/guide_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b58beb4

Please sign in to comment.