Skip to content

Commit

Permalink
Merge pull request #1871 from alphagov/transition-super-bc
Browse files Browse the repository at this point in the history
Test alternative text for Transition navigation
  • Loading branch information
sihugh authored Oct 6, 2020
2 parents 7862e9f + b58beb4 commit 0c4aa5a
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 0c4aa5a

Please sign in to comment.