From b1d30c7eda7194f1c55ffbbb18ad4020494726b5 Mon Sep 17 00:00:00 2001 From: Mateusz Grotek Date: Mon, 17 Feb 2025 10:59:32 +0000 Subject: [PATCH] Always show content list in guides --- app/presenters/guide_presenter.rb | 21 ------- app/views/content_items/guide.html.erb | 55 ++++++++----------- app/views/content_items/guide_single.html.erb | 10 ++-- .../content_items_controller_test.rb | 12 ++++ test/integration/guide_test.rb | 48 ---------------- 5 files changed, 40 insertions(+), 106 deletions(-) diff --git a/app/presenters/guide_presenter.rb b/app/presenters/guide_presenter.rb index 1eece5a53..5a13a420f 100644 --- a/app/presenters/guide_presenter.rb +++ b/app/presenters/guide_presenter.rb @@ -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 @@ -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 diff --git a/app/views/content_items/guide.html.erb b/app/views/content_items/guide.html.erb index 4c9230a74..e567056fc 100644 --- a/app/views/content_items/guide.html.erb +++ b/app/views/content_items/guide.html.erb @@ -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 %> @@ -19,28 +18,24 @@
- <%= 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" - } %> - - <% end %> + <%= render "govuk_publishing_components/components/skip_link", { + text: t("guide.skip_contents"), + href: "#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 @@ -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 %> - - <% end %> + <% end %>
diff --git a/app/views/content_items/guide_single.html.erb b/app/views/content_items/guide_single.html.erb index 0b3037d93..186842c93 100644 --- a/app/views/content_items/guide_single.html.erb +++ b/app/views/content_items/guide_single.html.erb @@ -18,17 +18,15 @@
<%= 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? %> - - <% end %> +
diff --git a/test/controllers/content_items_controller_test.rb b/test/controllers/content_items_controller_test.rb index d7be54947..18335f54a 100644 --- a/test/controllers/content_items_controller_test.rb +++ b/test/controllers/content_items_controller_test.rb @@ -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 diff --git a/test/integration/guide_test.rb b/test/integration/guide_test.rb index 57dd3dda6..72163b397 100644 --- a/test/integration/guide_test.rb +++ b/test/integration/guide_test.rb @@ -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"]