From b8c16c7bd2e67f095c9d23ceaf30d2a1fbdfdadf Mon Sep 17 00:00:00 2001 From: Simon Hughesdon Date: Thu, 8 Mar 2018 16:34:03 +0000 Subject: [PATCH] Allow step by step nav pages with 0 steps To enable us to preview pages at all stages of the content design process we need to be able to handle step by step navs with zero steps. This adds tests and adjusts the show_sidebar logic to handle this. --- Gemfile.lock | 2 +- lib/govuk_publishing_components/step_nav.rb | 6 ++- .../step_nav_helper.rb | 5 +- spec/features/step_nav_helper_spec.rb | 49 +++++++++++++++++++ spec/lib/step_nav_helper_spec.rb | 9 +++- 5 files changed, 67 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index abab228e64..f3f1f5d612 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - govuk_publishing_components (5.3.0) + govuk_publishing_components (5.4.0) govspeak (>= 5.0.3) govuk_frontend_toolkit rails (>= 5.0.0.1) diff --git a/lib/govuk_publishing_components/step_nav.rb b/lib/govuk_publishing_components/step_nav.rb index d62bd9c280..672d61c1ba 100644 --- a/lib/govuk_publishing_components/step_nav.rb +++ b/lib/govuk_publishing_components/step_nav.rb @@ -13,7 +13,11 @@ def base_path end def content - @content ||= content_item.dig(:details, :step_by_step_nav) + content_item.dig(:details, :step_by_step_nav) + end + + def steps + content_item.dig(:details, :step_by_step_nav, :steps) end private diff --git a/lib/govuk_publishing_components/step_nav_helper.rb b/lib/govuk_publishing_components/step_nav_helper.rb index a25c9cd31f..5699029952 100644 --- a/lib/govuk_publishing_components/step_nav_helper.rb +++ b/lib/govuk_publishing_components/step_nav_helper.rb @@ -12,9 +12,12 @@ def step_navs end def show_sidebar? + show_header? && first_step_nav.steps.present? + end + + def show_header? step_navs.count == 1 end - alias_method :show_header?, :show_sidebar? def show_related_links? step_navs.any? && step_navs.count < 5 diff --git a/spec/features/step_nav_helper_spec.rb b/spec/features/step_nav_helper_spec.rb index 71d390de6c..609c55cebb 100644 --- a/spec/features/step_nav_helper_spec.rb +++ b/spec/features/step_nav_helper_spec.rb @@ -48,6 +48,34 @@ end end + context 'one related step by step navigation journey with no steps' do + before do + content_store_has_random_item(base_path: '/vomit-comet', schema: 'transaction', part_of_step_navs: [zero_steps_step_nav]) + + visit '/step-nav/vomit-comet' + end + + it 'shows step nav related links' do + expect(page).to have_selector('.gem-c-step-nav-related') + + within('.gem-c-step-nav-related') do + expect(page).to have_selector('.gem-c-step-nav-related__link', count: 1) + expect(page).to have_link('Learn to spacewalk: small step by giant leap', href: '/learn-to-spacewalk') + end + end + + it 'does not show the full step nav sidebar' do + expect(page).to_not have_css('.gem-c-step-nav') + end + + it 'shows the step nav header' do + within('.gem-c-step-nav-header') do + expect(page).to have_link('Learn to spacewalk: small step by giant leap', href: '/learn-to-spacewalk') + end + end + end + + context 'multiple related step by step navigation journeys' do before do content_store_has_random_item(base_path: '/vomit-comet', schema: 'transaction', part_of_step_navs: [ @@ -182,4 +210,25 @@ def spacewalk_step_nav } } end + + def zero_steps_step_nav + { + "content_id" => "8f5d4f2b-daf0-4460-88c1-fdd76c90f6f1", + "locale" => "en", + "title" => "Learn to spacewalk: small step by giant leap", + "base_path" => "/learn-to-spacewalk", + "details" => { + "step_by_step_nav": { + "title": "Learn to spacewalk: small step by giant leap", + "introduction": [ + { + "content_type": "text/govspeak", + "content": "Check what you need to do to learn to spacewalk." + } + ], + "steps": [] + } + } + } + end end diff --git a/spec/lib/step_nav_helper_spec.rb b/spec/lib/step_nav_helper_spec.rb index fe76e5dc86..2202a5eb93 100644 --- a/spec/lib/step_nav_helper_spec.rb +++ b/spec/lib/step_nav_helper_spec.rb @@ -6,7 +6,14 @@ { "content_id" => "cccc-dddd", "title" => "Learn to spacewalk: small step by giant leap", - "base_path" => "/learn-to-spacewalk" + "base_path" => "/learn-to-spacewalk", + "details" => { + "step_by_step_nav" => { + "steps" => [ + "title": "Step one" + ] + } + } } end