-
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.
Merge pull request #4270 from alphagov/2832-fix-corporate-information…
…-pages-should-have-a-parent-of-an-org-page-l Use breadcrumbs based on organisation, if no parent linked
- Loading branch information
Showing
10 changed files
with
283 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
36 changes: 36 additions & 0 deletions
36
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,36 @@ | ||
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: "/" }, | ||
{ title: "Organisations", url: "/government/organisations" }, | ||
*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
89 changes: 89 additions & 0 deletions
89
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,89 @@ | ||
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.second) } | ||
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 parent-based breadcrumbs" 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: "Organisations", url: "/government/organisations" }, | ||
{ 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 |
25 changes: 25 additions & 0 deletions
25
...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,25 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe GovukPublishingComponents::Presenters::ContentBreadcrumbsBasedOnOrganisations do | ||
subject { described_class.new(content_item) } | ||
let(:content_item) { GovukSchemas::Example.find("corporate_information_page", example_name: "best-practice-about-page") } | ||
|
||
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: "Organisations", url: "/government/organisations" }, | ||
{ | ||
title: "Intellectual Property Office", | ||
url: "/government/organisations/intellectual-property-office", | ||
}, | ||
]) | ||
end | ||
end | ||
end |
92 changes: 92 additions & 0 deletions
92
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,92 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe GovukPublishingComponents::Presenters::ContextualNavigation do | ||
subject { described_class.new(content_item, request) } | ||
let(:example) { %w[guide guide] } | ||
let(:content_item) { example_document_for(example.first, example.second) } | ||
let(:path) { content_item["base_path"] } | ||
let(:query_parameters) { {} } | ||
let(:request) { instance_double("ActionDispatch::Request", path:, query_parameters:) } | ||
|
||
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 "#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(:example) { %w[homepage homepage_with_popular_links_on_govuk] } | ||
|
||
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(:example) { %w[worldwide_corporate_information_page worldwide_corporate_information_page] } | ||
|
||
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(:example) { %w[document_collection 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(:example) { %w[corporate_information_page corporate_information_page] } | ||
|
||
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(:example) { %w[guide guide] } | ||
|
||
it "returns false" do | ||
expect(subject.content_is_a_corporate_information_page?).to be(false) | ||
end | ||
end | ||
end | ||
|
||
describe "#use_organisation_breadcrumbs?" do | ||
context "when content item is corporate information page linked to at least 1 normal organisation" do | ||
let(:example) { %w[corporate_information_page best-practice-working-at] } | ||
|
||
it "returns true" do | ||
expect(subject.use_organisation_breadcrumbs?).to be(true) | ||
end | ||
end | ||
|
||
context "when content item is not corporate information page linked to at least 1 normal organisation" do | ||
let(:example) { %w[worldwide_corporate_information_page worldwide_corporate_information_page] } | ||
|
||
it "returns false" do | ||
expect(subject.use_organisation_breadcrumbs?).to be(false) | ||
end | ||
end | ||
end | ||
end |