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

Do not attempt to show siblings if there aren't any #3269

Merged
merged 2 commits into from
Jul 22, 2024
Merged
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
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
Loading