Skip to content

Commit

Permalink
Test using govspeak from gem
Browse files Browse the repository at this point in the history
- update assert_has_component_govspeak to be simpler, since the component is no longer coming from static in a strange format
- remove within_component_govspeak method from test helper as no longer needed
- update all tests that relied on these methods
- amend some tests that were too specific and failing
  • Loading branch information
andysellick committed Jun 5, 2018
1 parent 37d0e62 commit 2e3adf6
Show file tree
Hide file tree
Showing 23 changed files with 85 additions and 156 deletions.
3 changes: 1 addition & 2 deletions test/integration/answer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ class AnswerTest < ActionDispatch::IntegrationTest
test "renders title and body" do
setup_and_visit_content_item('answer')
assert page.has_text?(@content_item["title"])
assert_has_component_govspeak(@content_item["details"]["body"])
# assert page.has_text?("Diweddarwyd diwethaf: 28 Mai 2015")
assert_has_component_govspeak("Bydd angen cod cychwyn arnoch i ddechrau defnyddio’r holl wasanaethau hyn, ac eithrio TAW. Anfonir hwn atoch cyn pen saith diwrnod gwaith ar ôl i chi gofrestru. Os ydych chi’n byw dramor, gall gymryd hyd at 21 diwrnod i gyrraedd.")
end

test "related links are rendered" do
Expand Down
2 changes: 1 addition & 1 deletion test/integration/case_study_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CaseStudyTest < ActionDispatch::IntegrationTest

within ".gem-c-notice" do
assert page.has_text?('This case study was withdrawn'), "is withdrawn"
assert_has_component_govspeak(@content_item["withdrawn_notice"]["explanation"])
assert_has_component_govspeak("We’ve withdrawn this case study and published newer")
assert page.has_css?("time[datetime='#{@content_item['withdrawn_notice']['withdrawn_at']}']")
end
end
Expand Down
30 changes: 11 additions & 19 deletions test/integration/consultation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class ConsultationTest < ActionDispatch::IntegrationTest
assert_footer_has_published_dates("Published 4 November 2016", "Last updated 7 November 2016")

within '.consultation-description' do
assert_has_component_govspeak(@content_item["details"]["body"])
assert page.has_text?("We are seeking external views on a postgraduate doctoral loan.")
end
end

test "consultation documents render" do
setup_and_visit_content_item('closed_consultation')

within '.consultation-documents' do
assert_has_component_govspeak(@content_item["details"]["documents"].join(''))
assert page.has_text?("Museums Review Terms of Reference")
end
end

Expand Down Expand Up @@ -83,15 +83,15 @@ class ConsultationTest < ActionDispatch::IntegrationTest

assert page.has_text?("Detail of feedback received")
within '.consultation-feedback' do
assert_has_component_govspeak(@content_item["details"]["public_feedback_detail"])
assert page.has_text?("The majority of respondents agreed or strongly agreed with our proposals, which were:")
end
end

test "consultation outcome documents render" do
setup_and_visit_content_item('consultation_outcome')

within '.consultation-outcome' do
assert_has_component_govspeak(@content_item["details"]["final_outcome_documents"].join(''))
assert page.has_text?("Employee Share Schemes: NIC elections - consulation response")
end
end

Expand All @@ -100,7 +100,7 @@ class ConsultationTest < ActionDispatch::IntegrationTest

assert page.has_text?("Feedback received")
within '.consultation-feedback-documents' do
assert_has_component_govspeak(@content_item["details"]["public_feedback_documents"].join(''))
assert page.has_text?("Analysis of responses to our consultation on setting the grade standards of new GCSEs in England – part 2")
end
end

Expand All @@ -114,27 +114,19 @@ class ConsultationTest < ActionDispatch::IntegrationTest
setup_and_visit_content_item('open_consultation_with_participation')

within '.consultation-ways-to-respond' do
within_component_govspeak do |component_args|
content = component_args.fetch("content")
html = Nokogiri::HTML.parse(content)
assert html.at_css(".call-to-action a[href='https://beisgovuk.citizenspace.com/ukgi/post-office-network-consultation']", text: 'Respond online')
assert html.at_css("a[href='mailto:[email protected]']", text: '[email protected]')
assert html.at_css(".contact", text: '2016 Post Office Network Consultation')
assert html.at_css("a[href='https://www.gov.uk/government/uploads/system/uploads/consultation_response_form_data/file/533/beis-16-36rf-post-office-network-consultation-response-form.docx']", text: 'response form')
end
assert page.has_css?(".call-to-action a[href='https://beisgovuk.citizenspace.com/ukgi/post-office-network-consultation']", text: 'Respond online')
assert page.has_css?("a[href='mailto:[email protected]']", text: '[email protected]')
assert page.has_css?(".contact", text: '2016 Post Office Network Consultation')
assert page.has_css?("a[href='https://www.gov.uk/government/uploads/system/uploads/consultation_response_form_data/file/533/beis-16-36rf-post-office-network-consultation-response-form.docx']", text: 'response form')
end
end

