Skip to content

Commit

Permalink
Merge pull request #943 from alphagov/add-inverse-option-to-contextua…
Browse files Browse the repository at this point in the history
…l-breadcrumbs

Add inverse option to contextual breadcrumbs
  • Loading branch information
andysellick authored Jun 20, 2019
2 parents 4a608d0 + 878713c commit 5558e1f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

## Unreleased

* Add inverse option to contextual breadcrumbs (PR #943)
* Adds support for secondary content items for step by step (PR #900)
* Adds missing tests for related to step navs (PR #900)
* Adds missing tests for also part of step navs component (PR #900)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<% navigation = GovukPublishingComponents::Presenters::ContextualNavigation.new(content_item, request) %>
<% prioritise_taxon_breadcrumbs ||= false %>
<% inverse ||= false %>

<div class='gem-c-contextual-breadcrumbs'>
<% if navigation.content_tagged_to_current_step_by_step? %>
Expand All @@ -8,27 +9,29 @@
navigation.step_nav_helper.header %>
<% elsif navigation.content_tagged_to_a_finder? %>
<%# Rendering finder breadcrumbs because the page is tagged to a finder %>
<%= render 'govuk_publishing_components/components/breadcrumbs', breadcrumbs: navigation.breadcrumbs %>
<%= render 'govuk_publishing_components/components/breadcrumbs', breadcrumbs: navigation.breadcrumbs, inverse: inverse %>
<% elsif navigation.content_is_tagged_to_a_live_taxon? && prioritise_taxon_breadcrumbs %>
<%# Rendering taxonomy breadcrumbs because the page is tagged to live taxons
and we want to prioritise them over all other breadcrumbs %>
<%= render 'govuk_publishing_components/components/breadcrumbs',
breadcrumbs: navigation.taxon_breadcrumbs[:breadcrumbs],
collapse_on_mobile: true %>
collapse_on_mobile: true,
inverse: inverse %>
<% elsif navigation.content_tagged_to_mainstream_browse_pages? %>
<%# Rendering parent-based breadcrumbs because the page is tagged to mainstream browse %>
<%= render 'govuk_publishing_components/components/breadcrumbs', breadcrumbs: navigation.breadcrumbs %>
<%= render 'govuk_publishing_components/components/breadcrumbs', breadcrumbs: navigation.breadcrumbs, inverse: inverse %>
<% elsif navigation.content_has_curated_related_items? %>
<%# Rendering parent-based breadcrumbs because the page has curated related links %>
<%= render 'govuk_publishing_components/components/breadcrumbs', breadcrumbs: navigation.breadcrumbs %>
<%= render 'govuk_publishing_components/components/breadcrumbs', breadcrumbs: navigation.breadcrumbs, inverse: inverse %>
<% elsif navigation.content_is_tagged_to_a_live_taxon? && !navigation.content_is_a_specialist_document? %>
<%# Rendering taxonomy breadcrumbs because the page is tagged to live taxons %>
<%= render 'govuk_publishing_components/components/breadcrumbs',
breadcrumbs: navigation.taxon_breadcrumbs[:breadcrumbs],
collapse_on_mobile: true %>
collapse_on_mobile: true,
inverse: inverse %>
<% elsif navigation.breadcrumbs.any? %>
<%# Rendering parent-based breadcrumbs because no browse, no related links, no live taxons %>
<%= render 'govuk_publishing_components/components/breadcrumbs', breadcrumbs: navigation.breadcrumbs %>
<%= render 'govuk_publishing_components/components/breadcrumbs', breadcrumbs: navigation.breadcrumbs, inverse: inverse %>
<% else %>
<%# Not rendering any breadcrumbs because there aren't any %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ examples:
data:
content_item:
title: "A content item"
inverse:
description: Passes the 'inverse' option to the breadcrumbs, if shown.
data:
content_item:
title: "Another content item"
inverse: true
context:
dark_background: true
20 changes: 20 additions & 0 deletions spec/components/contextual_breadcrumbs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def set_live_taxons(content_item)
assert_select "a", text: "Passports"
end

it "renders inverse parent-based breadcrumbs if the content_item is tagged to mainstream browse" do
render_component(content_item: example_document_for("place", "find-regional-passport-office"), inverse: true)
assert_select ".gem-c-breadcrumbs.gem-c-breadcrumbs--inverse"
end

it "renders curated related items breadcrumbs if the content_item has curated related items" do
content_item = example_document_for("licence", "licence_without_continuation_link")
content_item = remove_mainstream_browse(content_item)
Expand All @@ -67,6 +72,15 @@ def set_live_taxons(content_item)
assert_select "a", text: "Education, training and skills"
end

it "renders inverse taxon breadcrumbs if there are some and no mainstream or curated_content" do
content_item = example_document_for("guide", "guide")
content_item = remove_mainstream_browse(content_item)
content_item = remove_curated_related_item(content_item)
content_item = set_live_taxons(content_item)
render_component(content_item: content_item, inverse: true)
assert_select ".gem-c-breadcrumbs.gem-c-breadcrumbs--inverse"
end

it "renders no taxon breadcrumbs if they are not live" do
content_item = example_document_for("guide", "guide")
content_item = remove_mainstream_browse(content_item)
Expand Down Expand Up @@ -120,6 +134,12 @@ def set_live_taxons(content_item)
assert_select "a", text: "EU Withdrawal Act 2018 statutory instruments"
end

it "renders inverse parent finder breadcrumb" do
content_item = example_document_for("guide", "guide-with-facet-groups")
render_component(content_item: content_item, prioritise_taxon_breadcrumbs: true, inverse: true)
assert_select ".gem-c-breadcrumbs.gem-c-breadcrumbs--inverse"
end

it "renders no breadcrumbs if there aren't any" do
content_item = example_document_for("guide", "guide")
content_item = remove_mainstream_browse(content_item)
Expand Down

0 comments on commit 5558e1f

Please sign in to comment.