Wait for suggestions to finish loading in tests
Sometimes tests were hanging indefinitely. Debugging shows that in some
cases it's due to submitting a form before the AJAX request to get
proposals, debates or investments suggestions is finished, since having
an AJAX and a non-AJAX request at the same time when running the test
sometimes leads to unexpected results.
In our case, we were having many timeouts in Github Actions in the
branches where we use both ActiveStorage and Paperclip to store files
(based on pull request 4598). I can reproduce it in those branches
running the following test ("Should show new image after successful
creation with one uploaded file"), although only when my laptop isn't
plugged (!!):
```
rspec './spec/system/proposals_spec.rb[1:33:1:14]'
```
Since we didn't have a proper way to know the AJAX request had finished,
we're adding a `suggest-success` class to the element showing the
suggestions when that happens. Then in the tests we can look for that
class after filling in the title of a proposal, debate or investments.
Just for clarity's sake, we're also adding the `suggest-loading` class
when the suggestions are loading.
In order not to have expectations everywhere about the suggestions,
we're extracting methods to fill in those titles in the tests. Note we
aren't using these methods in the "edit" actions (suggestions are not
showing when editing) or in tests with the `no_js` tag (since
suggestions only work with JavaScript).
This commit is contained in:
@@ -65,7 +65,7 @@ describe "Budget Investments" do
|
||||
expect(page).to have_content user.document_number
|
||||
end
|
||||
|
||||
fill_in "Title", with: "Build a park in my neighborhood"
|
||||
fill_in_new_investment_title with: "Build a park in my neighborhood"
|
||||
fill_in_ckeditor "Description", with: "There is no parks here..."
|
||||
fill_in "budget_investment_location", with: "City center"
|
||||
fill_in "budget_investment_organization_name", with: "T.I.A."
|
||||
|
||||
@@ -16,7 +16,7 @@ describe "Proposals" do
|
||||
expect(page).to have_content user.document_number.to_s
|
||||
end
|
||||
|
||||
fill_in "Proposal title", with: "Help refugees"
|
||||
fill_in_new_proposal_title with: "Help refugees"
|
||||
fill_in "Proposal summary", with: "In summary, what we want is..."
|
||||
fill_in_ckeditor "Proposal text", with: "This is very important because..."
|
||||
fill_in "External video URL", with: "https://www.youtube.com/watch?v=yRYFKcMa_Ek"
|
||||
|
||||
Reference in New Issue
Block a user