Skip to content

Commit

Permalink
Merge pull request #2026 from alphagov/switch-to-meta-block
Browse files Browse the repository at this point in the history
Switch to meta block
  • Loading branch information
owenatgov authored Mar 1, 2021
2 parents 691dda8 + 3dd0db4 commit 32d0b31
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

.metadata-column {
padding-left: 0;
padding-top: govuk-spacing(3);
}

.metadata-logo {
Expand Down
8 changes: 3 additions & 5 deletions app/presenters/content_item/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ def important_metadata

def publisher_metadata
{
published: published,
from: from,
first_published: published,
last_updated: updated,
link_to_history: updated.present?,
other: {
from: from,
},
see_updates_link: true,
}
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_publisher_metadata_with_logo.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="govuk-grid-row">
<div class="metadata-logo-wrapper<%= ' responsive-bottom-margin' if @content_item.try(:logo) %>">
<div class="govuk-grid-column-two-thirds metadata-column">
<%= render "components/publisher-metadata", @content_item.publisher_metadata %>
<%= render 'govuk_publishing_components/components/metadata', @content_item.publisher_metadata %>
</div>
<div class="govuk-grid-column-one-third">
<% if @content_item.try(:logo) %>
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/content_items_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ class ContentItemsControllerTest < ActionController::TestCase
assert_select ".metadata-logo-wrapper", false
assert_select ".app-c-figure", false
assert_select ".gem-c-contextual-sidebar", false
assert_select ".app-c-published-dates", false
assert_select ".gem-c-metadata__definition", false
assert_select ".gem-c-contextual-footer", false
end

Expand Down
10 changes: 4 additions & 6 deletions test/integration/consultation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ class ConsultationTest < ActionDispatch::IntegrationTest
assert_has_component_title(@content_item["title"])
assert page.has_text?(@content_item["description"])

assert_has_publisher_metadata(
published: "Published 4 November 2016",
last_updated: "Last updated 7 November 2016",
metadata: {
"From": { "Department for Education": "/government/organisations/department-for-education" },
},
assert_has_metadata(
published: "4 November 2016",
last_updated: "7 November 2016",
from: { "Department for Education": "/government/organisations/department-for-education" },
)

assert_footer_has_published_dates("Published 4 November 2016", "Last updated 7 November 2016")
Expand Down
13 changes: 5 additions & 8 deletions test/integration/detailed_guide_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ class DetailedGuideTest < ActionDispatch::IntegrationTest
assert_has_component_title(@content_item["title"])
assert page.has_text?(@content_item["description"])

assert_has_publisher_metadata(
published: "Published 12 June 2014",
last_updated: "Last updated 18 February 2016",
history_link: true,
metadata: {
"From:": {
"HM Revenue & Customs": "/government/organisations/hm-revenue-customs",
},
assert_has_metadata(
published: "12 June 2014",
last_updated: "18 February 2016",
from: {
"HM Revenue & Customs": "/government/organisations/hm-revenue-customs",
},
)
end
Expand Down
12 changes: 4 additions & 8 deletions test/integration/document_collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@ class DocumentCollectionTest < ActionDispatch::IntegrationTest

test "renders metadata and document footer" do
setup_and_visit_content_item("document_collection")
assert_has_publisher_metadata(
published: "Published 29 February 2016",
metadata:
{
"From:":
{
"Driver and Vehicle Standards Agency": "/government/organisations/driver-and-vehicle-standards-agency",
},
assert_has_metadata(
published: "29 February 2016",
from: {
"Driver and Vehicle Standards Agency": "/government/organisations/driver-and-vehicle-standards-agency",
},
)
assert_footer_has_published_dates("Published 29 February 2016")
Expand Down
15 changes: 7 additions & 8 deletions test/integration/fatality_notice_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ class FatalityNoticeTest < ActionDispatch::IntegrationTest

assert_not page.has_css?(".gem-c-notice")

assert_has_publisher_metadata(
published: "Published 27 February 1881",
last_updated: "Last updated 14 September 2016",
history_link: true,
metadata: {
"From": { "Ministry of Defence": "/government/organisations/ministry-of-defence" },
assert_has_metadata(
published: "27 February 1881",
last_updated: "14 September 2016",
from: {
"Ministry of Defence": "/government/organisations/ministry-of-defence",
},
)

Expand Down Expand Up @@ -60,8 +59,8 @@ class FatalityNoticeTest < ActionDispatch::IntegrationTest

test "fatality notice with minister" do
setup_and_visit_content_item("fatality_notice_with_minister")
assert_has_publisher_metadata_other(
"From": {
assert_has_metadata(
from: {
"Ministry of Defence": "/government/organisations/ministry-of-defence",
"The Rt Hon Sir Eric Pickles MP": "/government/people/eric-pickles",
},
Expand Down
12 changes: 5 additions & 7 deletions test/integration/news_article_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ class NewsArticleTest < ActionDispatch::IntegrationTest
test "renders first published and from in metadata and document footer" do
setup_and_visit_content_item("news_article")

assert_has_publisher_metadata(
published: "Published 25 December 2016",
metadata: {
"From": {
"Prime Minister's Office, 10 Downing Street":
"/government/organisations/prime-ministers-office-10-downing-street",
},
assert_has_metadata(
published: "25 December 2016",
from: {
"Prime Minister's Office, 10 Downing Street":
"/government/organisations/prime-ministers-office-10-downing-street",
},
)

Expand Down
12 changes: 5 additions & 7 deletions test/integration/publication_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ class PublicationTest < ActionDispatch::IntegrationTest
test "renders metadata and document footer" do
setup_and_visit_content_item("publication")

assert_has_publisher_metadata(
published: "Published 3 May 2016",
metadata: {
"From": {
"Environment Agency": "/government/organisations/environment-agency",
"The Rt Hon Sir Eric Pickles MP": "/government/people/eric-pickles",
},
assert_has_metadata(
published: "3 May 2016",
from: {
"Environment Agency": "/government/organisations/environment-agency",
"The Rt Hon Sir Eric Pickles MP": "/government/people/eric-pickles",
},
)

Expand Down
6 changes: 3 additions & 3 deletions test/integration/specialist_document_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ class SpecialistDocumentTest < ActionDispatch::IntegrationTest
test "renders from in publisher metadata" do
setup_and_visit_content_item("aaib-reports")

assert_has_publisher_metadata_other(
"From": {
assert_has_metadata(
from: {
"Air Accidents Investigation Branch":
"/government/organisations/air-accidents-investigation-branch",
"/government/organisations/air-accidents-investigation-branch",
},
)
end
Expand Down
14 changes: 6 additions & 8 deletions test/integration/speech_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ class SpeechTest < ActionDispatch::IntegrationTest
test "renders metadata and document footer, including speaker" do
setup_and_visit_content_item("speech")

assert_has_publisher_metadata(
published: "Published 8 March 2016",
metadata: {
"From": {
"Department of Energy & Climate Change and The Rt Hon Andrea Leadsom MP": nil,
"Department of Energy": "/government/organisations/department-of-energy-climate-change",
"The Rt Hon Andrea Leadsom MP": "/government/people/andrea-leadsom",
},
assert_has_metadata(
published: "8 March 2016",
from: {
"Department of Energy & Climate Change and The Rt Hon Andrea Leadsom MP": nil,
"Department of Energy": "/government/organisations/department-of-energy-climate-change",
"The Rt Hon Andrea Leadsom MP": "/government/people/andrea-leadsom",
},
)

Expand Down
8 changes: 3 additions & 5 deletions test/integration/statistical_data_set_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ class StatisticalDataSetTest < ActionDispatch::IntegrationTest

test "renders metadata and document footer" do
setup_and_visit_content_item("statistical_data_set")
assert_has_publisher_metadata(
published: "Published 13 December 2012",
metadata: {
"From:": { "Department for Transport": "/government/organisations/department-for-transport" },
},
assert_has_metadata(
published: "13 December 2012",
from: { "Department for Transport": "/government/organisations/department-for-transport" },
)
assert_footer_has_published_dates("Published 13 December 2012")
end
Expand Down
39 changes: 24 additions & 15 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,33 +80,42 @@ def assert_has_contents_list(contents)
end
end

def assert_has_published_dates(published = nil, last_updated = nil, history_link = false, element_index = 0)
def assert_has_published_dates(first_published = nil, last_updated = nil, history_link = false)
text = []
text << published if published
text << first_published if first_published
text << last_updated if last_updated
within(all(".app-c-published-dates")[element_index]) do
within ".app-c-published-dates:last-of-type" do
assert page.has_text?(text.join("\n")), "Published dates #{text.join("\n")} not found"
if history_link
assert page.has_link?("see all updates", href: "#history"), "Updates link not found"
end
end
end

def assert_has_publisher_metadata_other(metadata)
within(".app-c-publisher-metadata__other") do
assert_has_metadata(
metadata, ".app-c-publisher-metadata__term", ".app-c-publisher-metadata__definition"
)
def assert_has_publisher_metadata_other(any_args)
assert_has_metadata(any_args)
end

def assert_has_metadata(any_args)
within ".gem-c-metadata" do
any_args.each do |_key, value|
value = { value => nil } if value.is_a?(String)
value.each do |text, href|
if href
assert page.has_link?(text, href: href), "Metadata text '#{text} with link of #{href}' not found"
else
assert page.has_text?(text), "Metadata value '#{text}' not found"
end
end
end
end
end

def assert_has_metadata(metadata, term_selector, definition_selector)
def assert_has_metadata_local(metadata, term_selector, definition_selector)
metadata.each do |key, value|
assert page.has_css?(term_selector, text: key),
"Metadata term '#{key}' not found"

value = { value => nil } if value.is_a?(String)

value.each do |text, href|
within(definition_selector, text: text) do
if href
Expand All @@ -121,21 +130,21 @@ def assert_has_metadata(metadata, term_selector, definition_selector)

def assert_has_publisher_metadata(options)
within(".app-c-publisher-metadata") do
assert_has_published_dates(options[:published], options[:last_updated], options[:history_link])
assert_has_published_dates(options[:first_published], options[:last_updated], options[:history_link])
assert_has_publisher_metadata_other(options[:metadata])
end
end

def assert_has_important_metadata(metadata)
within(".app-c-important-metadata") do
assert_has_metadata(
assert_has_metadata_local(
metadata, ".app-c-important-metadata__term", ".app-c-important-metadata__definition"
)
end
end

def assert_footer_has_published_dates(published = nil, last_updated = nil, history_link = false)
assert_has_published_dates(published, last_updated, history_link, 1)
def assert_footer_has_published_dates(first_published = nil, last_updated = nil, history_link = false)
assert_has_published_dates(first_published, last_updated, history_link)
end

def setup_and_visit_content_item(name, parameter_string = "")
Expand Down

0 comments on commit 32d0b31

Please sign in to comment.