-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for worldwide offices embedded in worldwide organisations
As part of the switch to Worldwide Organisation content items containing the content for their offices, we need to switch the rendering of the office pages to use these parts. This makes that switch in a backward compatible way, so we can continue rendering office pages under the existing content items until the office routes are updated to point to the organisation's content item. In a later PR, we will remove `WorldwideOfficePresenter` and it's associated view.
- Loading branch information
Showing
7 changed files
with
164 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
class WorldwideOrganisationOfficePresenter < ContentItemPresenter | ||
include ContentItem::ContentsList | ||
include WorldwideOrganisation::Branding | ||
|
||
def formatted_title | ||
worldwide_organisation&.formatted_title | ||
end | ||
|
||
def body | ||
office["access_and_opening_times"] | ||
end | ||
|
||
def contact | ||
associated_contact = content_item.dig("links", "contacts").select { |contact| | ||
contact["content_id"] == office["contact_content_id"] | ||
}.first | ||
|
||
WorldwideOrganisation::LinkedContactPresenter.new(associated_contact) | ||
end | ||
|
||
def show_default_breadcrumbs? | ||
false | ||
end | ||
|
||
def office | ||
all_offices = content_item.dig("details", "main_office_parts") + content_item.dig("details", "home_page_office_parts") | ||
|
||
all_offices.select { |office| | ||
office["slug"] == requested_path.gsub("#{content_item['base_path']}/", "") | ||
}.first | ||
end | ||
|
||
def worldwide_organisation | ||
WorldwideOrganisationPresenter.new(content_item, requested_path, view_context) | ||
end | ||
|
||
def sponsoring_organisations | ||
worldwide_organisation&.sponsoring_organisations | ||
end | ||
|
||
private | ||
|
||
def show_contents_list? | ||
true | ||
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
35 changes: 35 additions & 0 deletions
35
app/views/content_items/worldwide_organisation_office.html.erb
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,35 @@ | ||
<%= render partial: "content_items/worldwide_organisation/header", locals: { | ||
worldwide_organisation: @content_item.worldwide_organisation, | ||
} %> | ||
|
||
<article class="govuk-grid-row"> | ||
<div class="govuk-grid-column-one-third"> | ||
<%= render "govuk_publishing_components/components/contents_list", | ||
contents: @content_item.contents, | ||
underline_links: true | ||
%> | ||
</div> | ||
|
||
<div class="govuk-grid-column-two-thirds"> | ||
<div class="body"> | ||
<%= render "govuk_publishing_components/components/heading", { | ||
text: sanitize("<span class='govuk-visually-hidden'>About </span>#{@content_item.contact.title}"), | ||
heading_level: 2, | ||
font_size: "xl", | ||
margin_bottom: 4, | ||
} %> | ||
|
||
<hr class="govuk-section-break govuk-section-break--visible"> | ||
<div class="govuk-!-padding-top-6 govuk-!-padding-bottom-6 govuk-clearfix"> | ||
<%= render partial: "content_items/worldwide_organisation/contact", locals: { | ||
contact: @content_item.contact, | ||
hide_title: true, | ||
} %> | ||
</div> | ||
|
||
<%= render "govuk_publishing_components/components/govspeak", {} do | ||
raw(@content_item.body) | ||
end %> | ||
</div> | ||
</div> | ||
</article> |
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
70 changes: 70 additions & 0 deletions
70
test/presenters/worldwide_organisation_office_presenter_test.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,70 @@ | ||
require "presenter_test_helper" | ||
|
||
class WorldwideOrganisationOfficePresenterTest < PresenterTestCase | ||
def schema_name | ||
"worldwide_organisation" | ||
end | ||
|
||
def requested_path | ||
"#{schema_item['base_path']}/#{schema_item.dig('details', 'main_office_parts', 0, 'slug')}" | ||
end | ||
|
||
def present_example(example) | ||
create_presenter( | ||
"WorldwideOrganisationOfficePresenter".safe_constantize, | ||
content_item: example, | ||
requested_path:, | ||
) | ||
end | ||
|
||
test "#title returns the title of the schema item" do | ||
assert_equal schema_item["title"], presented_item.title | ||
end | ||
|
||
test "#body returns the access and opening times of the schema item" do | ||
assert_equal schema_item.dig("details", "main_office_parts", 0, "access_and_opening_times"), presented_item.body | ||
end | ||
|
||
test "#contact returns the contact as an instance of #{WorldwideOrganisation::LinkedContactPresenter}" do | ||
assert presented_item.contact.is_a?(WorldwideOrganisation::LinkedContactPresenter) | ||
end | ||
|
||
test "#sponsoring_organisation_logo returns the logo details of the item" do | ||
with_non_default_crest = schema_item | ||
sponsoring_organisation = first_sponsoring_organisation(with_non_default_crest) | ||
sponsoring_organisation["details"]["logo"]["crest"] = "dbt" | ||
|
||
presented = present_example(with_non_default_crest) | ||
|
||
expected = { name: "British Deputy High Commission<br/>Hyderabad", url: "/world/uk-embassy-in-country", crest: "dbt", brand: "foreign-commonwealth-development-office" } | ||
assert_equal expected, presented.organisation_logo | ||
end | ||
|
||
test "#sponsoring_organisation_logo returns default values when the crest and brand of the first sponsoring organisation are blank" do | ||
with_empty_logo = schema_item | ||
sponsoring_organisation = first_sponsoring_organisation(with_empty_logo) | ||
sponsoring_organisation["details"]["logo"]["crest"] = nil | ||
sponsoring_organisation["details"]["brand"] = nil | ||
|
||
presented = present_example(with_empty_logo) | ||
|
||
expected = { name: "British Deputy High Commission<br/>Hyderabad", url: "/world/uk-embassy-in-country", crest: "single-identity", brand: "single-identity" } | ||
assert_equal expected, presented.organisation_logo | ||
end | ||
|
||
test "#sponsoring_organisation_logo returns default values when the sponsoring organisations are nil" do | ||
without_sponsoring_organisations = schema_item | ||
without_sponsoring_organisations["links"].delete("sponsoring_organisations") | ||
|
||
presented = present_example(without_sponsoring_organisations) | ||
|
||
expected = { name: "British Deputy High Commission<br/>Hyderabad", url: "/world/uk-embassy-in-country", crest: "single-identity", brand: "single-identity" } | ||
assert_equal expected, presented.organisation_logo | ||
end | ||
|
||
private | ||
|
||
def first_sponsoring_organisation(item) | ||
item["links"]["sponsoring_organisations"][0] | ||
end | ||
end |