Skip to content

Commit

Permalink
Merge pull request #4484 from alphagov/fix-broken-assertions
Browse files Browse the repository at this point in the history
Fix broken spec assertions
  • Loading branch information
kevindew authored Dec 10, 2024
2 parents 52b5260 + 1cdab18 commit 4496b31
Show file tree
Hide file tree
Showing 21 changed files with 56 additions and 46 deletions.
2 changes: 1 addition & 1 deletion spec/component_guide/component_audit_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

describe "Component audit page" do
describe "Component audit page", :capybara do
it "renders the audit page" do
visit "/component-guide/audit"
expect(page).to have_title "Component audit - Component Guide"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

describe "Component examples with accessibility criteria" do
describe "Component examples with accessibility criteria", :capybara do
it "shows the accessibility acceptance criteria as HTML" do
visit "/component-guide/test_component"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

describe "Component example with automated testing", js: true do
describe "Component example with automated testing", :capybara, js: true do
it "has accessibility testing hooks" do
visit "/component-guide/test_component"
expect(page).to have_selector('[data-module="test-a11y"]')
Expand Down
2 changes: 1 addition & 1 deletion spec/component_guide/component_example_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

describe "Component example" do
describe "Component example", :capybara do
it "illustrates how to use the component" do
visit "/component-guide/test_component"

Expand Down
2 changes: 1 addition & 1 deletion spec/component_guide/component_index_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

describe "Component guide index" do
describe "Component guide index", :capybara do
# Load ordering test can only fail if run as the first test in suite
# https://github.com/rails/rails/issues/12168
it "renders using gem layout not app layout after viewing a page on the application" do
Expand Down
2 changes: 1 addition & 1 deletion spec/component_guide/component_preview_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

describe "Component preview" do
describe "Component preview", :capybara do
it "shows all component examples on a page without header or footer" do
visit "/component-guide/test_component_with_params/preview"
expect(page).to have_selector(".hide-header-and-footer")
Expand Down
26 changes: 13 additions & 13 deletions spec/components/contextual_breadcrumbs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def set_live_taxons(content_item)

it "renders parent-based breadcrumbs if the content_item is tagged to mainstream browse and there is a parent" do
render_component(content_item: example_document_for("place", "find-regional-passport-office"))
assert_no_selector(".gem-c-step-nav-header")
assert_select(".gem-c-step-nav-header", false)
assert_select "a", text: "Home"
assert_select "a", text: "Passports, travel and living abroad"
assert_select "a", text: "Passports"
Expand All @@ -72,7 +72,7 @@ def set_live_taxons(content_item)
content_item = example_document_for("licence", "licence_without_continuation_link")
content_item = remove_mainstream_browse(content_item)
render_component(content_item:)
assert_no_selector(".gem-c-step-nav-header")
assert_select(".gem-c-step-nav-header", false)
assert_select "a", text: "Home"
assert_select "a", text: "Business and self-employed"
assert_select "a", text: "Licences and licence applications"
Expand All @@ -82,7 +82,7 @@ def set_live_taxons(content_item)
content_item = example_document_for("guide", "guide-with-no-parent")
content_item = set_live_taxons(content_item)
render_component(content_item:)
assert_no_selector(".gem-c-step-nav-header")
assert_select(".gem-c-step-nav-header", false)
assert_select "a", text: "Home"
assert_select "a", text: "School curriculum"
assert_select "a", text: "Education, training and skills"
Expand Down Expand Up @@ -118,8 +118,8 @@ def set_live_taxons(content_item)
content_item = remove_mainstream_browse(content_item)
content_item = remove_curated_related_item(content_item)
content_item["links"]["taxons"].each { |taxon| taxon["phase"] = "draft" }
assert_no_selector(".gem-c-step-nav-header")
assert_no_selector(".gem-c-breadcrumbs")
assert_select(".gem-c-step-nav-header", false)
assert_select(".gem-c-breadcrumbs", false)
end

it "renders parent finder breadcrumb if content schema is a specialist document" do
Expand Down Expand Up @@ -177,8 +177,8 @@ def set_live_taxons(content_item)
content_item = remove_mainstream_browse(content_item)
content_item = remove_curated_related_item(content_item)
content_item["links"]["taxons"] = nil
assert_no_selector(".gem-c-step-nav-header")
assert_no_selector(".gem-c-breadcrumbs")
assert_select(".gem-c-step-nav-header", false)
assert_select(".gem-c-breadcrumbs", false)
end

