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

Render custom organisation logos when provided #246

Merged
merged 2 commits into from Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/presenters/html_publication_presenter.rb
Expand Up @@ -31,4 +31,12 @@ def last_changed
def organisations
content_item["links"]["organisations"].sort_by { |o| o["title"] }
end

def organisation_logo(organisation)
super.tap do |logo|
if organisations.count > 1
logo[:organisation].delete(:image)
end
end
end
end
17 changes: 14 additions & 3 deletions app/presenters/organisation_branding.rb
@@ -1,13 +1,24 @@
module OrganisationBranding
def organisation_logo(organisation = default_organisation)
{
logo = organisation["details"]["logo"]

logo_component_params = {
organisation: {
name: organisation["details"]["logo"]["formatted_title"],
name: logo["formatted_title"],
url: organisation["base_path"],
brand: organisation_brand(organisation),
crest: organisation["details"]["logo"]["crest"]
crest: logo["crest"],
}
}

if logo["image"]
logo_component_params[:organisation][:image] = {
url: logo["image"]["url"],
alt_text: logo["image"]["alt_text"],
}
end

logo_component_params
end

def organisation_brand_class(organisation = default_organisation)
Expand Down
6 changes: 5 additions & 1 deletion app/views/content_items/corporate_information_page.html.erb
@@ -1,7 +1,11 @@
<%= content_for :title, @content_item.page_title %>

<div class="<%= @content_item.organisation_brand_class %>">
<%= render 'govuk_component/organisation_logo', @content_item.organisation_logo %>
<div class="grid-row">
<div class="column-quarter">
<%= render 'govuk_component/organisation_logo', @content_item.organisation_logo %>
</div>
</div>
<%= render 'shared/title_and_translations', content_item: @content_item %>
<%= render 'shared/description', description: @content_item.description %>

Expand Down
16 changes: 16 additions & 0 deletions test/integration/corporate_information_page_test.rb
Expand Up @@ -39,4 +39,20 @@ class CorporateInformationPageTest < ActionDispatch::IntegrationTest
}
)
end

test "renders a custom organisation logo" do
setup_and_visit_content_item('corporate_information_page_translated_custom_logo')
assert_has_component_organisation_logo(
organisation: {
name: 'Land Registry',
url: '/government/organisations/land-registry',
brand: 'department-for-business-innovation-skills',
crest: nil,
image: {
url: 'https://assets.publishing.service.gov.uk/government/uploads/system/uploads/organisation/logo/69/LR_logo_265.png',
alt_text: 'Land Registry'
}
}
)
end
end
21 changes: 21 additions & 0 deletions test/presenters/html_publication_presenter_test.rb
Expand Up @@ -39,4 +39,25 @@ def format_name
test 'has organisation branding' do
assert presented_item("published").is_a?(OrganisationBranding)
end

test 'includes custom organisation logos when a single organisation is listed' do
presented = presented_item("updated")
organisation = presented.organisations.first
example_logo = schema_item("updated")["links"]["organisations"][0]["details"]["logo"]["image"].symbolize_keys
presented_logo = presented.organisation_logo(organisation)[:organisation][:image]

assert presented.organisations.count == 1
assert_equal example_logo, presented_logo
end

test 'hides custom organisation logos when multiple organisations listed together' do
presented = presented_item("multiple_organisations")
organisation = presented.organisations.first
organisation["details"]["logo"]["image"] = {
"url" => "url"
}

assert presented.organisations.count > 1
refute presented.organisation_logo(organisation)[:organisation][:image]
end
end
13 changes: 13 additions & 0 deletions test/presenters/organisation_branding_test.rb
Expand Up @@ -36,4 +36,17 @@ def test_organisation
refute_equal organisation_brand(organisation), test_organisation["details"]["brand"]
assert_equal organisation_brand(organisation), "executive-office"
end

test "includes an image organisations with a custom logo" do
organisation = test_organisation
organisation["details"]["logo"]["image"] = {
"url" => "url",
"alt_text" => "alt_text"
}

logo = organisation_logo(organisation)

assert_equal logo[:organisation][:image][:url], organisation["details"]["logo"]["image"]["url"]
assert_equal logo[:organisation][:image][:alt_text], organisation["details"]["logo"]["image"]["alt_text"]
end
end