Skip to content

Commit

Permalink
Display an H1 of the page title on some worldwide org pages
Browse files Browse the repository at this point in the history
  • Loading branch information
hannako committed Jan 17, 2025
1 parent d7c3224 commit b65317e
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def show_default_breadcrumbs?
false
end

def display_page_title?
false
end

def worldwide_organisation
return unless content_item.dig("links", "worldwide_organisation")

Expand Down
4 changes: 4 additions & 0 deletions app/presenters/worldwide_office_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ def formatted_title
worldwide_organisation&.formatted_title
end

def display_page_title?
false
end

def body
content_item.dig("details", "access_and_opening_times")
end
Expand Down
10 changes: 10 additions & 0 deletions app/presenters/worldwide_organisation_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@ class WorldwideOrganisationPresenter < ContentItemPresenter
include ContentItem::Body
include WorldwideOrganisation::Branding
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::SanitizeHelper

WorldwideOffice = Struct.new(:contact, :has_access_and_opening_times?, :public_url, keyword_init: true)

def formatted_title
content_item.dig("details", "logo", "formatted_title")
end

def display_page_title?
return if sponsoring_organisations.empty?
return if formatted_title.nil? || content_item["title"].nil?

logo_formatted_title = strip_tags(formatted_title).gsub(/\s+/, "")
page_title = content_item["title"].gsub(/\s+/, "")
logo_formatted_title != page_title
end

def sponsoring_organisation_links
return if sponsoring_organisations.empty?

Expand Down
22 changes: 16 additions & 6 deletions app/views/content_items/worldwide_organisation/_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
<% locals = { organisation: @content_item.organisation_logo, inline: true, heading_level: 1 }
if @content_item.display_page_title?
locals.merge!(margin_bottom: 9)
locals.delete(:heading_level)
end
%>

<header class="worldwide-organisation-header govuk-grid-row">
<div class="govuk-grid-column-two-thirds worldwide-organisation-header__logo">
<%= render "govuk_publishing_components/components/organisation_logo", {
organisation: @content_item.organisation_logo,
heading_level: 1,
inline: true,
} %>
<%= render "govuk_publishing_components/components/organisation_logo", locals %>
<% if @content_item.display_page_title? %>
<%= render "govuk_publishing_components/components/heading", {
text: @content_item.title,
heading_level: 1,
font_size: "l",
margin_bottom: 5,
} %>
<% end %>
</div>

<div class="govuk-grid-column-one-third govuk-!-padding-top-2">
<% if @content_item.available_translations.length > 1 %>
<%= render 'govuk_publishing_components/components/translation_nav',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def schema_name
assert_equal expected, presented.organisation_logo
end

test "#display_page_title? returns false" do
assert_not presented_item.display_page_title?
end

private

def first_sponsoring_organisation(item)
Expand Down
4 changes: 4 additions & 0 deletions test/presenters/worldwide_office_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def schema_name
assert_equal expected, presented.organisation_logo
end

test "#display_page_title? returns false" do
assert_not presented_item.display_page_title?
end

private

def first_sponsoring_organisation(item)
Expand Down
18 changes: 18 additions & 0 deletions test/presenters/worldwide_organisation_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,22 @@ def schema_name

assert_equal [], presented.home_page_offices
end

test "#display_page_title? returns true if the formatted logo title is different to the page title" do
content_item = schema_item
content_item["title"] = "Department for Business and Trade Paraguay"
content_item["details"]["logo"]["formatted_title"] = "Department for Business and Trade"

presented = create_presenter(WorldwideOrganisationPresenter, content_item: content_item)
assert presented.display_page_title?
end

test "#display_page_title? returns false if the formatted logo has the same text as the page title" do
content_item = schema_item
content_item["title"] = "Department for Business and Trade Paraguay"
content_item["details"]["logo"]["formatted_title"] = "Department for Business and Trade<br/>Paraguay"

presented = create_presenter(WorldwideOrganisationPresenter, content_item: content_item)
assert_not presented.display_page_title?
end
end

0 comments on commit b65317e

Please sign in to comment.