test "ways to respond postal address is formatted with line breaks" do
setup_and_visit_content_item('open_consultation_with_participation')

within '.consultation-ways-to-respond' do
within_component_govspeak do |component_args|
content = component_args.fetch("content")
html = Nokogiri::HTML.parse(content)
assert html.at_css(".contact .content p", text: '2016 Post Office Network Consultation')
assert html.at_css(".contact .content p br")
end
assert page.has_css?(".contact .content p", text: '2016 Post Office Network Consultation')
assert page.has_css?(".contact .content p br")
end
end

Expand Down
54 changes: 18 additions & 36 deletions test/integration/contact_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,63 +7,45 @@ class ContactTest < ActionDispatch::IntegrationTest

test "online forms are rendered" do
setup_and_visit_content_item('contact')
within_component_govspeak do |component_args|
content = component_args.fetch("content")

assert content.include? @content_item["details"]["more_info_contact_form"]
first_contact_form_link = @content_item["details"]["contact_form_links"].first
assert_has_component_govspeak("If HMRC needs to contact you about anything confidential they’ll reply by phone or post.")
assert_has_component_govspeak("Contact HMRC to report suspicious activity in relation to smuggling, customs, excise and VAT fraud.")

assert content.include? first_contact_form_link['description']

html = Nokogiri::HTML.parse(content)
assert_not_nil html.at_css("h2#online-forms-title")
assert_not_nil html.at_css("a[href='#{first_contact_form_link['link']}']")
end
assert page.has_css?("h2#online-forms-title")
first_contact_form_link = @content_item["details"]["contact_form_links"].first
assert page.has_css?("a[href='#{first_contact_form_link['link']}']")
end

test "emails are rendered" do
setup_and_visit_content_item('contact')
within_component_govspeak do |component_args|
content = component_args.fetch("content")

html = Nokogiri::HTML.parse(content)
assert_not_nil html.at_css("h2#email-title")
assert_not_nil html.at_css(".email:first-of-type")
end
assert page.has_css?("h2#email-title")
assert page.has_css?(".email:first-of-type")
end

test "phones are rendered" do
setup_and_visit_content_item('contact')
within_component_govspeak do |component_args|
first_phone = @content_item["details"]["phone_numbers"].first
html = Nokogiri::HTML.parse(component_args.fetch("content"))

assert_not_nil html.at_css("h2#phone-title")
assert_not_nil html.at("h3:contains(\"#{first_phone['title']}\")")
assert_not_nil html.at("p:contains(\"#{first_phone['number']}\")")
assert_not_nil html.at("p:contains(\"24 hours a day, 7 days a week\")")
end
first_phone = @content_item["details"]["phone_numbers"].first

assert page.has_css?("h2#phone-title")
assert page.has_css?("h3", text: first_phone['title'])
assert page.has_css?("p", text: first_phone['number'])
assert page.has_css?("p", text: "24 hours a day, 7 days a week")
end

test "phone number heading is not rendered when only one number" do
setup_and_visit_content_item('contact_with_welsh')
within_component_govspeak do |component_args|
first_phone = @content_item["details"]["phone_numbers"].first
html = Nokogiri::HTML.parse(component_args.fetch("content"))

assert_equal 1, @content_item["details"]["phone_numbers"].size
refute html.at("h3:contains(\"#{first_phone['title']}\")")
end
assert_equal 1, @content_item["details"]["phone_numbers"].size
first_phone = @content_item["details"]["phone_numbers"].first
refute page.has_css?("h3", text: first_phone['title'])
end

test "posts are rendered" do
setup_and_visit_content_item('contact')
within_component_govspeak do |component_args|
content = component_args.fetch("content")
html = Nokogiri::HTML.parse(content)

assert_not_nil html.at_css("h2#post-title")
assert_not_nil html.at_css(".street-address")
end
assert page.has_css?("h2#post-title")
assert page.has_css?(".street-address")
end
end
25 changes: 8 additions & 17 deletions test/integration/corporate_information_page_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class CorporateInformationPageTest < ActionDispatch::IntegrationTest

