Skip to content

Commit

Permalink
Allow step by step nav pages with 0 steps
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sihugh committed Mar 8, 2018
1 parent 5898496 commit b8c16c7
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 4 deletions.
2 changes: 1 addition & 1 deletion 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)
Expand Down
6 changes: 5 additions & 1 deletion lib/govuk_publishing_components/step_nav.rb
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion lib/govuk_publishing_components/step_nav_helper.rb
Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions spec/features/step_nav_helper_spec.rb
Expand Up @@ -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: [
Expand Down Expand Up @@ -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
9 changes: 8 additions & 1 deletion spec/lib/step_nav_helper_spec.rb
Expand Up @@ -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

Expand Down

0 comments on commit b8c16c7

Please sign in to comment.