From dd62c7aee10dff216e3749077ec9d1cfe862401f Mon Sep 17 00:00:00 2001 From: Dilwoar Hussain Date: Tue, 25 Sep 2018 10:57:06 +0100 Subject: [PATCH] Refactor related_to_step_navs function to superceed the original check This is required because the show_related_links function is used by content_tagged_to_a_reasonable_number_of_step_by_steps which is used to display the heading of the step by step. When a content item has step by step turned off by default, it will not contain any step_navs objects - as this is a `&&` statement, it will return false straight away. Inside the active_step_by_step? function, we merge both lists together, therefore, will display the related step by step links where appropriate. --- .../page_with_step_by_step_navigation.rb | 3 ++- .../page_with_step_by_step_navigation_spec.rb | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb b/lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb index 8b0e35b911..fcc5f63e0c 100644 --- a/lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb +++ b/lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb @@ -30,7 +30,8 @@ def show_header? end def show_related_links? - step_navs.any? && (step_navs.count < 5 || active_step_by_step?) + return true if active_step_by_step? + step_navs.any? && step_navs.count < 5 end def show_also_part_of_step_nav? diff --git a/spec/lib/presenters/page_with_step_by_step_navigation_spec.rb b/spec/lib/presenters/page_with_step_by_step_navigation_spec.rb index 6ff6fd27a7..570a7d95c0 100644 --- a/spec/lib/presenters/page_with_step_by_step_navigation_spec.rb +++ b/spec/lib/presenters/page_with_step_by_step_navigation_spec.rb @@ -381,6 +381,24 @@ expect(step_nav_helper.active_step_by_step?).to eq(false) expect(step_nav_helper.show_also_part_of_step_nav?).to be false end + + it "shows header for related to step nav when a step by step is active" do + step_nav = { + "content_id" => "cccc-dddd", + "title" => "Learn to spacewalk: small step by giant leap", + "base_path" => "/learn-to-spacewalk" + } + content_item = { + "title" => "Book a session in the vomit comet", + "document_type" => "transaction", + "links" => { + "related_to_step_navs" => [step_nav], + } + } + step_nav_helper = described_class.new(content_item, "/driving-lessons-learning-to-drive", "step-by-step-nav" => "cccc-dddd") + expect(step_nav_helper.active_step_by_step?).to eq(true) + expect(step_nav_helper.show_header?).to eq(true) + end end def payload_for(schema, content_item)