-
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.
Render Worldwide Corporate Information Pages
We have added a new content item to represent Corporate Information Pages that are associated with Worldwide Organisations (alphagov/publishing-api#2399). Because the Worldwide Corporate Information Pages have a link to their Worldwide Organisation, much of the rendering code added for Worldwide Offices and Worldwide Organisations works with this page.
- Loading branch information
1 parent
0d0d746
commit fcb5933
Showing
4 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
app/presenters/worldwide_corporate_information_page_presenter.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,29 @@ | ||
class WorldwideCorporateInformationPagePresenter < ContentItemPresenter | ||
include ContentItem::Body | ||
include ContentItem::ContentsList | ||
include WorldwideOrganisation::Branding | ||
|
||
def show_default_breadcrumbs? | ||
false | ||
end | ||
|
||
def worldwide_organisation | ||
return unless content_item.dig("links", "worldwide_organisation") | ||
|
||
WorldwideOrganisationPresenter.new(content_item.dig("links", "worldwide_organisation").first, requested_path, view_context) | ||
end | ||
|
||
def sponsoring_organisations | ||
worldwide_organisation&.sponsoring_organisations | ||
end | ||
|
||
def organisation_logo | ||
super.merge!(name: worldwide_organisation&.title) | ||
end | ||
|
||
private | ||
|
||
def show_contents_list? | ||
true | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
app/views/content_items/worldwide_corporate_information_page.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,29 @@ | ||
<%= 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"> | ||
<%= render "govuk_publishing_components/components/heading", { | ||
text: @content_item.title, | ||
heading_level: 2, | ||
font_size: "xl", | ||
margin_bottom: 4, | ||
} %> | ||
|
||
<p class="govuk-body-l"><%= @content_item.description %></p> | ||
|
||
<div class="body"> | ||
<%= render "govuk_publishing_components/components/govspeak", {} do | ||
raw(@content_item.body) | ||
end %> | ||
</div> | ||
</div> | ||
</article> |
80 changes: 80 additions & 0 deletions
80
test/integration/worldwide_corporate_information_page_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,80 @@ | ||
require "test_helper" | ||
|
||
class WorldwideCorporateInformationPageTest < ActionDispatch::IntegrationTest | ||
test "includes the title of the organisation" do | ||
setup_and_visit_content_item("worldwide_corporate_information_page") | ||
|
||
assert page.has_title?("British Embassy Manila") | ||
end | ||
|
||
test "omits breadcrumbs" do | ||
setup_and_visit_content_item("worldwide_corporate_information_page") | ||
|
||
assert page.has_no_selector?(".govuk-breadcrumbs") | ||
end | ||
|
||
test "includes the body and contents" do | ||
setup_and_visit_content_item("worldwide_corporate_information_page") | ||
|
||
assert page.has_content? "Contents" | ||
assert_has_contents_list([ | ||
{ text: "General information", id: "general-information" }, | ||
{ text: "Current work opportunities", id: "current-work-opportunities" }, | ||
]) | ||
assert page.has_content?("Fair competition is at the centre of recruitment at the British Embassy Manila.") | ||
end | ||
|
||
test "includes the description" do | ||
setup_and_visit_content_item("worldwide_corporate_information_page") | ||
|
||
assert page.has_content? "The description for the worldwide corporate information page" | ||
end | ||
|
||
test "includes the logo and name of the worldwide organisation as a link" do | ||
setup_and_visit_content_item("worldwide_corporate_information_page") | ||
|
||
assert_has_component_organisation_logo | ||
assert page.has_link? "British Embassy Manila", href: "/world/organisations/british-embassy-manila" | ||
end | ||
|
||
test "includes the world locations and sponsoring organisations" do | ||
setup_and_visit_content_item("worldwide_corporate_information_page") | ||
|
||
within find(".worldwide-organisation-header__metadata", match: :first) do | ||
assert page.has_link? "Philippines", href: "/world/philippines/news" | ||
assert page.has_link? "Palau", href: "/world/palau/news" | ||
|
||
assert page.has_link? "Foreign, Commonwealth & Development Office", href: "/government/organisations/foreign-commonwealth-development-office" | ||
end | ||
end | ||
|
||
test "does not render the translations when there are no translations" do | ||
setup_and_visit_content_item("worldwide_corporate_information_page") | ||
|
||
assert_not page.has_text?("English") | ||
end | ||
|
||
test "renders the translations when there are translations" do | ||
setup_and_visit_content_item( | ||
"worldwide_corporate_information_page", | ||
{ | ||
"links" => { | ||
"available_translations" => | ||
[ | ||
{ | ||
"locale": "en", | ||
"base_path": "/world/organisations/british-embassy-madrid/about/recruitment", | ||
}, | ||
{ | ||
"locale": "es", | ||
"base_path": "/world/organisations/british-embassy-madrid/about/recruitment.es", | ||
}, | ||
], | ||
}, | ||
}, | ||
) | ||
|
||
assert page.has_text?("English") | ||
assert page.has_link?("Español", href: "/world/organisations/british-embassy-madrid/about/recruitment.es") | ||
end | ||
end |
54 changes: 54 additions & 0 deletions
54
test/presenters/worldwide_corporate_information_page_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,54 @@ | ||
require "presenter_test_helper" | ||
|
||
class WorldwideCorporateInformationPagePresenterTest < PresenterTestCase | ||
def schema_name | ||
"worldwide_corporate_information_page" | ||
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["details"]["body"], presented_item.body | ||
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 = create_presenter(WorldwideCorporateInformationPagePresenter, content_item: with_non_default_crest) | ||
|
||
expected = { name: "British Embassy Manila", url: "/world/organisations/british-embassy-manila", 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 = create_presenter(WorldwideCorporateInformationPagePresenter, content_item: with_empty_logo) | ||
|
||
expected = { name: "British Embassy Manila", url: "/world/organisations/british-embassy-manila", 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"]["worldwide_organisation"][0]["links"].delete("sponsoring_organisations") | ||
|
||
presented = create_presenter(WorldwideCorporateInformationPagePresenter, content_item: without_sponsoring_organisations) | ||
|
||
expected = { name: "British Embassy Manila", url: "/world/organisations/british-embassy-manila", crest: "single-identity", brand: "single-identity" } | ||
assert_equal expected, presented.organisation_logo | ||
end | ||
|
||
private | ||
|
||
def first_sponsoring_organisation(item) | ||
item["links"]["worldwide_organisation"][0]["links"]["sponsoring_organisations"][0] | ||
end | ||
end |