Skip to content

Commit a0812da

Browse files
committed
Update specs
Publishing components release 21.53.0 contains a refactor of the way HTML publication breadcrumbs are composed. The BreadcrumbSelector now uses the parent of the HTML publication, so an extra stub is needed for the HtmlPublicationTest tests.
1 parent 8d3bc4e commit a0812da

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

test/integration/html_publication_test.rb

+11-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class HtmlPublicationTest < ActionDispatch::IntegrationTest
66
end
77

88
test "html publications" do
9-
setup_and_visit_content_item("published")
9+
setup_and_visit_html_publication("published")
1010

1111
within ".gem-c-inverse-header" do
1212
assert page.has_text?(@content_item["details"]["format_sub_type"])
@@ -24,7 +24,7 @@ class HtmlPublicationTest < ActionDispatch::IntegrationTest
2424
end
2525

2626
test "html publications with meta data" do
27-
setup_and_visit_content_item("print_with_meta_data")
27+
setup_and_visit_html_publication("print_with_meta_data")
2828

2929
within ".govuk-grid-row.sidebar-with-body" do
3030
assert page.find(".print-meta-data", visible: false)
@@ -35,7 +35,7 @@ class HtmlPublicationTest < ActionDispatch::IntegrationTest
3535
end
3636

3737
test "html publications with meta data - print version" do
38-
setup_and_visit_content_item("print_with_meta_data", "?medium=print")
38+
setup_and_visit_html_publication("print_with_meta_data", "?medium=print")
3939

4040
within ".govuk-grid-row.sidebar-with-body" do
4141
assert page.find(".print-meta-data", visible: true)
@@ -46,25 +46,25 @@ class HtmlPublicationTest < ActionDispatch::IntegrationTest
4646
end
4747

4848
test "renders back to contents elements" do
49-
setup_and_visit_content_item("published")
49+
setup_and_visit_html_publication("published")
5050
assert page.has_css?(".app-c-back-to-top[href='#contents']")
5151
end
5252

5353
test "prime minister office organisation html publication" do
54-
setup_and_visit_content_item("prime_ministers_office")
54+
setup_and_visit_html_publication("prime_ministers_office")
5555
assert_has_component_organisation_logo_with_brand("executive-office", 4)
5656
end
5757

5858
test "no contents are shown when headings are an empty list" do
59-
setup_and_visit_content_item("prime_ministers_office")
59+
setup_and_visit_html_publication("prime_ministers_office")
6060

6161
within ".gem-c-inverse-header" do
6262
assert_not page.has_text?("Contents")
6363
end
6464
end
6565

6666
test "html publication with rtl text direction" do
67-
setup_and_visit_content_item("arabic_translation")
67+
setup_and_visit_html_publication("arabic_translation")
6868
assert page.has_css?("#wrapper.direction-rtl"), "has .direction-rtl class on #wrapper element"
6969
end
7070

@@ -81,6 +81,7 @@ def assert_has_component_organisation_logo_with_brand(brand, index = 1)
8181
'withdrawn_at': "2014-08-09T11:39:05Z",
8282
}
8383

84+
stub_content_store_has_item(content_item["links"]["parent"][0]["base_path"])
8485
stub_content_store_has_item("/government/publications/canada-united-kingdom-joint-declaration/canada-united-kingdom-joint-declaration", content_item.to_json)
8586
visit_with_cachebust "/government/publications/canada-united-kingdom-joint-declaration/canada-united-kingdom-joint-declaration"
8687

@@ -90,12 +91,13 @@ def assert_has_component_organisation_logo_with_brand(brand, index = 1)
9091

9192
test "if document has no parent document_type 'publication' is shown" do
9293
content_item = GovukSchemas::Example.find("html_publication", example_name: "prime_ministers_office")
93-
content_item["links"]["parent"][0]["document_type"] = nil
94+
parent = content_item["links"]["parent"][0]
95+
parent["document_type"] = nil
9496
content_item["withdrawn_notice"] = {
9597
'explanation': "This is out of date",
9698
'withdrawn_at': "2014-08-09T11:39:05Z",
9799
}
98-
100+
stub_content_store_has_item(parent["base_path"])
99101
stub_content_store_has_item("/government/publications/canada-united-kingdom-joint-declaration/canada-united-kingdom-joint-declaration", content_item.to_json)
100102
visit_with_cachebust "/government/publications/canada-united-kingdom-joint-declaration/canada-united-kingdom-joint-declaration"
101103

test/test_helper.rb

+19
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ def setup_and_visit_content_item(name, parameter_string = "")
139139
end
140140
end
141141

142+
def setup_and_visit_html_publication(name, parameter_string = "")
143+
@content_item = get_content_example(name).tap do |item|
144+
parent = item["links"]["parent"][0]
145+
stub_content_store_has_item(item["base_path"], item.to_json)
146+
stub_content_store_has_item(parent["base_path"], parent.to_json)
147+
visit_with_cachebust("#{item['base_path']}#{parameter_string}")
148+
end
149+
end
150+
142151
def setup_and_visit_content_item_with_taxons(name, taxons)
143152
@content_item = get_content_example(name).tap do |item|
144153
item["links"]["taxons"] = taxons
@@ -156,8 +165,18 @@ def setup_and_visit_random_content_item(document_type: nil)
156165
content_id = content_item["content_id"]
157166
path = content_item["base_path"]
158167

168+
if schema_type == "html_publication"
169+
parent = content_item.dig("links", "parent")&.first
170+
if parent
171+
parent_path = parent["base_path"]
172+
stub_request(:get, %r{#{parent_path}})
173+
.to_return(status: 200, body: content_item.to_json, headers: {})
174+
end
175+
end
176+
159177
stub_request(:get, %r{#{path}})
160178
.to_return(status: 200, body: content_item.to_json, headers: {})
179+
161180
visit path
162181

163182
assert_selector %(meta[name="govuk:content-id"][content="#{content_id}"]), visible: false

0 commit comments

Comments
 (0)