Skip to content

Commit

Permalink
Merge pull request #988 from alphagov/add-services-frontend
Browse files Browse the repository at this point in the history
Add services frontend
  • Loading branch information
Vanita Barrett authored Jul 26, 2018
2 parents 2356bcc + 0edddd7 commit 94869b3
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 37 deletions.
2 changes: 1 addition & 1 deletion app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def load_taxonomy_navigation
services = Supergroups::Services.new(taxon_ids)

@taxonomy_navigation = {
services: services.tagged_content,
services: (services.all_services if services.any_services?),
}

@tagged_taxons = taxons.map do |taxon|
Expand Down
39 changes: 34 additions & 5 deletions app/presenters/supergroups/services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,50 @@ 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,
promoted_content: promoted_content,
}
end

def any_services?
@content.any?
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
items = @content.shift(promoted_content_count)
format_document_data(items, "HighlightBoxClicked")
end

private

def format_document_data(documents)
documents&.map do |document|
def promoted_content_count
3
end

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"],
}
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion app/views/shared/_taxonomy_navigation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
} %>
</div>
<% end %>
Expand Down
44 changes: 36 additions & 8 deletions test/integration/content_pages_navigation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,11 +36,11 @@ 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')
assert page.has_css?('.gem-c-highlight-boxes__title', text: 'Free school meals form')
end

test "ContentPagesNav variant B only includes live taxons" do
Expand All @@ -51,10 +51,38 @@ 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')
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-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

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)

assert page.has_css?('.gem-c-highlight-boxes__title', text: 'Apprenticeship agreement: template')
refute page.has_css?('h3', text: "Services")
end

def setup_variant_a
Expand Down
55 changes: 33 additions & 22 deletions test/support/content_pages_nav_test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
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

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 = [
Expand Down

0 comments on commit 94869b3

Please sign in to comment.