Skip to content

Commit

Permalink
test: Wait for modal to open before testing its content
Browse files Browse the repository at this point in the history
Capybara needs to be told to expect that the modal is open
before we can check for content present in it.

Fixes a lot of extremely flaky specs.

(cherry picked from commit c67f75f)
  • Loading branch information
tvdeyen committed Dec 3, 2024
1 parent 0519828 commit 29692af
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions admin/spec/features/adjustment_reasons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
before do
visit "/admin/adjustment_reasons#{query}"
click_on "Add new"
expect(page).to have_selector("dialog")
expect(page).to have_content("New Adjustment Reason")
expect(page).to be_axe_clean
end

it "opens a modal" do
expect(page).to have_selector("dialog")
it "closing the modal keeps query params" do
within("dialog") { click_on "Cancel" }
expect(page).not_to have_selector("dialog")
expect(page.current_url).to include(query)
Expand Down Expand Up @@ -69,12 +69,12 @@
Spree::AdjustmentReason.create(name: "Good Reason", code: 5999)
visit "/admin/adjustment_reasons#{query}"
find_row("Good Reason").click
expect(page).to have_selector("dialog")
expect(page).to have_content("Edit Adjustment Reason")
expect(page).to be_axe_clean
end

it "opens a modal" do
expect(page).to have_selector("dialog")
it "closing the modal keeps query params" do
within("dialog") { click_on "Cancel" }
expect(page).not_to have_selector("dialog")
expect(page.current_url).to include(query)
Expand Down
8 changes: 4 additions & 4 deletions admin/spec/features/refund_reasons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
before do
visit "/admin/refund_reasons/#{query}"
click_on "Add new"
expect(page).to have_selector("dialog")
expect(page).to have_content("New Refund Reason")
expect(page).to be_axe_clean
end

it "opens a modal" do
expect(page).to have_selector("dialog")
it "closing the modal keeps query params" do
within("dialog") { click_on "Cancel" }
expect(page).not_to have_selector("dialog")
expect(page.current_url).to include(query)
Expand Down Expand Up @@ -66,12 +66,12 @@
Spree::RefundReason.create(name: "Return process")
visit "/admin/refund_reasons#{query}"
find_row("Return process").click
expect(page).to have_selector("dialog")
expect(page).to have_content("Edit Refund Reason")
expect(page).to be_axe_clean
end

it "opens a modal" do
expect(page).to have_selector("dialog")
it "closing the modal keeps query params" do
within("dialog") { click_on "Cancel" }
expect(page).not_to have_selector("dialog")
expect(page.current_url).to include(query)
Expand Down
8 changes: 4 additions & 4 deletions admin/spec/features/return_reasons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
before do
visit "/admin/return_reasons#{query}"
click_on "Add new"
expect(page).to have_selector("dialog")
expect(page).to have_content("New Return Reason")
expect(page).to be_axe_clean
end

it "opens a modal" do
expect(page).to have_selector("dialog")
it "closing the modal keeps query params" do
within("dialog") { click_on "Cancel" }
expect(page).not_to have_selector("dialog")
expect(page.current_url).to include(query)
Expand Down Expand Up @@ -68,12 +68,12 @@
Spree::ReturnReason.create(name: "Good Reason")
visit "/admin/return_reasons#{query}"
find_row("Good Reason").click
expect(page).to have_selector("dialog")
expect(page).to have_content("Edit Return Reason")
expect(page).to be_axe_clean
end

it "opens a modal" do
expect(page).to have_selector("dialog")
it "closing the modal keeps query params" do
within("dialog") { click_on "Cancel" }
expect(page).not_to have_selector("dialog")
expect(page.current_url).to include(query)
Expand Down
8 changes: 4 additions & 4 deletions admin/spec/features/roles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@
before do
visit "/admin/roles#{query}"
click_on "Add new"
expect(page).to have_selector("dialog")
expect(page).to have_content("New Role")
expect(page).to be_axe_clean
end

