Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display an H1 of the page title on some worldwide org pages #3525

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion test/integration/worldwide_organisation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class WorldwideOrganisationTest < ActionDispatch::IntegrationTest
test "renders basic worldwide organisation page" do
setup_and_visit_content_item("worldwide_organisation")
assert_has_component_title("British Deputy High Commission\nHyderabad")
assert_has_component_title("UK Embassy in Country")
assert page.has_text?(@content_item["description"])
end

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
Loading