From 0edddd7485a1368426d41197565b981298fee44f Mon Sep 17 00:00:00 2001 From: Vanita Barrett Date: Tue, 24 Jul 2018 10:59:34 +0000 Subject: [PATCH] Hide section when no tagged services --- app/controllers/content_items_controller.rb | 2 +- app/presenters/supergroups/services.rb | 4 ++++ test/integration/content_pages_navigation_test.rb | 11 +++++++++++ test/support/content_pages_nav_test_helper.rb | 14 ++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/controllers/content_items_controller.rb b/app/controllers/content_items_controller.rb index fc08cdf13..840861e46 100644 --- a/app/controllers/content_items_controller.rb +++ b/app/controllers/content_items_controller.rb @@ -71,7 +71,7 @@ def load_taxonomy_navigation services = Supergroups::Services.new(taxon_ids) @taxonomy_navigation = { - services: services.all_services, + services: (services.all_services if services.any_services?), } @tagged_taxons = taxons.map do |taxon| diff --git a/app/presenters/supergroups/services.rb b/app/presenters/supergroups/services.rb index e3125edfa..ad62fbb35 100644 --- a/app/presenters/supergroups/services.rb +++ b/app/presenters/supergroups/services.rb @@ -14,6 +14,10 @@ def all_services } end + def any_services? + @content.any? + end + def tagged_content items = @content.drop(promoted_content_count) format_document_data(items) diff --git a/test/integration/content_pages_navigation_test.rb b/test/integration/content_pages_navigation_test.rb index 1e98780ca..724e303e8 100644 --- a/test/integration/content_pages_navigation_test.rb +++ b/test/integration/content_pages_navigation_test.rb @@ -74,6 +74,17 @@ class ContentPagesNavigationTest < ActionDispatch::IntegrationTest assert page.has_css?('.gem-c-document-list__item a[data-track-label="/government/publications/meals"]', text: 'Free school meals form') end + test "does not show the Services section if there is no tagged content" do + stub_empty_rummager + setup_variant_b + + taxons = SINGLE_TAXON + + setup_and_visit_content_item_with_taxons('guide', taxons) + + refute page.has_css?('h3', text: "Services") + end + def setup_variant_a ContentItemsController.any_instance.stubs(:show_new_navigation?).returns(false) end diff --git a/test/support/content_pages_nav_test_helper.rb b/test/support/content_pages_nav_test_helper.rb index fc7f605c8..49bea9472 100644 --- a/test/support/content_pages_nav_test_helper.rb +++ b/test/support/content_pages_nav_test_helper.rb @@ -21,6 +21,20 @@ def stub_rummager ) end + def stub_empty_rummager + results = [] + + stub_any_rummager_search.to_return( + body: { + "results": results, + "total": 1, + "start": 0, + "aggregates": {}, + "suggested_queries": [] + }.to_json + ) + end + SINGLE_TAXON = [ { "base_path" => "/education/becoming-an-apprentice",