it "renders taxon breadcrumbs even if there are mainstream browse pages if prioritise_taxon_breadcrumbs is true" do
Expand All @@ -187,8 +187,8 @@ def set_live_taxons(content_item)
content_item = set_live_taxons(content_item)
render_component(content_item:, prioritise_taxon_breadcrumbs: true)
assert_select "a", text: "Home"
assert_no_selector "a", text: "Business and self-employed"
assert_no_selector "a", text: "Licences and licence applications"
assert_select "a", text: "Business and self-employed", count: 0
assert_select "a", text: "Licences and licence applications", count: 0
assert_select "a", text: "School curriculum"
assert_select "a", text: "Education, training and skills"
end
Expand All @@ -201,8 +201,8 @@ def set_live_taxons(content_item)
assert_select "a", text: "Home"
assert_select "a", text: "Business and self-employed"
assert_select "a", text: "Licences and licence applications"
assert_no_selector "a", text: "School curriculum"
assert_no_selector "a", text: "Education, training and skills"
assert_select "a", text: "School curriculum", count: 0
assert_select "a", text: "Education, training and skills", count: 0
end

it "renders mainstream browse pages if prioritise_taxon_breadcrumbs is not passed and are live taxons" do
Expand All @@ -213,7 +213,7 @@ def set_live_taxons(content_item)
assert_select "a", text: "Home"
assert_select "a", text: "Business and self-employed"
assert_select "a", text: "Licences and licence applications"
assert_no_selector "a", text: "School curriculum"
assert_no_selector "a", text: "Education, training and skills"
assert_select "a", text: "School curriculum", count: 0
assert_select "a", text: "Education, training and skills", count: 0
end
end
19 changes: 14 additions & 5 deletions spec/components/contextual_footer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,25 @@ def component_name

render_component(content_item:)

has_selector? ".gem-c-contextual-footer"
assert_select ".gem-c-contextual-footer"
end

context "part of a step by step" do
it "does not renders the footer" do
render_component(
content_item: GovukSchemas::RandomExample.for_schema(frontend_schema: "step_by_step_nav"),
)
content_item = GovukSchemas::RandomExample.for_schema(frontend_schema: "speech") do |payload|
payload["links"].merge!("part_of_step_navs" => [{
"title" => "Step by Step",
"content_id" => SecureRandom.uuid,
"base_path" => "/step-by-step",
"locale" => "en",
}])

assert_no_selector ".gem-c-contextual-footer"
payload
end

render_component(content_item:)

assert_select ".gem-c-contextual-footer", false
end
end

Expand Down
11 changes: 6 additions & 5 deletions spec/components/input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ def component_name
name: "email-address",
width: 11,
)
expect(page).to have_no_css(".govuk-input--width-10")

assert_select ".govuk-input--width-10", false
end

context "when a hint is provided" do
Expand Down Expand Up @@ -283,7 +284,7 @@ def component_name
enterkeyhint: "chocolate",
)

assert_no_selector ".govuk-input[enterkeyhint='chocolate']"
assert_select ".govuk-input[enterkeyhint='chocolate']", false
end

it "renders the input and label with the correct `dir` attribute when the input is set to 'right_to_left: true'" do
Expand Down Expand Up @@ -314,8 +315,8 @@ def component_name
)

assert_select ".govuk-input[dir='rtl']"
assert_no_selector ".govuk-label[dir='rtl']"
assert_no_selector ".govuk-hint[dir='rtl']"
assert_no_selector ".govuk-error-message[dir='rtl']"
assert_select ".govuk-label[dir='rtl']", false
assert_select ".govuk-hint[dir='rtl']", false
assert_select ".govuk-error-message[dir='rtl']", false
end
end
4 changes: 2 additions & 2 deletions spec/components/layout_footer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ def component_name
it "allows the licence to be hidden" do
render_component({ hide_licence: true })

assert_no_selector ".govuk-footer__licence-logo"
assert_no_selector ".govuk-footer__licence-description"
assert_select ".govuk-footer__licence-logo", false
assert_select ".govuk-footer__licence-description", false
end

