From 0a1ddcfaeea76a4c9618e7a7abfb3f14c5a98f76 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Fri, 19 Jul 2019 13:40:45 +0200 Subject: [PATCH 1/3] Change how disabled button is checked in new refund feature spec This is an attempt to fix a flaky spec that we have: https://circleci.com/gh/nebulab/solidus/2687#tests/containers/1 Using a more standard way of checking HTML elements state for Capybara could fix the issue since it could not be waiting for the button to change state with the current code. --- backend/spec/features/admin/orders/new_refund_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/spec/features/admin/orders/new_refund_spec.rb b/backend/spec/features/admin/orders/new_refund_spec.rb index 9dcb0b2950b..039e54fc520 100644 --- a/backend/spec/features/admin/orders/new_refund_spec.rb +++ b/backend/spec/features/admin/orders/new_refund_spec.rb @@ -29,7 +29,7 @@ fill_in 'refund_amount', with: amount select reason.name, from: 'Reason' click_button 'Refund' - expect(find('input[type="submit"]')).to be_disabled + expect(page).to have_button('Refund', disabled: true) end end end From 1e8d0d89123908cff3532e955110c9a299c24241 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Fri, 19 Jul 2019 13:47:22 +0200 Subject: [PATCH 2/3] Change how we check for flash messages in a product edit spec This is an attempt to fix a flaky spec: https://circleci.com/gh/nebulab/solidus/2686#tests/containers/1 Probably using this method, Capybara will wait for the page to display the flash message before making the expectation fail. --- backend/spec/features/admin/products/edit/taxons_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/spec/features/admin/products/edit/taxons_spec.rb b/backend/spec/features/admin/products/edit/taxons_spec.rb index 3a63112006e..855ff888fe1 100644 --- a/backend/spec/features/admin/products/edit/taxons_spec.rb +++ b/backend/spec/features/admin/products/edit/taxons_spec.rb @@ -26,13 +26,13 @@ def assert_selected_taxons(taxons) visit spree.edit_admin_product_path(product) assert_selected_taxons([taxon_1]) - select2_search "Clothing", from: "Taxon" assert_selected_taxons([taxon_1, taxon_2]) click_button "Update" - - expect(find(".flash")).to have_text "Product \"#{product.name}\" has been successfully updated!" + within('.flash') do + expect(page).to have_content(%(Product "#{product.name}" has been successfully updated!)) + end assert_selected_taxons([taxon_1, taxon_2]) end From 401278d2007e475e5647929c8cf09f2b58db4180 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Wed, 7 Aug 2019 16:58:03 +0200 Subject: [PATCH 3/3] Click somewhere else on the page before submit Without this line we have a flaky spec probably due to select2 not closing its fixed overlay correctly. We've notice that the submit button wasn't pressed at all when we had failures. This means something is preventing the click to happen. The select2 plugin has a lot of code that interacts with other page elements preventing clicks so that could be the root cause. Clicking anywhere in the page before submit apparently solves the issue. --- backend/spec/features/admin/products/edit/taxons_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/spec/features/admin/products/edit/taxons_spec.rb b/backend/spec/features/admin/products/edit/taxons_spec.rb index 855ff888fe1..6af6bad67a5 100644 --- a/backend/spec/features/admin/products/edit/taxons_spec.rb +++ b/backend/spec/features/admin/products/edit/taxons_spec.rb @@ -29,7 +29,13 @@ def assert_selected_taxons(taxons) select2_search "Clothing", from: "Taxon" assert_selected_taxons([taxon_1, taxon_2]) + # Without this line we have a flaky spec probably due to select2 not + # closing its fixed overlay correctly. Clicking anywhere in the page + # before submit apparently solves the issue. + find('.edit_product', visible: true, obscured: false).click + click_button "Update" + within('.flash') do expect(page).to have_content(%(Product "#{product.name}" has been successfully updated!)) end