Skip to content

Commit

Permalink
Add offices as multi-part content for editionable worldwide organisat…
Browse files Browse the repository at this point in the history
…ions

This includes the content of the worldwide offices in the editionable
worldwide organisation page, allowing us to render them from a single
content item.

Depends on alphagov/publishing-api#2638.
  • Loading branch information
brucebolt committed Feb 14, 2024
1 parent fdf4546 commit fe7478e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class EditionableWorldwideOrganisationPresenter
include ActionView::Helpers::UrlHelper
include ApplicationHelper
include OrganisationHelper
include Presenters::PublishingApi::WorldwideOfficeHelper

attr_accessor :item, :update_type, :state

Expand All @@ -25,10 +26,12 @@ def content
description: item.summary,
details: {
body:,
home_page_office_parts:,
logo: {
crest: "single-identity",
formatted_title: worldwide_organisation_logo_name(item),
},
main_office_parts:,
office_contact_associations:,
people_role_associations:,
social_media_links:,
Expand Down Expand Up @@ -155,5 +158,17 @@ def world_location_names
}
end
end

def home_page_office_parts
return [] unless item.home_page_offices.any?

worldwide_office_parts(item.home_page_offices)
end

def main_office_parts
return [] unless item.main_office

worldwide_office_parts([item.main_office])
end
end
end
14 changes: 12 additions & 2 deletions test/factories/editionable_worldwide_organisations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,23 @@

trait(:with_main_office) do
after :create do |organisation, _evaluator|
FactoryBot.create(:worldwide_office, worldwide_organisation: nil, edition: organisation)
FactoryBot.create(
:worldwide_office,
worldwide_organisation: nil,
edition: organisation,
access_and_opening_times: "our main office opening times",
)
end
end

trait(:with_home_page_offices) do
after :create do |organisation, _evaluator|
worldwide_office = create(:worldwide_office, worldwide_organisation: nil, edition: organisation)
worldwide_office = create(
:worldwide_office,
worldwide_organisation: nil,
edition: organisation,
access_and_opening_times: "our office opening times",
)
organisation.add_office_to_home_page!(worldwide_office)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def present(...)
:with_home_page_offices,
analytics_identifier: "WO123")

main_office_service = create(:worldwide_office_worldwide_service, worldwide_office: worldwide_org.reload.main_office)

primary_role = create(:ambassador_role)
ambassador = create(:person)
create(:ambassador_role_appointment, role: primary_role, person: ambassador)
Expand All @@ -39,10 +41,31 @@ def present(...)
description: worldwide_org.summary,
details: {
body: "<div class=\"govspeak\"><p>Information about the organisation with <em>italics</em>.</p>\n</div>",
home_page_office_parts: [
{
slug: worldwide_org.reload.home_page_offices.first.slug,
access_and_opening_times: Whitehall::GovspeakRenderer.new.govspeak_to_html(worldwide_org.reload.home_page_offices.first.access_and_opening_times),
services: [],
type: worldwide_org.reload.home_page_offices.first.worldwide_office_type.name,
},
],
logo: {
crest: "single-identity",
formatted_title: "Editionable<br/>worldwide<br/>organisation<br/>title",
},
main_office_parts: [
{
access_and_opening_times: Whitehall::GovspeakRenderer.new.govspeak_to_html(worldwide_org.reload.main_office.access_and_opening_times),
services: [
{
title: main_office_service.worldwide_service.name,
type: main_office_service.worldwide_service.service_type.name,
},
],
slug: worldwide_org.reload.main_office.slug,
type: worldwide_org.reload.main_office.worldwide_office_type.name,
},
],
office_contact_associations: [
{
office_content_id: worldwide_org.reload.main_office.content_id,
Expand Down

0 comments on commit fe7478e

Please sign in to comment.