Skip to content

Commit

Permalink
Display protection_type logo
Browse files Browse the repository at this point in the history
This is a departmental request that came through
[Zendesk](https://govuk.zendesk.com/agent/tickets/4197468) and will
conditionally display logos for specialist documents of the newly added
type `protected_food_drink_name`.

Context on why and how `protected_food_drink_name` was added can be
found in these PRs:
- alphagov/specialist-publisher#1720
- alphagov/govuk-content-schemas#1013
- alphagov/search-api#2186
- #1867

The logos added are placeholders while we wait for higher resolution and
properly cropped ones.

The test added in
`test/presenters/specialist_document_presenter_test.rb:21`
depends on the the schema example added in
alphagov/govuk-content-schemas#1020

Trello card: https://trello.com/c/NKJYyZep/2157-3-update-protected-food-names-frontend-template
  • Loading branch information
Alan Gabbianelli committed Oct 16, 2020
1 parent 5935df4 commit df976ff
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions app/assets/stylesheets/views/_specialist-document.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.specialist-document {
@include sidebar-with-body;
}

.protected-food-drink-name-logo {
float: right;
width: 150px;
padding-left: 2em;
padding-bottom: 2em;
}
25 changes: 25 additions & 0 deletions app/presenters/specialist_document_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ def finder_link
end
end

def protected_food_drink_name?
content_item["document_type"] == "protected_food_drink_name"
end

def protection_type
content_item.dig("details", "metadata", "protection_type")
end

def images
{
"protected-designation-of-origin-pdo" => {
"url" => view_context.image_url("protected-food-drink-names/protected-designation-of-origin-pdo.png"),
"alt_text" => "The scheme logo is a black stamp with the words Designated Origin UK Protected",
},
"protected-geographical-indication-pgi" => {
"url" => view_context.image_url("protected-food-drink-names/protected-geographical-indication-pgi.png"),
"alt_text" => "The scheme logo is a black stamp with the words Geographic Origin UK Protected",
},
"traditional-speciality-guaranteed-tsg" => {
"url" => view_context.image_url("protected-food-drink-names/traditional-speciality-guaranteed-tsg.png"),
"alt_text" => "The scheme logo is a black stamp with the words Traditional Speciality UK Protected",
},
}
end

private

def nested_headers
Expand Down
9 changes: 9 additions & 0 deletions app/views/content_items/specialist_document.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
items: @content_item.important_metadata %>

<%= render "components/contents-list-with-body", contents: @content_item.contents do %>

<% if @content_item.protected_food_drink_name? %>
<img
class="app-c-figure__image protected-food-drink-name-logo"
src="<%= @content_item.images.dig(@content_item.protection_type, "url") %>"
alt="<%= @content_item.images.dig(@content_item.protection_type, "alt_text") %>"
>
<% end %>

<div class="responsive-bottom-margin">
<%= render 'govuk_publishing_components/components/govspeak', @content_item.govspeak_body %>
<% if @content_item.continuation_link %>
Expand Down
12 changes: 12 additions & 0 deletions test/presenters/specialist_document_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ class PresentedSpecialistDocument < SpecialistDocumentTestCase
assert_equal expected_body, presented_item("aaib-reports").body
end

test "presents the protection_type when specialist document's schema is 'protected-food-drink-names'" do
protection_type = "protected-designation-of-origin-pdo"

assert_equal protection_type, presented_item("protected-food-drink-names").protection_type
assert_equal protection_type, schema_item("protected-food-drink-names")["details"]["metadata"]["protection_type"]
end

test "does not present the protection_type when specialist document's schema is not 'protected-food-drink-names'" do
assert_nil schema_item("aaib-reports")["details"]["metadata"]["protection_type"]
assert_nil presented_item("aaib-reports").protection_type
end

test "has metadata" do
assert presented_item("aaib-reports").is_a?(ContentItem::Metadata)
end
Expand Down

0 comments on commit df976ff

Please sign in to comment.