From f63be041c129fe5f91dae6996f59acd4540c4acf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 14 Mar 2025 20:30:51 +0100 Subject: [PATCH] Add missing expectations to confirm the page has changed After a `visit`, we were checking for content or filling in fields that were already there before the `visit`, so we weren't 100% sure that the request had finished before the test continued. In the case of the verification tests, we were clicking the submit buttons over and over without and then checking or interacting with elements that were already there. Even though the button was disabled between requests, meaning there wouldn't be simultaneous requests, it was possible to interact with a form field before waiting for the request to finish. Some of these tests have recently failed on our CI, and it might be because of that: ``` 1) Admin budgets Edit Changing name for current locale will update the slug if budget is in draft phase Failure/Error: raise ex, cause: cause Selenium::WebDriver::Error::UnknownError: unknown error: unhandled inspector error: {"code":-32000, "message":"Node with given id does not belong to the document"} (Session info: chrome=134.0.6998.35) 1) Budgets creation wizard Creation of a multiple-headings budget by steps Failure/Error: expect(page).to have_content "Heading created successfully!" Selenium::WebDriver::Error::UnknownError: unknown error: unhandled inspector error: {"code":-32000, "message":"Node with given id does not belong to the document"} (Session info: chrome=134.0.6998.35) 1) Custom information texts Show custom texts instead of default ones Failure/Error: raise ex, cause: cause Selenium::WebDriver::Error::UnknownError: unknown error: unhandled inspector error: {"code":-32000, "message":"Node with given id does not belong to the document"} (Session info: chrome=134.0.6998.35) 1) Users Regular authentication Sign in Avoid username-email collisions Failure/Error: raise ex, cause: cause Selenium::WebDriver::Error::UnknownError: unknown error: unhandled inspector error: {"code":-32000, "message":"Node with given id does not belong to the document"} (Session info: chrome=134.0.6998.35) 2) Verify Letter Code verification 6 tries allowed Failure/Error: raise ex, cause: cause Selenium::WebDriver::Error::UnknownError: unknown error: unhandled inspector error: {"code":-32000, "message":"Node with given id does not belong to the document"} (Session info: chrome=134.0.6998.35) 2) Valuation budget investments Valuate Finish valuation Failure/Error: raise ex, cause: cause Selenium::WebDriver::Error::UnknownError: unknown error: unhandled inspector error: {"code":-32000, "message":"Node with given id does not belong to the document"} (Session info: chrome=134.0.6998.35) 1) Users Delete a level 2 user account from document verification page Failure/Error: raise ex, cause: cause Selenium::WebDriver::Error::UnknownError: unknown error: unhandled inspector error: {"code":-32000, "message":"Node with given id does not belong to the document"} (Session info: chrome=134.0.6998.35) ``` --- spec/system/admin/budget_headings_spec.rb | 2 + spec/system/admin/budgets_spec.rb | 5 +++ .../admin/budgets_wizard/budgets_spec.rb | 4 +- .../admin/budgets_wizard/groups_spec.rb | 2 +- .../admin/budgets_wizard/headings_spec.rb | 2 +- .../admin/budgets_wizard/wizard_spec.rb | 6 +++ spec/system/admin/poll/booths_spec.rb | 19 +++++--- spec/system/admin/translatable_spec.rb | 8 ++-- spec/system/budgets/executions_spec.rb | 44 ++++++++++++------- spec/system/management/users_spec.rb | 3 +- spec/system/moderation/users_spec.rb | 6 +-- .../information_texts_spec.rb | 3 ++ spec/system/users_auth_spec.rb | 7 ++- .../valuation/budget_investments_spec.rb | 4 +- spec/system/verification/letter_spec.rb | 14 ++++-- spec/system/verification/residence_spec.rb | 3 ++ 16 files changed, 88 insertions(+), 44 deletions(-) diff --git a/spec/system/admin/budget_headings_spec.rb b/spec/system/admin/budget_headings_spec.rb index 04b00a40b..eaa1a9af5 100644 --- a/spec/system/admin/budget_headings_spec.rb +++ b/spec/system/admin/budget_headings_spec.rb @@ -189,6 +189,7 @@ describe "Admin budget headings", :admin do visit budget_investments_path(budget, heading_id: "old-english-name") + expect(page).not_to have_content "Heading updated successfully" expect(page).to have_content "Old English Name" visit edit_admin_budget_group_heading_path(budget, group, heading) @@ -201,6 +202,7 @@ describe "Admin budget headings", :admin do visit budget_investments_path(budget, heading_id: "new-english-name") + expect(page).not_to have_content "Heading updated successfully" expect(page).to have_content "New English Name" end end diff --git a/spec/system/admin/budgets_spec.rb b/spec/system/admin/budgets_spec.rb index d3ede52c7..5b4518281 100644 --- a/spec/system/admin/budgets_spec.rb +++ b/spec/system/admin/budgets_spec.rb @@ -128,6 +128,9 @@ describe "Admin budgets", :admin do expect(page).to have_content "Group created successfully!" + within("#notice") { click_button "Close" } + expect(page).not_to have_content "Group created successfully!" + click_button "Add new group" fill_in "Group name", with: "District A" click_button "Create new group" @@ -315,6 +318,7 @@ describe "Admin budgets", :admin do visit budget_path(id: "old-english-name") + expect(page).not_to have_content "Participatory budget updated successfully" expect(page).to have_content "Old English Name" visit edit_admin_budget_path(budget) @@ -327,6 +331,7 @@ describe "Admin budgets", :admin do visit budget_path(id: "new-english-name") + expect(page).not_to have_content "Participatory budget updated successfully" expect(page).to have_content "New English Name" end diff --git a/spec/system/admin/budgets_wizard/budgets_spec.rb b/spec/system/admin/budgets_wizard/budgets_spec.rb index c96342bde..57a0d355e 100644 --- a/spec/system/admin/budgets_wizard/budgets_spec.rb +++ b/spec/system/admin/budgets_wizard/budgets_spec.rb @@ -48,9 +48,9 @@ describe "Budgets wizard, first step", :admin do visit new_admin_budgets_wizard_budget_path click_button "Continue to groups" - expect(page).not_to have_content "New participatory budget created successfully!" expect(page).to have_css ".is-invalid-label", text: "Name" expect(page).to have_css ".creation-timeline" + expect(page).not_to have_content "New participatory budget created successfully!" end scenario "Name should be unique" do @@ -60,9 +60,9 @@ describe "Budgets wizard, first step", :admin do fill_in "Name", with: "Existing Name" click_button "Continue to groups" - expect(page).not_to have_content "New participatory budget created successfully!" expect(page).to have_css(".is-invalid-label", text: "Name") expect(page).to have_css("small.form-error", text: "has already been taken") + expect(page).not_to have_content "New participatory budget created successfully!" end scenario "Do not show results and stats settings on new budget" do diff --git a/spec/system/admin/budgets_wizard/groups_spec.rb b/spec/system/admin/budgets_wizard/groups_spec.rb index 13d04105e..3927777db 100644 --- a/spec/system/admin/budgets_wizard/groups_spec.rb +++ b/spec/system/admin/budgets_wizard/groups_spec.rb @@ -53,12 +53,12 @@ describe "Budgets wizard, groups step", :admin do click_button "Create new group" - expect(page).not_to have_content "Group created successfully!" expect(page).to have_css ".is-invalid-label", text: "Group name" expect(page).to have_css ".creation-timeline" expect(page).to have_content "can't be blank" expect(page).to have_button "Create new group" expect(page).to have_button "Cancel" + expect(page).not_to have_content "Group created successfully!" expect(page).not_to have_button "Add new group" expect(page).not_to have_content "Continue to headings" end diff --git a/spec/system/admin/budgets_wizard/headings_spec.rb b/spec/system/admin/budgets_wizard/headings_spec.rb index de50af030..d56983fd5 100644 --- a/spec/system/admin/budgets_wizard/headings_spec.rb +++ b/spec/system/admin/budgets_wizard/headings_spec.rb @@ -74,11 +74,11 @@ describe "Budgets wizard, headings step", :admin do click_button "Create new heading" - expect(page).not_to have_content "Heading created successfully!" expect(page).to have_css(".is-invalid-label", text: "Heading name") expect(page).to have_content "can't be blank" expect(page).to have_button "Create new heading" expect(page).to have_button "Cancel" + expect(page).not_to have_content "Heading created successfully!" expect(page).not_to have_button "Add new heading" expect(page).not_to have_content "Continue to phases" diff --git a/spec/system/admin/budgets_wizard/wizard_spec.rb b/spec/system/admin/budgets_wizard/wizard_spec.rb index 85cb9c514..34a26f3ff 100644 --- a/spec/system/admin/budgets_wizard/wizard_spec.rb +++ b/spec/system/admin/budgets_wizard/wizard_spec.rb @@ -52,6 +52,9 @@ describe "Budgets creation wizard", :admin do within("table") { expect(page).to have_content "All city" } expect(page).not_to have_content "There are no groups." + within("#notice") { click_button "Close" } + expect(page).not_to have_content "Group created successfully!" + click_button "Add new group" fill_in "Group name", with: "Districts" click_button "Create new group" @@ -85,6 +88,9 @@ describe "Budgets creation wizard", :admin do within_table("Headings in Districts") { expect(page).to have_content "North" } expect(page).not_to have_content "There are no headings" + within("#notice") { click_button "Close" } + expect(page).not_to have_content "Heading created successfully!" + click_button "Add new heading" fill_in "Heading name", with: "South" fill_in "Money amount", with: "500000" diff --git a/spec/system/admin/poll/booths_spec.rb b/spec/system/admin/poll/booths_spec.rb index 7b38e46ea..5a12c77d9 100644 --- a/spec/system/admin/poll/booths_spec.rb +++ b/spec/system/admin/poll/booths_spec.rb @@ -113,17 +113,24 @@ describe "Admin booths", :admin do end scenario "Search" do - booth = create(:poll_booth) + create(:poll_booth, name: "Consulting Detective", location: "221B Baker Street") + create(:poll_booth, name: "World's Greatest Detective", location: "Gotham") visit admin_booths_path - fill_in "search", with: booth.name - click_button "Search" - expect(page).to have_css(".booth", count: 1) + expect(page).to have_css ".booth", count: 2 - fill_in "search", with: booth.location + fill_in "search", with: "Consulting" click_button "Search" - expect(page).to have_css(".booth", count: 1) + expect(page).not_to have_content "Greatest Detective" + expect(page).to have_content "Consulting Detective" + expect(page).to have_css ".booth", count: 1 + + fill_in "search", with: "Gotham" + click_button "Search" + expect(page).not_to have_content "Consulting Detective" + expect(page).to have_content "Greatest Detective" + expect(page).to have_css ".booth", count: 1 fill_in "search", with: "Wrong search criteria" click_button "Search" diff --git a/spec/system/admin/translatable_spec.rb b/spec/system/admin/translatable_spec.rb index 11080fe8a..8a8dc8128 100644 --- a/spec/system/admin/translatable_spec.rb +++ b/spec/system/admin/translatable_spec.rb @@ -87,7 +87,6 @@ describe "Admin edit translatable records", :admin do expect(page).to have_content "Draft updated successfully" - visit path click_link class: "fullscreen-toggle" expect(page).to have_field "Text", with: "Text in English" @@ -120,6 +119,9 @@ describe "Admin edit translatable records", :admin do expect(page).to have_content "Question updated successfully" visit path + + expect(page).not_to have_content "Question updated successfully" + select "Português brasileiro", from: "Language:" expect(page).to have_field "Questão", with: "Português" @@ -338,8 +340,6 @@ describe "Admin edit translatable records", :admin do expect(page).to have_content "Process updated successfully" - visit edit_admin_legislation_process_path(translatable) - expect_to_have_language_selected "Français" expect_not_to_have_language "English" end @@ -363,8 +363,8 @@ describe "Admin edit translatable records", :admin do visit path - expect(page).not_to have_select "Current language", with_options: ["Español"] expect(page).to have_select "Current language", with_options: ["English"] + expect(page).not_to have_select "Current language", with_options: ["Español"] end end diff --git a/spec/system/budgets/executions_spec.rb b/spec/system/budgets/executions_spec.rb index d6e663cb6..26c3cb5b4 100644 --- a/spec/system/budgets/executions_spec.rb +++ b/spec/system/budgets/executions_spec.rb @@ -27,14 +27,21 @@ describe "Executions" do create(:milestone, milestoneable: investment1) visit budget_path(budget) + + expect(page).not_to have_content(investment1.title) + click_link "See results" + expect(page).to have_content(investment1.title) + expect(page).to have_content(investment2.title) + expect(page).to have_content(investment4.title) + click_link "Milestones" - expect(page).to have_content(investment1.title) expect(page).not_to have_content(investment2.title) expect(page).not_to have_content(investment3.title) expect(page).not_to have_content(investment4.title) + expect(page).to have_content(investment1.title) end scenario "Do not display headings with no winning investments for selected status" do @@ -56,11 +63,12 @@ describe "Executions" do end scenario "Show message when there are no winning investments with the selected status" do - create(:milestone_status, name: I18n.t("seeds.budgets.statuses.executed")) + create(:milestone, milestoneable: investment1) + create(:milestone_status, name: "Executed") visit budget_executions_path(budget) - expect(page).to have_content("No winner investments in this state") + expect(page).not_to have_content("No winner investments in this state") select "Executed (0)", from: "Project's current state" click_button "Filter" @@ -118,8 +126,8 @@ describe "Executions" do select "Studying the project (1)", from: "Project's current state" click_button "Filter" - expect(page).to have_content(investment1.title) expect(page).not_to have_content(investment2.title) + expect(page).to have_content(investment1.title) select "Bidding (1)", from: "Project's current state" click_button "Filter" @@ -130,8 +138,8 @@ describe "Executions" do select "Executing the project (0)", from: "Project's current state" click_button "Filter" - expect(page).not_to have_content(investment1.title) expect(page).not_to have_content(investment2.title) + expect(page).not_to have_content(investment1.title) end scenario "are based on latest milestone status" do @@ -145,15 +153,17 @@ describe "Executions" do visit budget_executions_path(budget) + expect(page).to have_content investment1.title + select "Studying the project (0)", from: "Project's current state" click_button "Filter" - expect(page).not_to have_content(investment1.title) + expect(page).not_to have_content investment1.title select "Bidding (1)", from: "Project's current state" click_button "Filter" - expect(page).to have_content(investment1.title) + expect(page).to have_content investment1.title end scenario "milestones with future dates are not shown" do @@ -167,15 +177,17 @@ describe "Executions" do visit budget_executions_path(budget) - select "Studying the project (1)", from: "Project's current state" - click_button "Filter" - - expect(page).to have_content(investment1.title) + expect(page).to have_content investment1.title select "Bidding (0)", from: "Project's current state" click_button "Filter" - expect(page).not_to have_content(investment1.title) + expect(page).not_to have_content investment1.title + + select "Studying the project (1)", from: "Project's current state" + click_button "Filter" + + expect(page).to have_content investment1.title end scenario "by milestone tag, only display tags for winner investments" do @@ -198,26 +210,26 @@ describe "Executions" do select "Studying the project (1)", from: "Project's current state" click_button "Filter" - expect(page).to have_content(investment1.title) expect(page).not_to have_content(investment2.title) + expect(page).to have_content(investment1.title) select "Bidding (1)", from: "Project's current state" click_button "Filter" - expect(page).not_to have_content(investment1.title) expect(page).to have_content(investment2.title) + expect(page).not_to have_content(investment1.title) select "tag1 (1)", from: "Milestone tag" click_button "Filter" - expect(page).not_to have_content(investment1.title) expect(page).not_to have_content(investment2.title) + expect(page).not_to have_content(investment1.title) select "All (2)", from: "Milestone tag" click_button "Filter" - expect(page).not_to have_content(investment1.title) expect(page).to have_content(investment2.title) + expect(page).not_to have_content(investment1.title) end end diff --git a/spec/system/management/users_spec.rb b/spec/system/management/users_spec.rb index 817cb0078..3b183b0fa 100644 --- a/spec/system/management/users_spec.rb +++ b/spec/system/management/users_spec.rb @@ -78,15 +78,14 @@ describe "Users" do fill_in "document_verification_document_number", with: "12345678Z" click_button "Check document" - expect(page).not_to have_content "This user account is already verified." expect(page).to have_content "This user can participate in the website with the following permissions" + expect(page).not_to have_content "This user account is already verified." click_link "Delete user" accept_confirm { click_button "Delete account" } expect(page).to have_content "User account deleted." - refresh fill_in "document_verification_document_number", with: "12345678Z" click_button "Check document" diff --git a/spec/system/moderation/users_spec.rb b/spec/system/moderation/users_spec.rb index 7ea01a603..8de8df186 100644 --- a/spec/system/moderation/users_spec.rb +++ b/spec/system/moderation/users_spec.rb @@ -34,16 +34,16 @@ describe "Moderate users" do expect(page).not_to have_content(debate2.title) expect(page).to have_content(debate3.title) - visit debate_path(debate3) + click_link debate3.title + expect(page).to have_css "h1", exact_text: debate3.title expect(page).not_to have_content(comment3.body) click_link "Sign out" expect(page).to have_content "You have been signed out successfully" - visit root_path - + within("#notice") { click_button "Close" } click_link "Sign in" fill_in "user_login", with: citizen.email fill_in "user_password", with: citizen.password diff --git a/spec/system/site_customization/information_texts_spec.rb b/spec/system/site_customization/information_texts_spec.rb index 0df49f4bc..a70205f89 100644 --- a/spec/system/site_customization/information_texts_spec.rb +++ b/spec/system/site_customization/information_texts_spec.rb @@ -12,6 +12,9 @@ describe "Custom information texts", :admin do expect(page).to have_content "Translation updated successfully" visit admin_site_customization_information_texts_path(tab: "proposals") + + expect(page).not_to have_content "Translation updated successfully" + fill_in "contents[content_#{proposal_key}]values[value_en]", with: "Custom help with proposals" click_button "Save" diff --git a/spec/system/users_auth_spec.rb b/spec/system/users_auth_spec.rb index 73f01d259..cf0b1b55d 100644 --- a/spec/system/users_auth_spec.rb +++ b/spec/system/users_auth_spec.rb @@ -94,12 +94,9 @@ describe "Users" do click_button "Enter" expect(page).to have_content "You have been signed in successfully." - - visit account_path - expect(page).to have_link "My content", href: user_path(u1) - visit "/" + within("#notice") { click_button "Close" } click_link "Sign out" expect(page).to have_content "You have been signed out successfully." @@ -235,6 +232,8 @@ describe "Users" do expect(page).to have_content "You have been signed out successfully" visit "/" + + expect(page).not_to have_content "You have been signed out successfully" expect_not_to_be_signed_in end diff --git a/spec/system/valuation/budget_investments_spec.rb b/spec/system/valuation/budget_investments_spec.rb index fb3849708..43e04ead9 100644 --- a/spec/system/valuation/budget_investments_spec.rb +++ b/spec/system/valuation/budget_investments_spec.rb @@ -427,7 +427,9 @@ describe "Valuation budget investments" do expect(page).to have_content investment.title click_link investment.title - expect(page).to have_content("Valuation finished") + + expect(page).to have_content "Investment preview" + expect(page).to have_content "Valuation finished" end context "Reopen valuation" do diff --git a/spec/system/verification/letter_spec.rb b/spec/system/verification/letter_spec.rb index 5f5d61b4b..71fd9ba6e 100644 --- a/spec/system/verification/letter_spec.rb +++ b/spec/system/verification/letter_spec.rb @@ -119,13 +119,19 @@ describe "Verify Letter" do visit edit_letter_path - 6.times do - fill_in "verification_letter_email", with: user.email - fill_in "verification_letter_password", with: user.password - fill_in "verification_letter_verification_code", with: "1" + 5.times do |n| + fill_in "Email", with: user.email + fill_in "Password", with: user.password + fill_in "Code you received in letter", with: "1" click_button "Verify my account" + + expect(page).to have_field "Password", with: "" + expect(page).to have_content "Verification code incorrect" end + fill_in "Password", with: user.password + click_button "Verify my account" + expect(page).to have_content "You have reached the maximum number of attempts. Please try again later." expect(page).to have_current_path(account_path) end diff --git a/spec/system/verification/residence_spec.rb b/spec/system/verification/residence_spec.rb index fa8850730..959024cd5 100644 --- a/spec/system/verification/residence_spec.rb +++ b/spec/system/verification/residence_spec.rb @@ -128,6 +128,9 @@ describe "Residence" do click_button "Verify residence" expect(page).to have_content "The Census was unable to verify your information" + + within("#error_explanation") { click_button "Close" } + expect(page).not_to have_content "The Census was unable to verify your information" end click_button "Verify residence"