-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use breadcrumbs based on organisation if no parent
Use breadcrumbs based on ancestors, if the document has a linked parent. Otherwise use breadcrumbs based on the first normal (non-world) organisation the page is linked to. If there are no linked organisations use taxon based breadcrumbs, or if taxons are also not linked to, the default breadcrumbs pointing to the homepage.
- Loading branch information
Showing
10 changed files
with
264 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_organisations.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module GovukPublishingComponents | ||
module Presenters | ||
# @private | ||
class ContentBreadcrumbsBasedOnOrganisations | ||
def self.call(content_item) | ||
new(content_item).breadcrumbs | ||
end | ||
|
||
def initialize(content_item) | ||
@content_item = ContentItem.new(content_item) | ||
end | ||
|
||
def breadcrumbs | ||
[ | ||
{ title: "Home", url: "/" }, | ||
*organisation_breadcrumbs_items, | ||
] | ||
end | ||
|
||
private | ||
|
||
attr_reader :content_item | ||
|
||
def organisation_breadcrumbs_items | ||
first_related_organisation = ContentItem.new(content_item.related_organisations.first) | ||
return [] unless first_related_organisation.present? | ||
|
||
[{ | ||
title: first_related_organisation.title, | ||
url: first_related_organisation.base_path, | ||
}] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
spec/lib/govuk_publishing_components/presenters/breadcrumb_selector_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe GovukPublishingComponents::Presenters::BreadcrumbSelector do | ||
subject do | ||
described_class.new( | ||
content_item, | ||
request, | ||
prioritise_taxon_breadcrumbs, | ||
disable_ga4, | ||
) | ||
end | ||
let(:example) { %w[guide guide] } | ||
let(:content_item) { example_document_for(example.first, example.secomd) } | ||
let(:path) { content_item["base_path"] } | ||
let(:query_parameters) { {} } | ||
let(:request) { instance_double("ActionDispatch::Request", path:, query_parameters:) } | ||
let(:prioritise_taxon_breadcrumbs) { false } | ||
let(:disable_ga4) { false } | ||
|
||
def example_document_for(schema_name, example_name) | ||
GovukSchemas::Example.find(schema_name, example_name:) | ||
end | ||
|
||
describe "#initialize" do | ||
it "does not raise exception" do | ||
expect { subject }.not_to raise_error | ||
end | ||
end | ||
|
||
describe "#breadcrumbs" do | ||
context "when content item is corporate information page with parent" do | ||
let(:example) { %w[corporate_information_page corporate_information_page_complaints] } | ||
|
||
it "returns breadcrumbs based on ancestors" do | ||
expect(subject.breadcrumbs).to eq([ | ||
{ title: "Home", url: "/" }, | ||
{ title: "Department of Health", url: "/government/organisations/department-of-health" }, | ||
{ title: "About us", url: "/government/organisations/department-of-health/about" }, | ||
]) | ||
end | ||
end | ||
|
||
context "when content item is corporate information page without parent but with organisation" do | ||
let(:example) { %w[corporate_information_page best-practice-about-page] } | ||
|
||
it "returns breadcrumbs based on organisation" do | ||
expect(subject.breadcrumbs).to eq([ | ||
{ title: "Home", url: "/" }, | ||
{ title: "Intellectual Property Office", url: "/government/organisations/intellectual-property-office" }, | ||
]) | ||
end | ||
end | ||
|
||
context "when content item is corporate information page without parent, organisations but with taxon" do | ||
let(:content_item) do | ||
item = example_document_for("corporate_information_page", "best-practice-about-page") | ||
item.dig("links", "organisations").clear | ||
item["links"]["taxons"] = [{ | ||
"base_path" => "/corporate-information", | ||
"title" => "Corporate information", | ||
"phase" => "live", | ||
}] | ||
item | ||
end | ||
|
||
it "returns breadcrumbs based on taxons" do | ||
expect(subject.breadcrumbs).to eq([ | ||
{ title: "Home", url: "/", is_page_parent: false }, | ||
{ title: "Corporate information", url: "/corporate-information", is_page_parent: true }, | ||
]) | ||
end | ||
end | ||
|
||
context "when content item is corporate information page without parent, organisations and taxons" do | ||
let(:content_item) do | ||
item = example_document_for("corporate_information_page", "best-practice-about-page") | ||
item.dig("links", "organisations").clear | ||
item | ||
end | ||
|
||
it "returns default breadcrumbs" do | ||
expect(subject.breadcrumbs).to eq([ | ||
{ title: "Home", url: "/" }, | ||
]) | ||
end | ||
end | ||
end | ||
end |
24 changes: 24 additions & 0 deletions
24
...govuk_publishing_components/presenters/content_breadcrumbs_based_on_organisations_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe GovukPublishingComponents::Presenters::ContentBreadcrumbsBasedOnOrganisations do | ||
subject { described_class.new(content_item) } | ||
let(:content_item) { GovukSchemas::Example.find("document_collection", example_name: "document_collection") } | ||
|
||
describe "#initialize" do | ||
it "does not raise exception" do | ||
expect { subject }.not_to raise_error | ||
end | ||
end | ||
|
||
describe "#breadcrumbs" do | ||
it "returns breadcrumbs based on organisation" do | ||
expect(subject.breadcrumbs).to eq([ | ||
{ title: "Home", url: "/" }, | ||
{ | ||
title: "Driver and Vehicle Standards Agency", | ||
url: "/government/organisations/driver-and-vehicle-standards-agency", | ||
}, | ||
]) | ||
end | ||
end | ||
end |
81 changes: 81 additions & 0 deletions
81
spec/lib/govuk_publishing_components/presenters/contextual_navigation_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe GovukPublishingComponents::Presenters::ContextualNavigation do | ||
subject { described_class.new(content_item, request) } | ||
let(:content_item) { GovukSchemas::Example.find("guide", example_name: "guide") } | ||
let(:path) { content_item["base_path"] } | ||
let(:query_parameters) { {} } | ||
let(:request) { instance_double("ActionDispatch::Request", path:, query_parameters:) } | ||
|
||
describe "#initialize" do | ||
it "does not raise exception" do | ||
expect { subject }.not_to raise_error | ||
end | ||
end | ||
|
||
describe "#organisation_breadcrumbs" do | ||
it "calls ContentBreadcrumbsBasedOnOrganisation" do | ||
called_class = GovukPublishingComponents::Presenters::ContentBreadcrumbsBasedOnOrganisations | ||
expect(called_class).to receive(:call) | ||
.with(content_item) | ||
.and_return([]) | ||
subject.organisation_breadcrumbs | ||
end | ||
end | ||
|
||
describe "#content_has_related_organisations?" do | ||
context "when content item is linked to no organisations" do | ||
let(:content_item) do | ||
GovukSchemas::Example.find( | ||
"homepage", | ||
example_name: "homepage_with_popular_links_on_govuk", | ||
) | ||
end | ||
|
||
it "returns false" do | ||
expect(subject.content_has_related_organisations?).to be(false) | ||
end | ||
end | ||
|
||
context "when content item is only linked to world organisations" do | ||
let(:content_item) do | ||
GovukSchemas::Example.find( | ||
"worldwide_corporate_information_page", | ||
example_name: "worldwide_corporate_information_page", | ||
) | ||
end | ||
|
||
it "returns false" do | ||
expect(subject.content_has_related_organisations?).to be(false) | ||
end | ||
end | ||
|
||
context "when content item is linked to at least 1 normal organisation" do | ||
let(:content_item) { GovukSchemas::Example.find("document_collection", example_name: "document_collection") } | ||
|
||
it "returns true" do | ||
expect(subject.content_has_related_organisations?).to be(true) | ||
end | ||
end | ||
end | ||
|
||
describe "#content_is_a_corporate_information_page?" do | ||
context "when content item is corporate information page" do | ||
let(:content_item) do | ||
GovukSchemas::Example.find("corporate_information_page", example_name: "corporate_information_page") | ||
end | ||
|
||
it "returns true" do | ||
expect(subject.content_is_a_corporate_information_page?).to be(true) | ||
end | ||
end | ||
|
||
context "when content item is not corporate information page" do | ||
let(:content_item) { GovukSchemas::Example.find("guide", example_name: "guide") } | ||
|
||
it "returns false" do | ||
expect(subject.content_is_a_corporate_information_page?).to be(false) | ||
end | ||
end | ||
end | ||
end |