Skip to content

Commit

Permalink
Merge pull request #1039 from alphagov/hide-mainstream-guide-contents…
Browse files Browse the repository at this point in the history
…-list

Use hide_chapter_navigation on guides
  • Loading branch information
andysellick authored Aug 16, 2018
2 parents 9ed03a2 + 749e6a3 commit 0956a2f
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 6 deletions.
21 changes: 21 additions & 0 deletions app/presenters/guide_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,30 @@ def parts
end
end

def show_guide_navigation?
multi_page_guide? && !hide_chapter_navigation?
end

def content_title
if parts.any?
return current_part_title if hide_chapter_navigation?
end

title
end

private

def draft_access_token_param
"token=#{draft_access_token}" if draft_access_token
end

def hide_chapter_navigation?
hide_navigation_elements = content_item.parsed_content["details"]["hide_chapter_navigation"]
part_of_step_navs? && hide_navigation_elements
end

def part_of_step_navs?
content_item.parsed_content["links"]["part_of_step_navs"].present?
end
end
16 changes: 10 additions & 6 deletions app/views/content_items/guide.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,34 @@

<div class="grid-row">
<div class="column-two-thirds">
<%= render 'govuk_publishing_components/components/title', { title: @content_item.title } %>
<% if @content_item.multi_page_guide? %>
<%= render 'govuk_publishing_components/components/title', { title: @content_item.content_title } %>

<% if @content_item.show_guide_navigation? %>
<aside class="part-navigation-container" role="complementary">
<%= render "govuk_publishing_components/components/contents_list", aria_label: 'Pages in this guide', contents: @content_item.part_link_elements, underline_links: true %>
</aside>
<% end %>
</div>

<div class="column-two-thirds">
<% if @content_item.has_parts? %>
<% if @content_item.multi_page_guide? %>
<% if @content_item.show_guide_navigation? %>
<h1 class="part-title">
<%= @content_item.current_part_title %>
</h1>
<% end %>

<%= render 'govuk_publishing_components/components/govspeak',
content: @content_item.current_part_body.html_safe,
direction: page_text_direction,
disable_youtube_expansions: true %>
<%= render 'govuk_publishing_components/components/previous_and_next_navigation', @content_item.previous_and_next_navigation %>

<% if @content_item.multi_page_guide? %>
<% if @content_item.show_guide_navigation? %>
<%= render 'govuk_publishing_components/components/previous_and_next_navigation', @content_item.previous_and_next_navigation %>
<%= render 'components/print-link', href: @content_item.print_link, link_text: t("multi_page.print_entire_guide") %>
<% end %>
<% end %>
</div>
<%= render 'shared/sidebar_navigation' %>

<%= render 'shared/sidebar_navigation' %>
</div>
48 changes: 48 additions & 0 deletions test/integration/guide_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,52 @@ class GuideTest < ActionDispatch::IntegrationTest
refute page.has_css?('h1', text: @content_item['details']['parts'].first['title'])
refute page.has_css?('.app-c-print-link')
end

test "replaces guide title with part title if in a step by step and hide_chapter_navigation is true" do
setup_and_visit_content_item('guide-with-step-navs-and-hide-navigation')
title = @content_item['title']
part_title = @content_item['details']['parts'][0]['title']

refute page.has_css?('h1', text: title)
assert_has_component_title(part_title)
end

test "does not replace guide title if not in a step by step and hide_chapter_navigation is true" do
setup_and_visit_content_item('guide-with-hide-navigation')
title = @content_item['title']
part_title = @content_item['details']['parts'][0]['title']

assert_has_component_title(title)
assert_has_component_title(part_title)
end

test "shows correct title in a single page guide if in a step by step and hide_chapter_navigation is true" do
setup_and_visit_content_item('single-page-guide-with-step-navs-and-hide-navigation')
title = @content_item['title']
part_title = @content_item['details']['parts'][0]['title']

refute page.has_css?('h1', text: title)
assert_has_component_title(part_title)
end

test "does not show guide navigation and print link if in a step by step and hide_chapter_navigation is true" do
setup_and_visit_content_item('guide-with-step-navs-and-hide-navigation')

refute page.has_css?('.gem-c-pagination')
refute page.has_css?('.app-c-print-link')
end

test "shows guide navigation and print link if not in a step by step and hide_chapter_navigation is true" do
setup_and_visit_content_item('guide-with-hide-navigation')

assert page.has_css?('.gem-c-pagination')
assert page.has_css?('.app-c-print-link')
end

test "guides with no parts in a step by step with hide_chapter_navigation do not error" do
setup_and_visit_content_item('no-part-guide-with-step-navs-and-hide-navigation')
title = @content_item['title']

assert_has_component_title(title)
end
end

0 comments on commit 0956a2f

Please sign in to comment.