From dddd5dd808cf7783bd6776017cf9fb575c27847e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 13 May 2020 17:36:05 +0200 Subject: [PATCH 1/2] Check the DOM after attaching file has succeeded We were checking `expect_document_has_title(0, "My Title")`, which was already true before the AJAX request generated by `attach_file` had finished. That meant the AJAX request sometimes was handled after this test had finished, affecting the following test and causing it to fail because its cookie was overwritten and so `current_user` was set to `nil`. In the test checking the filename is present, a similar scenario was taking place: we were updating the `.file-name` element in the `change` event of `fileupload` (using `App.Documentable.setFilename`); that is, when the AJAX request started. And so the test passed before the request was finished, causing the same issue. --- spec/shared/system/nested_documentable.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/shared/system/nested_documentable.rb b/spec/shared/system/nested_documentable.rb index 3a461b12b..9c6482d84 100644 --- a/spec/shared/system/nested_documentable.rb +++ b/spec/shared/system/nested_documentable.rb @@ -80,6 +80,8 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na Rails.root.join("spec/fixtures/files/empty.pdf"), make_visible: true ) + + expect(page).to have_css ".loading-bar.complete" end expect(page).to have_css ".file-name", text: "empty.pdf" @@ -110,6 +112,8 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na Rails.root.join("spec/fixtures/files/empty.pdf"), make_visible: true ) + + expect(page).to have_css ".loading-bar.complete" end expect_document_has_title(0, "My Title") From f5c8d5eea6f76d7ce351f92661b3204f861f5b9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 14 May 2020 00:12:14 +0200 Subject: [PATCH 2/2] Submit the form after the image is attached We were submitting the form without checking the AJAX request to attach the image had finished, so sometimes two requests were executed at the same time. Sometimes this made InvisibleCaptcha to go crazy and report the form was submitted too quickly. Checking the first AJAX request has finished before submitting the form solves the problem. --- spec/shared/system/nested_imageable.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/shared/system/nested_imageable.rb b/spec/shared/system/nested_imageable.rb index 19592858f..6977e3e81 100644 --- a/spec/shared/system/nested_imageable.rb +++ b/spec/shared/system/nested_imageable.rb @@ -182,6 +182,8 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p Rails.root.join("spec/fixtures/files/clippy.jpg") ) + expect(page).to have_selector ".loading-bar.complete" + click_on submit_button expect(page).to have_content imageable_success_notice @@ -197,6 +199,8 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p Rails.root.join("spec/fixtures/files/clippy.jpg") ) + expect(page).to have_selector ".loading-bar.complete" + click_on submit_button imageable_redirected_to_resource_show_or_navigate_to