diff --git a/app/presenters/hmrc_manual_section_presenter.rb b/app/presenters/hmrc_manual_section_presenter.rb index 26d264025..ba79a126b 100644 --- a/app/presenters/hmrc_manual_section_presenter.rb +++ b/app/presenters/hmrc_manual_section_presenter.rb @@ -30,23 +30,25 @@ def breadcrumbs end def previous_and_next_links - siblings = {} + return unless siblings + + section_siblings = {} if previous_sibling - siblings[:previous_page] = { + section_siblings[:previous_page] = { title: I18n.t("manuals.previous_page"), url: previous_sibling["base_path"], } end if next_sibling - siblings[:next_page] = { + section_siblings[:next_page] = { title: I18n.t("manuals.next_page"), url: next_sibling["base_path"], } end - siblings + section_siblings end private @@ -68,6 +70,8 @@ def siblings child_section_groups = parent_for_section.dig("details", "child_section_groups") + return unless child_section_groups + sibling_child_sections = child_section_groups.map do |group| included_section = group["child_sections"].find { |section| section["section_id"].include?(current_section_id) } group["child_sections"] if included_section.present? diff --git a/test/presenters/hmrc_manual_section_presenter_test.rb b/test/presenters/hmrc_manual_section_presenter_test.rb index 9227b7541..7de0ea49b 100644 --- a/test/presenters/hmrc_manual_section_presenter_test.rb +++ b/test/presenters/hmrc_manual_section_presenter_test.rb @@ -146,6 +146,19 @@ class PresentedHmrcManualSectionTest < HmrcManualSectionPresenterTestCase assert_equal expected_previous_link, presented_manual_section.previous_and_next_links end + test "presents no previous or next links if there is no previous or next section" do + manual_base_path = schema_item("vatgpb2000")["details"]["manual"]["base_path"] + manual = schema_item("vat-government-public-bodies", "hmrc_manual") + + manual["details"]["child_section_groups"] = [] + + stub_content_store_has_item(manual_base_path, manual.to_json) + + expected_links = {} + + assert_equal expected_links, presented_manual_section.previous_and_next_links + end + def presented_manual_section(overrides = {}) presented_item("vatgpb2000", overrides) end