diff --git a/lib/govuk_publishing_components/components/related_navigation_helper.rb b/lib/govuk_publishing_components/components/related_navigation_helper.rb index 700728980e..f6a4a2ff78 100644 --- a/lib/govuk_publishing_components/components/related_navigation_helper.rb +++ b/lib/govuk_publishing_components/components/related_navigation_helper.rb @@ -24,7 +24,6 @@ def related_navigation { "topical_events" => related_topical_events }, { "world_locations" => related_world_locations }, { "statistical_data_sets" => related_statistical_data_sets }, - { "worldwide_organisations" => related_worldwide_organisations }, ] other = [related_external_links, related_contacts] || [] @@ -100,11 +99,6 @@ def related_world_locations build_links_for_sidebar(locations) end - def related_worldwide_organisations - organisations = filter_link_type("worldwide_organisations", "worldwide_organisation") - build_links_for_sidebar(organisations) - end - def related_collections collections = filter_link_type("document_collections", "document_collection") build_links_for_sidebar(collections) @@ -172,7 +166,7 @@ def parent end def grandparent - parent.dig("parent", 0) + parent.dig("links", "parent", 0) end # This method post-processes the topics collated by the helper. @@ -214,12 +208,14 @@ def tagged_to_same_mainstream_browse_page def parents_tagged_to_same_mainstream_browse_page return [] unless parent && grandparent - - common_parent_content_ids = tagged_to_same_mainstream_browse_page.map(&:content_id) + common_parent_content_ids = tagged_to_same_mainstream_browse_page.map { |item| item["content_id"] } @parents_tagged_to_same_mainstream_browse_page ||= related_links.select do |related_item| next if common_parent_content_ids.include?(related_item["content_id"]) - related_item.dig("links", "mainstream_browse_pages").map(&:parent).map(&:content_id).include?(grandparent["content_id"]) + mainstream_browse_pages = related_item.dig("links", "mainstream_browse_pages") + parents = mainstream_browse_pages.map { |page| page["links"]["parent"][0] } + content_ids = parents.map { |parent| parent["content_id"] } + content_ids.include?(grandparent["content_id"]) end end diff --git a/spec/lib/related_navigation_helper_spec.rb b/spec/lib/related_navigation_helper_spec.rb index 56cc2c397c..5f3a032dac 100644 --- a/spec/lib/related_navigation_helper_spec.rb +++ b/spec/lib/related_navigation_helper_spec.rb @@ -30,7 +30,6 @@ def payload_for(schema, content_item) { "topical_events" => [] }, { "world_locations" => [] }, { "statistical_data_sets" => [] }, - { "worldwide_organisations" => [] }, ] expect(nothing).to eq(expected) @@ -138,49 +137,11 @@ def payload_for(schema, content_item) { "topical_events" => [{ path: "/related-topical-event", text: "related topical event" }] }, { "world_locations" => [{ path: "/world/world-location/news", text: "World, ~ (@Location)" }] }, { "statistical_data_sets" => [] }, - { "worldwide_organisations" => [] }, ] expect(payload).to eql(expected) end - it "returns worldwide organisations" do - payload = payload_for("world_location_news_article", - "details" => { - "body" => "body", - "government" => { - "title" => "government", - "slug" => "government", - "current" => true - }, - "political" => true, - "first_public_at" => "2016-01-01T19:00:00Z", - }, - "links" => { - "worldwide_organisations" => [ - { - "content_id" => "32c1b93d-2553-47c9-bc3c-fc5b513ecc32", - "title" => "related worldwide organisation", - "base_path" => "/related-worldwide-organisation", - "document_type" => "worldwide_organisation", - "locale" => "en" - } - ], - }) - expected = [ - { "related_items" => [] }, - { "related_guides" => [] }, - { "collections" => [] }, - { "topics" => [] }, - { "policies" => [] }, - { "topical_events" => [] }, - { "world_locations" => [] }, - { "statistical_data_sets" => [] }, - { "worldwide_organisations" => [{ path: "/related-worldwide-organisation", text: "related worldwide organisation" }] }, - ] - expect(payload).to eql(expected) - end - it "returns statistical data sets" do payload = payload_for("publication", "details" => { @@ -214,7 +175,6 @@ def payload_for(schema, content_item) { "topical_events" => [] }, { "world_locations" => [] }, { "statistical_data_sets" => [{ path: "/related-statistical-data-set", text: "related statistical data set" }] }, - { "worldwide_organisations" => [] }, ] expect(payload).to eql(expected) end @@ -263,12 +223,97 @@ def payload_for(schema, content_item) { "topical_events" => [] }, { "world_locations" => [] }, { "statistical_data_sets" => [] }, - { "worldwide_organisations" => [] }, ] expect(payload).to eql(expected) end + it "returns parent and grandparent topics" do + payload = payload_for("answer", + "links" => { + "parent" => [ + { + "base_path" => "/browse/working/tax-minimum-wage", + "content_id" => "a3e4b233-e2f3-4709-b531-8da7f21a3f6d", + "locale" => "en", + "title" => "Your pay, tax and the National Minimum Wage", + "links" => { + "parent" => [ + { + "base_path" => "/browse/working", + "content_id" => "a24f0662-bbfe-4b77-9ec0-e73240e88b9a", + "locale" => "en", + "title" => "Working, jobs and pensions", + } + ] + }, + } + ], + "ordered_related_items" => [ + { + "base_path" => "/apprenticeships-guide", + "content_id" => "b95f3e83-a8d1-40fa-843c-cb712861707d", + "locale" => "en", + "title" => "Become an apprentice", + "links" => { + "mainstream_browse_pages" => [ + { + "base_path" => "/browse/working/finding-job", + "content_id" => "eceb3053-43d1-4a49-873d-85ff9ade7066", + "locale" => "en", + "title" => "Finding a job", + "links" => { + "parent" => [ + { + "base_path" => "/browse/working", + "content_id" => "a24f0662-bbfe-4b77-9ec0-e73240e88b9a", + "locale" => "en", + "title" => "Working, jobs and pensions", + } + ] + }, + } + ] + }, + }, + { + "base_path" => "/national-insurance", + "content_id" => "c995522c-4020-4d54-ae5d-271d4b3a8777", + "locale" => "en", + "title" => "National Insurance", + "links" => { + "mainstream_browse_pages" => [ + { + "base_path" => "/browse/working/tax-minimum-wage", + "content_id" => "a3e4b233-e2f3-4709-b531-8da7f21a3f6d", + "locale" => "en", + "title" => "Your pay, tax and the National Minimum Wage", + "links" => { + "parent" => [ + { + "base_path" => "/browse/working", + "content_id" => "a24f0662-bbfe-4b77-9ec0-e73240e88b9a", + "locale" => "en", + "title" => "Working, jobs and pensions", + } + ] + }, + } + ] + }, + } + ] + }) + + expected = { + "topics" => [ + { text: "Your pay, tax and the National Minimum Wage", path: "/browse/working/tax-minimum-wage" }, + { text: "Working, jobs and pensions", path: "/browse/working" }, + ] + } + expect(payload).to include(expected) + end + it "returns an Elsewhere on the web section for external related links" do payload = payload_for("placeholder", "details" => {