it "opens a modal" do
expect(page).to have_selector("dialog")
it "closing the modal keeps query params" do
within("dialog") { click_on "Cancel" }
expect(page).not_to have_selector("dialog")
expect(page.current_url).to include(query)
Expand Down Expand Up @@ -121,14 +121,14 @@
Spree::Role.create(name: "Reviewer", permission_sets: [settings_edit_permission])
visit "/admin/roles#{query}"
find_row("Reviewer").click
expect(page).to have_selector("dialog")
expect(page).to have_content("Edit Role")
expect(page).to be_axe_clean
expect(Spree::Role.find_by(name: "Reviewer").permission_set_ids)
.to contain_exactly(settings_edit_permission.id)
end

it "opens a modal" do
expect(page).to have_selector("dialog")
it "closing the modal keeps query params" do
within("dialog") { click_on "Cancel" }
expect(page).not_to have_selector("dialog")
expect(page.current_url).to include(query)
Expand Down
8 changes: 4 additions & 4 deletions admin/spec/features/shipping_categories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
before do
visit "/admin/shipping_categories#{query}"
click_on "Add new"
expect(page).to have_selector("dialog")
expect(page).to have_content("New Shipping Category")
expect(page).to be_axe_clean
end

it "opens a modal" do
expect(page).to have_selector("dialog")
it "closing the modal keeps query params" do
within("dialog") { click_on "Cancel" }
expect(page).not_to have_selector("dialog")
expect(page.current_url).to include(query)
Expand Down Expand Up @@ -66,12 +66,12 @@
Spree::ShippingCategory.create(name: "Letter Mail")
visit "/admin/shipping_categories#{query}"
find_row("Letter Mail").click
expect(page).to have_selector("dialog")
expect(page).to have_content("Edit Shipping Category")
expect(page).to be_axe_clean
end

it "opens a modal" do
expect(page).to have_selector("dialog")
it "closing the modal keeps query params" do
within("dialog") { click_on "Cancel" }
expect(page).not_to have_selector("dialog")
expect(page.current_url).to include(query)
Expand Down
8 changes: 4 additions & 4 deletions admin/spec/features/store_credit_reasons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
before do
visit "/admin/store_credit_reasons#{query}"
click_on "Add new"
expect(page).to have_selector("dialog")
expect(page).to have_content("New Store Credit Reason")
expect(page).to be_axe_clean
end

it "opens a modal" do
expect(page).to have_selector("dialog")
it "closing the modal keeps query params" do
within("dialog") { click_on "Cancel" }
expect(page).not_to have_selector("dialog")
expect(page.current_url).to include(query)
Expand Down Expand Up @@ -66,12 +66,12 @@
Spree::StoreCreditReason.create(name: "New Customer Reward")
visit "/admin/store_credit_reasons#{query}"
find_row("New Customer Reward").click
expect(page).to have_selector("dialog")
expect(page).to have_content("Edit Store Credit Reason")
expect(page).to be_axe_clean
end

it "opens a modal" do
expect(page).to have_selector("dialog")
it "closing the modal keeps query params" do
within("dialog") { click_on "Cancel" }
expect(page).not_to have_selector("dialog")
expect(page.current_url).to include(query)
Expand Down
4 changes: 2 additions & 2 deletions admin/spec/features/tax_categories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
before do
visit "/admin/tax_categories#{query}"
click_on "Add new"
expect(page).to have_selector("dialog")
expect(page).to have_content("New Tax Category")
expect(page).to be_axe_clean
end

it "opens a modal" do
expect(page).to have_selector("dialog")
it "closing the modal keeps query params" do
within("dialog") { click_on "Cancel" }
expect(page).not_to have_selector("dialog")
expect(page.current_url).to include(query)
Expand Down

0 comments on commit 29692af

Please sign in to comment.