Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always show content list in guides #3573

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions app/presenters/guide_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ def has_parts?
parts.any?
end

def multi_page_guide?
parts.size > 1
end

def print_link
"#{base_path}/print"
end
Expand All @@ -41,29 +37,12 @@ def parts
end
end

def show_guide_navigation?
multi_page_guide? && !hide_chapter_navigation?
end

def content_title
if parts.any? && hide_chapter_navigation?
return current_part_title
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
Expand Down
55 changes: 24 additions & 31 deletions app/views/content_items/guide.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
canonical_url: @content_item.canonical_url,
body: @content_item.has_parts? ? @content_item.current_part_body : nil
) %>

<%= @requested_variant.analytics_meta_tag.html_safe if @requested_variant.present? %>
<% end %>

Expand All @@ -19,28 +18,24 @@

<div class="govuk-grid-row gem-print-columns-none">
<div class="govuk-grid-column-two-thirds">
<%= render 'govuk_publishing_components/components/heading', {
text: @content_item.content_title,
<%= render 'govuk_publishing_components/components/heading', {
text: @content_item.title,
heading_level: 1,
font_size: "xl",
margin_bottom: 8
} %>
<% if @content_item.show_guide_navigation? %>
<%= render "govuk_publishing_components/components/skip_link", {
text: t("guide.skip_contents"),
href: "#guide-contents"
} %>
<aside class="part-navigation-container" role="complementary">
<%= render "govuk_publishing_components/components/contents_list", aria: { label: t("guide.pages_in_guide") }, contents: @content_item.part_link_elements, underline_links: true %>
</aside>
<% end %>
<%= render "govuk_publishing_components/components/skip_link", {
text: t("guide.skip_contents"),
href: "#guide-contents"
} %>
<aside class="part-navigation-container" role="complementary">
<%= render "govuk_publishing_components/components/contents_list", aria: { label: t("guide.pages_in_guide") }, contents: @content_item.part_link_elements, underline_links: true %>
</aside>
</div>

<div class="govuk-grid-column-two-thirds govuk-!-margin-top-6" id="guide-contents">
<% if @content_item.has_parts? %>
<% if @content_item.show_guide_navigation? %>
<%= render 'govuk_publishing_components/components/heading', heading_level: 1, font_size: 'l', margin_bottom: 6, text: @content_item.current_part_title %>
<% end %>
<%= render 'govuk_publishing_components/components/heading', heading_level: 1, font_size: 'l', margin_bottom: 6, text: @content_item.current_part_title %>
<%
disable_youtube_expansions = true
# This is for the /child-benefit/how-to-claim page
Expand All @@ -55,23 +50,21 @@
<%= raw(@content_item.current_part_body) %>
<% end %>

<% if @content_item.show_guide_navigation? %>
<%= render 'govuk_publishing_components/components/previous_and_next_navigation', @content_item.previous_and_next_navigation %>
<%= render 'govuk_publishing_components/components/previous_and_next_navigation', @content_item.previous_and_next_navigation %>

<div class="responsive-bottom-margin">
<a href="<%= @content_item.print_link %>"
class="govuk-link govuk-link--no-visited-state govuk-body"
data-module="ga4-link-tracker"
data-ga4-link="<%= {
event_name: "navigation",
type: "print page",
section: "Footer",
text: t("multi_page.print_entire_guide", locale: :en)
}.to_json %>">
<%= t("multi_page.print_entire_guide") %>
</a>
</div>
<% end %>
<div class="responsive-bottom-margin">
<a href="<%= @content_item.print_link %>"
class="govuk-link govuk-link--no-visited-state govuk-body"
data-module="ga4-link-tracker"
data-ga4-link="<%= {
event_name: "navigation",
type: "print page",
section: "Footer",
text: t("multi_page.print_entire_guide", locale: :en)
}.to_json %>">
<%= t("multi_page.print_entire_guide") %>
</a>
</div>
<% end %>
</div>

Expand Down
10 changes: 4 additions & 6 deletions app/views/content_items/guide_single.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= render 'govuk_publishing_components/components/heading', {
text: @content_item.content_title,
text: @content_item.title,
heading_level: 1,
font_size: "xl",
margin_bottom: 8
} %>

<% if @content_item.show_guide_navigation? %>
<aside class="part-navigation-container" role="complementary">
<%= render "govuk_publishing_components/components/contents_list", aria: { label: t("guide.pages_in_guide") }, contents: @content_item.part_link_elements, underline_links: true %>
</aside>
<% end %>
<aside class="part-navigation-container" role="complementary">
<%= render "govuk_publishing_components/components/contents_list", aria: { label: t("guide.pages_in_guide") }, contents: @content_item.part_link_elements, underline_links: true %>
</aside>
</div>

<div class="govuk-grid-column-two-thirds">
Expand Down
12 changes: 12 additions & 0 deletions test/controllers/content_items_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,18 @@ class ContentItemsControllerTest < ActionController::TestCase
assert_equal "true", @response.headers[Slimmer::Headers::REMOVE_SEARCH_HEADER]
end

test "contents list is present" do
content_item = content_store_has_schema_example("guide", "guide-with-step-navs")
content_item["base_path"] = "/help-with-childcare-costs/support-while-you-study"
content_item["details"]["hide_chapter_navigation"] = true

stub_content_store_has_item(content_item["base_path"], content_item)

get :show, params: { path: "help-with-childcare-costs/support-while-you-study" }
assert_response :success
assert response.body.include?("contents-list")
end

def path_for(content_item, locale = nil)
base_path = content_item["base_path"].sub(/^\//, "")
base_path.gsub!(/\.#{locale}$/, "") if locale
Expand Down
48 changes: 0 additions & 48 deletions test/integration/guide_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,54 +34,6 @@ class GuideTest < ActionDispatch::IntegrationTest
assert page.has_css?('.gem-c-contents-list a[href$="?token=some_token"]')
end

test "does not show part navigation, print link or part title when only one part" do
setup_and_visit_content_item("single-page-guide")

assert_not page.has_css?("h1", text: @content_item["details"]["parts"].first["title"])
assert_not page.has_css?(".gem-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"]

assert_not 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"]

assert_not 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")

assert_not page.has_css?(".govuk-pagination")
assert_not page.has_css?(".govuk-link.govuk-link--no-visited-state[href$='/print']")
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?(".govuk-pagination")
assert page.has_css?(".govuk-link.govuk-link--no-visited-state[href$='/print']", text: "View a printable version of the whole guide")
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"]
Expand Down
Loading