assert_has_component_title(@content_item["title"])
assert page.has_text?(@content_item["description"])
assert_has_component_govspeak(@content_item["details"]["body"])
assert page.has_text?("Ni all y Gofrestrfa Tir drafod achosion unigol ar ein sianeli cyfryngau cymdeithasol. Ni fyddwn yn gofyn i chi ddatgelu gwybodaeth bersonol na thalu trwy Twitter, Facebook, LinkedIn nac ebost. Os cewch neges o’r fath, peidiwch ag ymateb – nid yw gan y Gofrestrfa Tir a gall fod yn faleisus.")
end

test "renders with contents list" do
Expand All @@ -33,28 +33,19 @@ class CorporateInformationPageTest < ActionDispatch::IntegrationTest
test "renders corporate information with body when present" do
setup_and_visit_content_item('corporate_information_page')

within_component_govspeak do |component_args|
content = component_args.fetch("content")
assert content.gsub(/\s+/, ' ').include? @content_item["details"]["body"].gsub(/\s+/, ' ')
assert page.has_css?("h2#corporate-information")
assert page.has_css?("h3#access-our-information")
assert page.has_css?("h3#jobs-and-contracts")

html = Nokogiri::HTML.parse(content)
assert_not_nil html.at_css("h2#corporate-information")
assert_not_nil html.at_css("h3#access-our-information")
assert_not_nil html.at_css("h3#jobs-and-contracts")

assert_not_nil html.at_css("ul li a[href='/government/organisations/department-of-health/about/complaints-procedure']")
assert_not_nil html.at_css("ul li a[href*='/government/publications']")
assert_not_nil html.at_css("ul li a[href='https://www.civilservicejobs.service.gov.uk/csr']")
end
assert page.has_css?("ul li a[href='/government/organisations/department-of-health/about/complaints-procedure']")
assert page.has_css?("ul li a[href*='/government/publications']")
assert page.has_css?("ul li a[href='https://www.civilservicejobs.service.gov.uk/csr']")
end

test "renders further information with body when present" do
setup_and_visit_content_item('corporate_information_page')

within_component_govspeak do |component_args|
content = component_args.fetch("content")
assert content.gsub(/\s+/, ' ').include? "Read about the types of information we routinely"
end
assert page.has_text?("Read about the types of information we routinely")
end

test "renders with organisation branding" do
Expand Down
8 changes: 3 additions & 5 deletions test/integration/detailed_guide_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ class DetailedGuideTest < ActionDispatch::IntegrationTest

assert page.has_css?('title', text: "[Withdrawn]", visible: false)

within ".gem-c-notice" do
assert page.has_text?('This guidance was withdrawn'), "is withdrawn"
assert_has_component_govspeak(@content_item["withdrawn_notice"]["explanation"])
assert page.has_css?("time[datetime='#{@content_item['withdrawn_notice']['withdrawn_at']}']")
end
assert page.has_text?('This guidance was withdrawn'), "is withdrawn"
assert_has_component_govspeak("This information has been archived as it is now out of date. For current information please go to")
assert page.has_css?("time[datetime='#{@content_item['withdrawn_notice']['withdrawn_at']}']")
end

test "historically political detailed guide" do
Expand Down
6 changes: 3 additions & 3 deletions test/integration/document_collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DocumentCollectionTest < ActionDispatch::IntegrationTest

test "renders body when provided" do
setup_and_visit_content_item('document_collection_with_body')
assert_has_component_govspeak(@content_item["details"]["body"])
assert_has_component_govspeak("Each regime page provides a current list of asset freeze targets designated by the United Nations (UN), European Union and United Kingdom, under legislation relating to current financial sanctions regimes.")
end

test "renders contents with link to each collection group" do
Expand Down Expand Up @@ -69,7 +69,7 @@ class DocumentCollectionTest < ActionDispatch::IntegrationTest
end

within ".app-c-contents-list-with-body" do
assert page.has_css?(shared_component_selector("govspeak"), count: group_count)
assert page.has_css?(".gem-c-govspeak", count: group_count)
assert page.has_css?('.gem-c-document-list', count: group_count)
end
end
Expand Down Expand Up @@ -144,7 +144,7 @@ class DocumentCollectionTest < ActionDispatch::IntegrationTest

