From 55f123c4be495eb4dc41e5c9d79b175fa73d7821 Mon Sep 17 00:00:00 2001 From: Vanita Barrett Date: Mon, 23 Jul 2018 16:04:30 +0000 Subject: [PATCH 1/3] Add promoted content logic to services Display the top 3 services in boxes, while showing the next 2 in a document list. --- app/controllers/content_items_controller.rb | 2 +- app/presenters/supergroups/services.rb | 15 +++++++++++++++ app/views/shared/_taxonomy_navigation.html.erb | 6 +++++- test/integration/content_pages_navigation_test.rb | 10 +++++----- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/controllers/content_items_controller.rb b/app/controllers/content_items_controller.rb index 357812a23..fc08cdf13 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.tagged_content, + services: services.all_services, } @tagged_taxons = taxons.map do |taxon| diff --git a/app/presenters/supergroups/services.rb b/app/presenters/supergroups/services.rb index 456c3cdaa..af2c4e835 100644 --- a/app/presenters/supergroups/services.rb +++ b/app/presenters/supergroups/services.rb @@ -6,13 +6,28 @@ def initialize(taxon_ids) @taxon_ids = taxon_ids end + def all_services + { + documents: tagged_content.drop(promoted_content_count), + promoted_content: promoted_content, + } + end + def tagged_content @content = MostPopularContent.fetch(content_ids: @taxon_ids, filter_content_purpose_supergroup: "services") format_document_data(@content) end + def promoted_content + tagged_content.shift(promoted_content_count) + end + private + def promoted_content_count + 3 + end + def format_document_data(documents) documents&.map do |document| data = { diff --git a/app/views/shared/_taxonomy_navigation.html.erb b/app/views/shared/_taxonomy_navigation.html.erb index efd49e1fe..8ee45d893 100644 --- a/app/views/shared/_taxonomy_navigation.html.erb +++ b/app/views/shared/_taxonomy_navigation.html.erb @@ -17,7 +17,11 @@ <%= render "govuk_publishing_components/components/highlight_boxes", { inverse: true, - items: taxonomy_navigation[:services] + items: taxonomy_navigation[:services][:promoted_content] + } %> + + <%= render "govuk_publishing_components/components/document_list", { + items: taxonomy_navigation[:services][:documents] } %> <% end %> diff --git a/test/integration/content_pages_navigation_test.rb b/test/integration/content_pages_navigation_test.rb index 46cedabf0..7aa408fce 100644 --- a/test/integration/content_pages_navigation_test.rb +++ b/test/integration/content_pages_navigation_test.rb @@ -36,9 +36,9 @@ class ContentPagesNavigationTest < ActionDispatch::IntegrationTest setup_and_visit_content_item_with_taxons('guide', THREE_TAXONS) - assert page.has_css?('.taxonomy-navigation h2', text: 'Becoming an apprentice') - assert page.has_css?('.taxonomy-navigation h2', text: 'Becoming a wizard') - assert page.has_css?('.taxonomy-navigation h2', text: 'Becoming the sorceror supreme') + assert page.has_css?('.taxonomy-navigation h2 a[href="/education/becoming-an-apprentice"]', text: 'Becoming an apprentice') + assert page.has_css?('.taxonomy-navigation h2 a[href="/education/becoming-a-wizard"]', text: 'Becoming a wizard') + assert page.has_css?('.taxonomy-navigation h2 a[href="/education/becoming-the-sorceror-supreme"]', text: 'Becoming the sorceror supreme') assert page.has_css?('.gem-c-highlight-boxes__title', text: 'Apprenticeship agreement: template') end @@ -51,8 +51,8 @@ class ContentPagesNavigationTest < ActionDispatch::IntegrationTest setup_and_visit_content_item_with_taxons('guide', taxons) - assert page.has_css?('.taxonomy-navigation h2', text: 'Becoming an apprentice') - refute page.has_css?('.taxonomy-navigation h2', text: 'Becoming a ghostbuster') + assert page.has_css?('.taxonomy-navigation h2 a[href="/education/becoming-an-apprentice"]', text: 'Becoming an apprentice') + refute page.has_css?('.taxonomy-navigation h2 a[href="/education/becoming-a-ghostbuster"]', text: 'Becoming a ghostbuster') assert page.has_css?('.gem-c-highlight-boxes__title', text: 'Apprenticeship agreement: template') end From 09b8789aa0a3768177344f3191383110e593d330 Mon Sep 17 00:00:00 2001 From: Vanita Barrett Date: Tue, 24 Jul 2018 09:56:33 +0000 Subject: [PATCH 2/3] Add GA tracking to services This should follow the same pattern as the topic page tracking --- app/presenters/supergroups/services.rb | 24 +++++++---- .../content_pages_navigation_test.rb | 23 +++++++++-- test/support/content_pages_nav_test_helper.rb | 41 +++++++++---------- 3 files changed, 56 insertions(+), 32 deletions(-) diff --git a/app/presenters/supergroups/services.rb b/app/presenters/supergroups/services.rb index af2c4e835..e3125edfa 100644 --- a/app/presenters/supergroups/services.rb +++ b/app/presenters/supergroups/services.rb @@ -4,22 +4,24 @@ class Services def initialize(taxon_ids) @taxon_ids = taxon_ids + @content = MostPopularContent.fetch(content_ids: @taxon_ids, filter_content_purpose_supergroup: "services") end def all_services { - documents: tagged_content.drop(promoted_content_count), + documents: tagged_content, promoted_content: promoted_content, } end def tagged_content - @content = MostPopularContent.fetch(content_ids: @taxon_ids, filter_content_purpose_supergroup: "services") - format_document_data(@content) + items = @content.drop(promoted_content_count) + format_document_data(items) end def promoted_content - tagged_content.shift(promoted_content_count) + items = @content.shift(promoted_content_count) + format_document_data(items, "HighlightBoxClicked") end private @@ -28,12 +30,20 @@ def promoted_content_count 3 end - def format_document_data(documents) - documents&.map do |document| + def format_document_data(documents, data_category = "DocumentListClicked") + documents.each.with_index(1)&.map do |document, index| data = { link: { text: document["title"], - path: document["link"] + path: document["link"], + data_attributes: { + track_category: "Services" + data_category, + track_action: index, + track_label: document["link"], + track_options: { + dimension29: document["title"], + } + } } } diff --git a/test/integration/content_pages_navigation_test.rb b/test/integration/content_pages_navigation_test.rb index 7aa408fce..1e98780ca 100644 --- a/test/integration/content_pages_navigation_test.rb +++ b/test/integration/content_pages_navigation_test.rb @@ -27,7 +27,7 @@ class ContentPagesNavigationTest < ActionDispatch::IntegrationTest setup_and_visit_content_item_with_taxons('guide', SINGLE_TAXON) assert page.has_css?('.taxonomy-navigation h2', text: 'Becoming an apprentice') - assert page.has_css?('.gem-c-highlight-boxes__title', text: 'Apprenticeship agreement: template') + assert page.has_css?('.gem-c-highlight-boxes__title', text: 'Free school meals form') end test "ContentPagesNav variant B renders many taxons nicely" do @@ -40,7 +40,7 @@ class ContentPagesNavigationTest < ActionDispatch::IntegrationTest assert page.has_css?('.taxonomy-navigation h2 a[href="/education/becoming-a-wizard"]', text: 'Becoming a wizard') assert page.has_css?('.taxonomy-navigation h2 a[href="/education/becoming-the-sorceror-supreme"]', text: 'Becoming the sorceror supreme') - assert page.has_css?('.gem-c-highlight-boxes__title', text: 'Apprenticeship agreement: template') + assert page.has_css?('.gem-c-highlight-boxes__title', text: 'Free school meals form') end test "ContentPagesNav variant B only includes live taxons" do @@ -53,8 +53,25 @@ class ContentPagesNavigationTest < ActionDispatch::IntegrationTest assert page.has_css?('.taxonomy-navigation h2 a[href="/education/becoming-an-apprentice"]', text: 'Becoming an apprentice') refute page.has_css?('.taxonomy-navigation h2 a[href="/education/becoming-a-ghostbuster"]', text: 'Becoming a ghostbuster') + end + + test "shows the Services section title and documents with tracking" do + stub_rummager + setup_variant_b + + taxons = SINGLE_TAXON + + setup_and_visit_content_item_with_taxons('guide', taxons) + + assert page.has_css?('h3', text: "Services") + assert page.has_css?('.gem-c-highlight-boxes__title', text: 'Free school meals form') + assert page.has_css?('.gem-c-highlight-boxes__title[data-track-category="ServicesHighlightBoxClicked"]', text: 'Free school meals form') + assert page.has_css?('.gem-c-highlight-boxes__title[data-track-action="1"]', text: 'Free school meals form') + assert page.has_css?('.gem-c-highlight-boxes__title[data-track-label="/government/publications/meals"]', text: 'Free school meals form') - assert page.has_css?('.gem-c-highlight-boxes__title', text: 'Apprenticeship agreement: template') + assert page.has_css?('.gem-c-document-list__item a[data-track-category="ServicesDocumentListClicked"]', text: 'Free school meals form') + assert page.has_css?('.gem-c-document-list__item a[data-track-action="1"]', text: 'Free school meals form') + assert page.has_css?('.gem-c-document-list__item a[data-track-label="/government/publications/meals"]', text: 'Free school meals form') end def setup_variant_a diff --git a/test/support/content_pages_nav_test_helper.rb b/test/support/content_pages_nav_test_helper.rb index 81cb4a471..fc7f605c8 100644 --- a/test/support/content_pages_nav_test_helper.rb +++ b/test/support/content_pages_nav_test_helper.rb @@ -1,27 +1,24 @@ module ContentPagesNavTestHelper def stub_rummager - stub_any_rummager_search - .to_return( - body: { - "results": [ - { - "content_store_document_type": "form", - "description": "This agreement must be signed by the apprentice and the employer at the start of the apprenticeship.", - "link": "/government/publications/apprenticeship-agreement-template", - "public_timestamp": "2012-08-28T00:00:00.000+01:00", - "title": "Apprenticeship agreement: template", - "index": "government", - "_id": "/government/publications/apprenticeship-agreement-template", - "elasticsearch_type": "edition", - "document_type": "edition" - } - ], - "total": 1, - "start": 0, - "aggregates": {}, - "suggested_queries": [] - }.to_json - ) + results = [] + + 4.times do + results.push( + "content_store_document_type": "form", + "link": "/government/publications/meals", + "title": "Free school meals form", + ) + end + + stub_any_rummager_search.to_return( + body: { + "results": results, + "total": 1, + "start": 0, + "aggregates": {}, + "suggested_queries": [] + }.to_json + ) end SINGLE_TAXON = [ From 0edddd7485a1368426d41197565b981298fee44f Mon Sep 17 00:00:00 2001 From: Vanita Barrett Date: Tue, 24 Jul 2018 10:59:34 +0000 Subject: [PATCH 3/3] 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",