it "shows the licence if hide_licence is set to false" do
Expand Down
2 changes: 1 addition & 1 deletion spec/components/layout_for_public_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

describe "Layout for public", type: :view do
describe "Layout for public", :capybara, type: :view do
def component_name
"layout_for_public"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/components/radio_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ def component_name
end

# This component can be interacted with, so use integration tests for these cases.
describe "Radio (integration)" do
describe "Radio (integration)", :capybara do
def input_visible
false # our inputs are hidden with CSS, and rely on the label.
end
Expand Down
6 changes: 3 additions & 3 deletions spec/components/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,18 @@ def component_name
it "renders the correct label size" do
render_component(label_size: "xl")
assert_select ".govuk-label.govuk-label--xl", text: "Search on GOV.UK"
assert_no_selector ".gem-c-search__label"
assert_select ".gem-c-search__label", false
end

it "renders the default label when given an incorrect t-shirt size" do
render_component(label_size: "super-massive-size")
assert_no_selector ".govuk-label"
assert_select ".govuk-label", false
assert_select ".gem-c-search__label", text: "Search on GOV.UK"
end

it "renders the default label when given no label size" do
render_component({})
assert_no_selector ".govuk-label"
assert_select ".govuk-label", false
assert_select ".gem-c-search__label", text: "Search on GOV.UK"
end

Expand Down
6 changes: 3 additions & 3 deletions spec/components/textarea_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ def component_name
)

assert_select ".govuk-textarea[dir='rtl']"
assert_no_selector ".govuk-label[dir='rtl']"
assert_no_selector ".govuk-hint[dir='rtl']"
assert_no_selector ".govuk-error-message[dir='rtl']"
assert_select ".govuk-label[dir='rtl']", false
assert_select ".govuk-hint[dir='rtl']", false
assert_select ".govuk-error-message[dir='rtl']", false
end
end
2 changes: 1 addition & 1 deletion spec/features/accordion_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

describe "Accordion", js: true, type: :view do
describe "Accordion", :js, :capybara do
scenario "There is a page with the accordion rendered" do
given_i_visit_a_page_with_the_accordion_component
then_the_accordion_loads
Expand Down
2 changes: 1 addition & 1 deletion spec/features/asset_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe "When the asset helper is configured", type: :view do
describe "When the asset helper is configured", :capybara do
scenario "go to page with multiple GOV.UK publishing components only" do
GovukPublishingComponents.configure do |config|
config.exclude_css_from_static = true
Expand Down
2 changes: 1 addition & 1 deletion spec/features/contextual_navigation_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

describe "Contextual navigation" do
describe "Contextual navigation", :capybara do
scenario "There's a step by step list" do
given_theres_a_page_with_a_step_by_step
and_i_visit_that_page
Expand Down
2 changes: 1 addition & 1 deletion spec/features/step_nav_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

describe "Specimen usage of step by step navigation helpers" do
describe "Specimen usage of step by step navigation helpers", :capybara do
include GdsApi::TestHelpers::ContentStore

context "no related step by step navigation journeys" do
Expand Down
2 changes: 1 addition & 1 deletion spec/features/tabs_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

describe "Tabs component", js: true do
describe "Tabs component", :js, :capybara do
scenario "Tabs load" do
given_i_visit_a_page_with_the_tabs_component
then_the_tabs_load
Expand Down
2 changes: 1 addition & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Selenium::WebDriver::Options.chrome(loggingPrefs: { browser: "ALL" })

RSpec.configure do |config|
config.include Capybara::DSL
config.include Capybara::DSL, capybara: true, visual_regression: true
config.include Helpers::Components, type: :view
config.include ActiveSupport::Testing::TimeHelpers
end
2 changes: 1 addition & 1 deletion spec/visual_regression_tests/all_components_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require "percy/capybara"
require "uri"

describe "visual regression test runner Percy", visual_regression: true do
describe "visual regression test runner Percy", :visual_regression do
it "takes a screenshot of each component" do
# Freeze time for consistency
travel_to Time.zone.local(2020, 12, 1, 6, 0, 0)
Expand Down

0 comments on commit 4496b31

Please sign in to comment.