From b65317ec0f62f6fc4a97e123a30206ed69f940aa Mon Sep 17 00:00:00 2001 From: Jessica Jones Date: Fri, 17 Jan 2025 14:27:54 +0000 Subject: [PATCH] Display an H1 of the page title on some worldwide org pages --- ...de_corporate_information_page_presenter.rb | 4 ++++ app/presenters/worldwide_office_presenter.rb | 4 ++++ .../worldwide_organisation_presenter.rb | 10 +++++++++ .../worldwide_organisation/_header.html.erb | 22 ++++++++++++++----- ...rporate_information_page_presenter_test.rb | 4 ++++ .../worldwide_office_presenter_test.rb | 4 ++++ .../worldwide_organisation_presenter_test.rb | 18 +++++++++++++++ 7 files changed, 60 insertions(+), 6 deletions(-) diff --git a/app/presenters/worldwide_corporate_information_page_presenter.rb b/app/presenters/worldwide_corporate_information_page_presenter.rb index d305f5d84..963ea9973 100644 --- a/app/presenters/worldwide_corporate_information_page_presenter.rb +++ b/app/presenters/worldwide_corporate_information_page_presenter.rb @@ -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") diff --git a/app/presenters/worldwide_office_presenter.rb b/app/presenters/worldwide_office_presenter.rb index d65d7fc63..880eeda6d 100644 --- a/app/presenters/worldwide_office_presenter.rb +++ b/app/presenters/worldwide_office_presenter.rb @@ -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 diff --git a/app/presenters/worldwide_organisation_presenter.rb b/app/presenters/worldwide_organisation_presenter.rb index 667d7aea4..0ef68e7f7 100644 --- a/app/presenters/worldwide_organisation_presenter.rb +++ b/app/presenters/worldwide_organisation_presenter.rb @@ -2,6 +2,7 @@ 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) @@ -9,6 +10,15 @@ 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? diff --git a/app/views/content_items/worldwide_organisation/_header.html.erb b/app/views/content_items/worldwide_organisation/_header.html.erb index 1166ae533..2c3680dcf 100644 --- a/app/views/content_items/worldwide_organisation/_header.html.erb +++ b/app/views/content_items/worldwide_organisation/_header.html.erb @@ -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 +%> +
-
<% if @content_item.available_translations.length > 1 %> <%= render 'govuk_publishing_components/components/translation_nav', diff --git a/test/presenters/worldwide_corporate_information_page_presenter_test.rb b/test/presenters/worldwide_corporate_information_page_presenter_test.rb index b3e1a2c40..bcdcf9464 100644 --- a/test/presenters/worldwide_corporate_information_page_presenter_test.rb +++ b/test/presenters/worldwide_corporate_information_page_presenter_test.rb @@ -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) diff --git a/test/presenters/worldwide_office_presenter_test.rb b/test/presenters/worldwide_office_presenter_test.rb index cdd0bdddd..c786c5833 100644 --- a/test/presenters/worldwide_office_presenter_test.rb +++ b/test/presenters/worldwide_office_presenter_test.rb @@ -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) diff --git a/test/presenters/worldwide_organisation_presenter_test.rb b/test/presenters/worldwide_organisation_presenter_test.rb index cad961b01..8e35b648e 100644 --- a/test/presenters/worldwide_organisation_presenter_test.rb +++ b/test/presenters/worldwide_organisation_presenter_test.rb @@ -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
Paraguay" + + presented = create_presenter(WorldwideOrganisationPresenter, content_item: content_item) + assert_not presented.display_page_title? + end end