Skip to content

Commit

Permalink
Use remove_breadcrumbs method to omit breadcrumbs
Browse files Browse the repository at this point in the history
This relies on the content item for the landing page existing, which it doesn't yet, and so it looks broken (both sets of breadcrumbs are currently rendering)
  • Loading branch information
JamesCGDS committed Oct 17, 2024
1 parent 92265b3 commit 7d69c34
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,14 @@ def wrapper_class(publication = nil)
def current_path_without_query_string
request.original_fullpath.split("?", 2).first
end

def remove_breadcrumbs(content_item)
remove_breadcrumbs = false

if content_item.respond_to?(:is_a_landing_page?) && content_item.is_a_landing_page?
remove_breadcrumbs = true
end

remove_breadcrumbs
end
end
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<% if publication && publication.in_beta %>
<%= render 'govuk_publishing_components/components/phase_banner', phase: "beta" %>
<% end %>
<% unless current_page?(root_path) || !(publication || @calendar) || !content_item.is_a_landing_page? %>
<% unless current_page?(root_path) || !(publication || @calendar) || remove_breadcrumbs(content_item) %>
<%= render 'govuk_publishing_components/components/contextual_breadcrumbs', content_item: content_item_hash %>
<% end %>
<% if local_assigns %>
Expand Down
26 changes: 26 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,30 @@ def dummy_publication
expect(current_path_without_query_string).to eq("/foo/bar")
end
end

describe "#remove_breadcrumbs" do
describe "when is_landing_page? is true" do
let(:content_item) { ContentItem.new({ "schema" => "landing_page" }) }

it "removes breadcrumbs" do
expect(remove_breadcrumbs(content_item)).to eq(true)
end
end

describe "when is_landing_page? is false" do
let(:content_item) { ContentItem.new({ "schema" => "a_different_page" }) }

it "does not remove breadcrumbs" do
expect(remove_breadcrumbs(content_item)).to eq(false)
end
end

describe "when is_landing_page? is undefined" do
let(:content_item) { ContentItem.new({ }) }

Check failure on line 70 in spec/helpers/application_helper_spec.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Layout/SpaceInsideHashLiteralBraces: Space inside empty hash literal braces detected. (https://rubystyle.guide#spaces-braces)

it "does not remove breadcrumbs" do
expect(remove_breadcrumbs(content_item)).to eq(false)
end
end
end
end

0 comments on commit 7d69c34

Please sign in to comment.