within ".gem-c-notice" do
assert page.has_text?('This collection was withdrawn'), "is withdrawn"
assert_has_component_govspeak(@content_item["withdrawn_notice"]["explanation"])
assert_has_component_govspeak("This information is now out of date.")
assert page.has_css?("time[datetime='#{@content_item['withdrawn_notice']['withdrawn_at']}']")
end
end
Expand Down
6 changes: 3 additions & 3 deletions test/integration/fatality_notice_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class FatalityNoticeTest < ActionDispatch::IntegrationTest
'should have image with ministry-of-defence source with alt text'
)

assert_has_component_govspeak("Colley served nearly all of his military and administrative career in British South Africa, but he played a significant part in the Second Anglo-Afghan War as military secretary and then private secretary to the governor-general of India, Lord Lytton. The war began in November 1878 and ended in May 1879 with the Treaty of Gandamak.")

within(".content-bottom-margin .app-c-published-dates") do
assert page.has_content?("Published 27 February 1881")
assert page.has_content?("Last updated 14 September 2016")
Expand Down Expand Up @@ -77,9 +79,7 @@ class FatalityNoticeTest < ActionDispatch::IntegrationTest
within ".gem-c-notice" do
assert_text("This fatality notice was withdrawn on 14 September 2016")

assert_has_component_govspeak(
"<div class=\"govspeak\"><p>This content is not factually correct. For current information please go to <a rel=\"external\" href=\"https://en.wikipedia.org/wiki/George_Pomeroy_Colley\">https://en.wikipedia.org/wiki/George_Pomeroy_Colley</a></p></div>"
)
assert_has_component_govspeak("This content is not factually correct. For current information please go to")
end
end
end
2 changes: 1 addition & 1 deletion test/integration/help_page_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class HelpPageTest < ActionDispatch::IntegrationTest
setup_and_visit_content_item('help_page')

assert page.has_text?(@content_item["title"])
assert_has_component_govspeak(@content_item["details"]["body"].squish)
assert_has_component_govspeak("GOV.UK puts small files (known as ‘cookies’) onto your computer to collect information about how you browse the site.")
assert_has_published_dates(@content_item["last_updated"])
end
end
4 changes: 1 addition & 3 deletions test/integration/html_publication_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ class HtmlPublicationTest < ActionDispatch::IntegrationTest
end

def assert_has_component_govspeak_html_publication(content)
within shared_component_selector("govspeak_html_publication") do
assert_equal content, JSON.parse(page.text).fetch("content")
end
assert_has_component_govspeak("The Environment Agency will normally put any responses it receives on the public register. This includes your name and contact details. Tell us if you don’t want your response to be public.")
end

def assert_has_component_organisation_logo_with_brand(brand, index = 1)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/news_article_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class NewsArticleTest < ActionDispatch::IntegrationTest
assert_has_component_government_navigation_active("announcements")
assert_has_component_title(@content_item["title"])
assert page.has_text?(@content_item["description"])
assert_has_component_govspeak(@content_item["details"]["body"])
assert page.has_text?("This year, the United Kingdom has had much to celebrate. Her Majesty The Queen celebrated her 90th birthday")
end

test "renders first published and from in metadata and document footer" do
Expand Down
6 changes: 3 additions & 3 deletions test/integration/publication_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PublicationTest < ActionDispatch::IntegrationTest
assert page.has_text?(@content_item["description"])

within '[aria-labelledby="details-title"]' do
assert_has_component_govspeak(@content_item["details"]["body"])
assert_has_component_govspeak("Installation name: Leeming Biogas Facility")
end
end

Expand All @@ -35,7 +35,7 @@ class PublicationTest < ActionDispatch::IntegrationTest
test "renders a govspeak block for attachments" do
setup_and_visit_content_item('publication')
within '[aria-labelledby="documents-title"]' do
assert_has_component_govspeak(@content_item["details"]["documents"].join(''))
assert_has_component_govspeak("Permit: Veolia ES (UK) Limited")
end
end

Expand All @@ -45,7 +45,7 @@ class PublicationTest < ActionDispatch::IntegrationTest

within ".gem-c-notice" do
assert page.has_text?('This publication was withdrawn'), "is withdrawn"
assert_has_component_govspeak(@content_item["withdrawn_notice"]["explanation"])
assert_has_component_govspeak("guidance for keepers of sheep, goats and pigs")
assert page.has_css?("time[datetime='#{@content_item['withdrawn_notice']['withdrawn_at']}']")
end
end
Expand Down
Loading

0 comments on commit 2e3adf6

Please sign in to comment.