Skip to content

Commit 3dd0db4

Browse files
author
Chris Yoong
committed
Updating testing
Update testing, remove app-level metadata test
1 parent a72e3a8 commit 3dd0db4

11 files changed

+68
-77
lines changed

test/controllers/content_items_controller_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ class ContentItemsControllerTest < ActionController::TestCase
381381
assert_select ".metadata-logo-wrapper", false
382382
assert_select ".app-c-figure", false
383383
assert_select ".gem-c-contextual-sidebar", false
384-
assert_select ".app-c-published-dates", false
384+
assert_select ".gem-c-metadata__definition", false
385385
assert_select ".gem-c-contextual-footer", false
386386
end
387387

test/integration/consultation_test.rb

+4-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ class ConsultationTest < ActionDispatch::IntegrationTest
77
assert_has_component_title(@content_item["title"])
88
assert page.has_text?(@content_item["description"])
99

10-
assert_has_publisher_metadata(
11-
published: "Published 4 November 2016",
12-
last_updated: "Last updated 7 November 2016",
13-
metadata: {
14-
"From": { "Department for Education": "/government/organisations/department-for-education" },
15-
},
10+
assert_has_metadata(
11+
published: "4 November 2016",
12+
last_updated: "7 November 2016",
13+
from: { "Department for Education": "/government/organisations/department-for-education" },
1614
)
1715

1816
assert_footer_has_published_dates("Published 4 November 2016", "Last updated 7 November 2016")

test/integration/detailed_guide_test.rb

+5-8
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@ class DetailedGuideTest < ActionDispatch::IntegrationTest
1111
assert_has_component_title(@content_item["title"])
1212
assert page.has_text?(@content_item["description"])
1313

14-
assert_has_publisher_metadata(
15-
published: "Published 12 June 2014",
16-
last_updated: "Last updated 18 February 2016",
17-
history_link: true,
18-
metadata: {
19-
"From:": {
20-
"HM Revenue & Customs": "/government/organisations/hm-revenue-customs",
21-
},
14+
assert_has_metadata(
15+
published: "12 June 2014",
16+
last_updated: "18 February 2016",
17+
from: {
18+
"HM Revenue & Customs": "/government/organisations/hm-revenue-customs",
2219
},
2320
)
2421
end

test/integration/document_collection_test.rb

+4-8
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@ class DocumentCollectionTest < ActionDispatch::IntegrationTest
1919

2020
test "renders metadata and document footer" do
2121
setup_and_visit_content_item("document_collection")
22-
assert_has_publisher_metadata(
23-
published: "Published 29 February 2016",
24-
metadata:
25-
{
26-
"From:":
27-
{
28-
"Driver and Vehicle Standards Agency": "/government/organisations/driver-and-vehicle-standards-agency",
29-
},
22+
assert_has_metadata(
23+
published: "29 February 2016",
24+
from: {
25+
"Driver and Vehicle Standards Agency": "/government/organisations/driver-and-vehicle-standards-agency",
3026
},
3127
)
3228
assert_footer_has_published_dates("Published 29 February 2016")

test/integration/fatality_notice_test.rb

+7-8
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ class FatalityNoticeTest < ActionDispatch::IntegrationTest
2020

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

23-
assert_has_publisher_metadata(
24-
published: "Published 27 February 1881",
25-
last_updated: "Last updated 14 September 2016",
26-
history_link: true,
27-
metadata: {
28-
"From": { "Ministry of Defence": "/government/organisations/ministry-of-defence" },
23+
assert_has_metadata(
24+
published: "27 February 1881",
25+
last_updated: "14 September 2016",
26+
from: {
27+
"Ministry of Defence": "/government/organisations/ministry-of-defence",
2928
},
3029
)
3130

@@ -60,8 +59,8 @@ class FatalityNoticeTest < ActionDispatch::IntegrationTest
6059

6160
test "fatality notice with minister" do
6261
setup_and_visit_content_item("fatality_notice_with_minister")
63-
assert_has_publisher_metadata_other(
64-
"From": {
62+
assert_has_metadata(
63+
from: {
6564
"Ministry of Defence": "/government/organisations/ministry-of-defence",
6665
"The Rt Hon Sir Eric Pickles MP": "/government/people/eric-pickles",
6766
},

test/integration/news_article_test.rb

+5-7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ class NewsArticleTest < ActionDispatch::IntegrationTest
1212
test "renders first published and from in metadata and document footer" do
1313
setup_and_visit_content_item("news_article")
1414

15-
assert_has_publisher_metadata(
16-
published: "Published 25 December 2016",
17-
metadata: {
18-
"From": {
19-
"Prime Minister's Office, 10 Downing Street":
20-
"/government/organisations/prime-ministers-office-10-downing-street",
21-
},
15+
assert_has_metadata(
16+
published: "25 December 2016",
17+
from: {
18+
"Prime Minister's Office, 10 Downing Street":
19+
"/government/organisations/prime-ministers-office-10-downing-street",
2220
},
2321
)
2422

test/integration/publication_test.rb

+5-7
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ class PublicationTest < ActionDispatch::IntegrationTest
1919
test "renders metadata and document footer" do
2020
setup_and_visit_content_item("publication")
2121

22-
assert_has_publisher_metadata(
23-
published: "Published 3 May 2016",
24-
metadata: {
25-
"From": {
26-
"Environment Agency": "/government/organisations/environment-agency",
27-
"The Rt Hon Sir Eric Pickles MP": "/government/people/eric-pickles",
28-
},
22+
assert_has_metadata(
23+
published: "3 May 2016",
24+
from: {
25+
"Environment Agency": "/government/organisations/environment-agency",
26+
"The Rt Hon Sir Eric Pickles MP": "/government/people/eric-pickles",
2927
},
3028
)
3129

test/integration/specialist_document_test.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ class SpecialistDocumentTest < ActionDispatch::IntegrationTest
4747
test "renders from in publisher metadata" do
4848
setup_and_visit_content_item("aaib-reports")
4949

50-
assert_has_publisher_metadata_other(
51-
"From": {
50+
assert_has_metadata(
51+
from: {
5252
"Air Accidents Investigation Branch":
53-
"/government/organisations/air-accidents-investigation-branch",
53+
"/government/organisations/air-accidents-investigation-branch",
5454
},
5555
)
5656
end

test/integration/speech_test.rb

+6-8
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ class SpeechTest < ActionDispatch::IntegrationTest
2020
test "renders metadata and document footer, including speaker" do
2121
setup_and_visit_content_item("speech")
2222

23-
assert_has_publisher_metadata(
24-
published: "Published 8 March 2016",
25-
metadata: {
26-
"From": {
27-
"Department of Energy & Climate Change and The Rt Hon Andrea Leadsom MP": nil,
28-
"Department of Energy": "/government/organisations/department-of-energy-climate-change",
29-
"The Rt Hon Andrea Leadsom MP": "/government/people/andrea-leadsom",
30-
},
23+
assert_has_metadata(
24+
published: "8 March 2016",
25+
from: {
26+
"Department of Energy & Climate Change and The Rt Hon Andrea Leadsom MP": nil,
27+
"Department of Energy": "/government/organisations/department-of-energy-climate-change",
28+
"The Rt Hon Andrea Leadsom MP": "/government/people/andrea-leadsom",
3129
},
3230
)
3331

test/integration/statistical_data_set_test.rb

+3-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ class StatisticalDataSetTest < ActionDispatch::IntegrationTest
1111

1212
test "renders metadata and document footer" do
1313
setup_and_visit_content_item("statistical_data_set")
14-
assert_has_publisher_metadata(
15-
published: "Published 13 December 2012",
16-
metadata: {
17-
"From:": { "Department for Transport": "/government/organisations/department-for-transport" },
18-
},
14+
assert_has_metadata(
15+
published: "13 December 2012",
16+
from: { "Department for Transport": "/government/organisations/department-for-transport" },
1917
)
2018
assert_footer_has_published_dates("Published 13 December 2012")
2119
end

test/test_helper.rb

+25-16
Original file line numberDiff line numberDiff line change
@@ -80,33 +80,42 @@ def assert_has_contents_list(contents)
8080
end
8181
end
8282

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

95-
def assert_has_publisher_metadata_other(metadata)
96-
within(".gem-c-metadata") do
97-
assert_has_metadata(
98-
metadata, ".gem-c-metadata__term", ".gem-c-metadata__definition"
99-
)
95+
def assert_has_publisher_metadata_other(any_args)
96+
assert_has_metadata(any_args)
97+
end
98+
99+
def assert_has_metadata(any_args)
100+
within ".gem-c-metadata" do
101+
any_args.each do |_key, value|
102+
value = { value => nil } if value.is_a?(String)
103+
value.each do |text, href|
104+
if href
105+
assert page.has_link?(text, href: href), "Metadata text '#{text} with link of #{href}' not found"
106+
else
107+
assert page.has_text?(text), "Metadata value '#{text}' not found"
108+
end
109+
end
110+
end
100111
end
101112
end
102113

103-
def assert_has_metadata(metadata, term_selector, definition_selector)
114+
def assert_has_metadata_local(metadata, term_selector, definition_selector)
104115
metadata.each do |key, value|
105116
assert page.has_css?(term_selector, text: key),
106117
"Metadata term '#{key}' not found"
107-
108118
value = { value => nil } if value.is_a?(String)
109-
110119
value.each do |text, href|
111120
within(definition_selector, text: text) do
112121
if href
@@ -120,22 +129,22 @@ def assert_has_metadata(metadata, term_selector, definition_selector)
120129
end
121130

122131
def assert_has_publisher_metadata(options)
123-
within(".gem-c-metadata") do
124-
assert_has_published_dates(options[:published], options[:last_updated], options[:history_link])
132+
within(".app-c-publisher-metadata") do
133+
assert_has_published_dates(options[:first_published], options[:last_updated], options[:history_link])
125134
assert_has_publisher_metadata_other(options[:metadata])
126135
end
127136
end
128137

129138
def assert_has_important_metadata(metadata)
130139
within(".app-c-important-metadata") do
131-
assert_has_metadata(
140+
assert_has_metadata_local(
132141
metadata, ".app-c-important-metadata__term", ".app-c-important-metadata__definition"
133142
)
134143
end
135144
end
136145

137-
def assert_footer_has_published_dates(published = nil, last_updated = nil, history_link = false)
138-
assert_has_published_dates(published, last_updated, history_link, 1)
146+
def assert_footer_has_published_dates(first_published = nil, last_updated = nil, history_link = false)
147+
assert_has_published_dates(first_published, last_updated, history_link)
139148
end
140149

141150
def setup_and_visit_content_item(name, parameter_string = "")

0 commit comments

Comments
 (0)