Skip to content

Commit

Permalink
Merge pull request #3269 from alphagov/fix-hmrc-siblings
Browse files Browse the repository at this point in the history
Do not attempt to show siblings if there aren't any
  • Loading branch information
brucebolt authored Jul 22, 2024
2 parents 44f031d + c0e1751 commit 09d7ae8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app/presenters/hmrc_manual_section_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?
Expand Down
13 changes: 13 additions & 0 deletions test/presenters/hmrc_manual_section_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 09d7ae8

Please sign in to comment.