From 40d89ee47c254d5b2591312798ff3284786d224c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 10 Mar 2025 16:32:40 +0100 Subject: [PATCH] Add missing expectations before calls to `visit` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There were many cases where we were clicking on a link or (most of the time) a button and then calling the `visit` method. In the past, it worked just fine because clicking on buttons usually results in non-AJAX requests, meaning that the test waited for the request to finish before continuing. That's no longer the case, though. In the last few months/years (not sure since when) we're getting sporadic failures because the test doesn't wait for the request to finish before making another request with the `visit` method. This sometimes results in flaky tests. Some of these tests have recently failed in our CI. Here are a few examples (note the numbers don't follow an order because these tests failed in different jobs): ``` 1) Admin edit translatable records Current locale translation does not exist For ActivePoll Shows first available fallback Failure/Error: expect(page).to have_content "Sondage en Français" expected to find text "Sondage en Français" in "Language: \n \nEnglish\nDeutsch\nEspañol\nFrançais\nNederlands\nPortuguês brasileiro\n中文\n Go back to CONSUL DEMOCRACY\nCONSUL DEMOCRACY\nADMINISTRATION\nMenu\nNotifications\nMy content\nMy account\nSign out\nProposals\nDebates\nComments\nPolls\n Collaborative Legislation\nParticipatory budgets\nVoting booths \nSignature Sheets\nMessages to users\nSite content\nModerated content\nProfiles\nStatistics\nSettings\nProposals dashboard\n× \nPolls description updated successfully.\nList of polls\nPolls description\nCreate poll\nThere are no polls." 2) Public area translatable records Existing records Update a translation With valid data Changes the existing translation Failure/Error: expect(page).to have_field "Debate title", with: "Title in English" expected to find field "Debate title" that is not disabled but there were no matches 2) Admin collaborative legislation Update Edit milestones summary Failure/Error: expect(page).to have_content "There is still a long journey ahead of us" expected to find text "There is still a long journey ahead of us" in "Language: \n \nEnglish\nDeutsch\nEspañol\nFrançais\nNederlands\nPortuguês brasileiro\n中文\n Go back to CONSUL DEMOCRACY\nCONSUL DEMOCRACY\nADMINISTRATION\nMenu\nNotifications\nMy content\nMy account\nSign out\nProposals\nDebates\nComments\nPolls\n Collaborative Legislation\nParticipatory budgets\nVoting booths \nSignature Sheets\nMessages to users\nSite content\nModerated content\nProfiles\nStatistics\nSettings\nProposals dashboard\n× \nProcess updated successfully. Click to visit\nBack\nAn example legislation process\nInformation\nHomepage\nDebate\nProposals\n Drafting\nFollowing\n1 language in use\nCurrent language\n English\nSummary\n Format\n ◢\n Milestone\nManage progress bars\nDon't have defined milestones\nCreate new milestone". (However, it was found 1 time including non-visible text.) 3) Admin collaborative legislation SDG related list create Collaborative Legislation with sdg related list Failure/Error: within("tr", text: "Legislation process with SDG related content") do expect(page).to have_css "td", exact_text: "17" end Capybara::ElementNotFound: Unable to find css "tr" 4) Valuation budget investments Valuate Feasibility can be marked as pending Failure/Error: expect(find("#budget_investment_feasibility_undecided")) .not_to be_checked Capybara::ElementNotFound: Unable to find css "#budget_investment_feasibility_undecided" 3) Custom information texts Show custom texts instead of default ones Failure/Error: within("#section_help") do expect(page).to have_content "Custom help with debates" expect(page).not_to have_content "Help with debates" end 4) Admin budgets Update Deselect all selected staff Failure/Error: expect(page).to have_link "Select administrators" expected to find link "Select administrators" but there were no matches 3) Admin polls SDG related list edit poll with sdg related list Failure/Error: within("tr", text: "Upcoming poll with SDG related content") do expect(page).to have_css "td", exact_text: "17" end Capybara::ElementNotFound: Unable to find css "tr" 4) Admin polls SDG related list create poll with sdg related list Failure/Error: within("tr", text: "Upcoming poll with SDG related content") do expect(page).to have_css "td", exact_text: "17" end Capybara::ElementNotFound: Unable to find css "tr" 5) Admin custom images Image is replaced on admin newsletters Failure/Error: within(".newsletter-body-content") do expect(page).to have_css("img[src*='logo_email_custom.png']") end Capybara::ElementNotFound: Unable to find css ".newsletter-body-content" 6) Admin custom images Image is replaced on front views Failure/Error: within("#map") do expect(page).to have_css("img[src*='custom_map.jpg'][alt='Districts list']") end Capybara::ElementNotFound: Unable to find css "#map" ``` --- spec/support/common_actions/users.rb | 4 +++- spec/system/admin/budgets_spec.rb | 3 +++ .../admin/legislation/processes_spec.rb | 11 ++++++++++ .../admin/legislation/questions_spec.rb | 8 ++++++++ spec/system/admin/poll/polls_spec.rb | 6 ++++++ .../admin/site_customization/images_spec.rb | 4 ++++ spec/system/admin/tags_spec.rb | 2 ++ spec/system/admin/translatable_spec.rb | 20 +++++++++++++++++++ spec/system/dashboard/polls_spec.rb | 3 +++ .../information_texts_spec.rb | 6 ++++++ spec/system/translatable_spec.rb | 2 ++ spec/system/users_auth_spec.rb | 2 ++ spec/system/users_spec.rb | 2 ++ .../valuation/budget_investments_spec.rb | 6 ++++++ 14 files changed, 78 insertions(+), 1 deletion(-) diff --git a/spec/support/common_actions/users.rb b/spec/support/common_actions/users.rb index 01caf46cf..b6dd6a4f2 100644 --- a/spec/support/common_actions/users.rb +++ b/spec/support/common_actions/users.rb @@ -39,8 +39,10 @@ module Users fill_in "user_login", with: user.email fill_in "user_password", with: user.password - click_button "Enter" + + expect(page).to have_content "You have been signed in successfully" + visit new_officing_residence_path end diff --git a/spec/system/admin/budgets_spec.rb b/spec/system/admin/budgets_spec.rb index e150448d7..d3ede52c7 100644 --- a/spec/system/admin/budgets_spec.rb +++ b/spec/system/admin/budgets_spec.rb @@ -435,6 +435,9 @@ describe "Admin budgets", :admin do expect(page).to have_link "Select valuators" click_button "Update Budget" + + expect(page).to have_content "Participatory budget updated successfully" + visit edit_admin_budget_path(budget) expect(page).to have_link "Select administrators" diff --git a/spec/system/admin/legislation/processes_spec.rb b/spec/system/admin/legislation/processes_spec.rb index 5c52b871a..fb7464de1 100644 --- a/spec/system/admin/legislation/processes_spec.rb +++ b/spec/system/admin/legislation/processes_spec.rb @@ -314,6 +314,8 @@ describe "Admin collaborative legislation", :admin do fill_in "Categories", with: "recycling,bicycles,pollution" click_button "Save changes" + expect(page).to have_content "Process updated successfully" + visit admin_legislation_process_proposals_path(process) expect(page).to have_field("Categories", with: "bicycles, pollution, recycling") @@ -322,6 +324,8 @@ describe "Admin collaborative legislation", :admin do fill_in "Summary", with: "Summarizing the process" click_button "Save changes" + expect(page).to have_content "Process updated successfully" + visit admin_legislation_process_proposals_path(process) expect(page).to have_field("Categories", with: "bicycles, pollution, recycling") @@ -337,6 +341,7 @@ describe "Admin collaborative legislation", :admin do click_button "Update Process" + expect(page).to have_content "Process updated successfully." expect(page).to have_current_path admin_legislation_process_milestones_path(process) visit milestones_legislation_process_path(process) @@ -397,6 +402,9 @@ describe "Admin collaborative legislation", :admin do click_sdg_goal(17) click_button "Create process" + + expect(page).to have_content "Process created successfully" + visit admin_legislation_processes_path within("tr", text: "Legislation process with SDG related content") do @@ -411,6 +419,9 @@ describe "Admin collaborative legislation", :admin do remove_sdg_goal_or_target_tag(1) click_button "Save changes" + + expect(page).to have_content "Process updated successfully" + visit admin_legislation_processes_path within("tr", text: "Legislation process with SDG related content") do diff --git a/spec/system/admin/legislation/questions_spec.rb b/spec/system/admin/legislation/questions_spec.rb index d19b42f33..b44de551f 100644 --- a/spec/system/admin/legislation/questions_spec.rb +++ b/spec/system/admin/legislation/questions_spec.rb @@ -131,6 +131,9 @@ describe "Admin legislation questions", :admin do expect(page).to have_field fields_for(:en).last[:id], with: "No" click_button "Save changes" + + expect(page).to have_content "Question updated successfully" + visit edit_question_url expect(page).not_to have_field fields_for(:en).first[:id], with: "Yes" @@ -154,6 +157,9 @@ describe "Admin legislation questions", :admin do find("#nested_question_options input").set("Opción 1") click_button "Save changes" + + expect(page).to have_content "Question updated successfully" + visit edit_question_url expect(page).to have_field(field_en[:id], with: "Option 1") @@ -178,6 +184,8 @@ describe "Admin legislation questions", :admin do click_button "Save changes" + expect(page).to have_content "Question updated successfully" + visit edit_question_url expect(page).to have_field(field_en[:id], with: "Option 1") diff --git a/spec/system/admin/poll/polls_spec.rb b/spec/system/admin/poll/polls_spec.rb index ebb87266b..7a79342c2 100644 --- a/spec/system/admin/poll/polls_spec.rb +++ b/spec/system/admin/poll/polls_spec.rb @@ -545,6 +545,9 @@ describe "Admin polls", :admin do click_sdg_goal(17) click_button "Create poll" + + expect(page).to have_content "Poll created successfully" + visit admin_polls_path within("tr", text: "Upcoming poll with SDG related content") do @@ -559,6 +562,9 @@ describe "Admin polls", :admin do remove_sdg_goal_or_target_tag(1) click_button "Update poll" + + expect(page).to have_content "Poll updated successfully" + visit admin_polls_path within("tr", text: "Upcoming poll with SDG related content") do diff --git a/spec/system/admin/site_customization/images_spec.rb b/spec/system/admin/site_customization/images_spec.rb index 10ceb3149..7f135a41a 100644 --- a/spec/system/admin/site_customization/images_spec.rb +++ b/spec/system/admin/site_customization/images_spec.rb @@ -42,6 +42,8 @@ describe "Admin custom images", :admin do click_button "Update" end + expect(page).to have_content "Image updated successfully" + visit proposals_path within("#map") do @@ -82,6 +84,8 @@ describe "Admin custom images", :admin do click_button "Update" end + expect(page).to have_content "Image updated successfully" + visit admin_newsletter_path(newsletter) within(".newsletter-body-content") do diff --git a/spec/system/admin/tags_spec.rb b/spec/system/admin/tags_spec.rb index 5406757db..3ba35a6e8 100644 --- a/spec/system/admin/tags_spec.rb +++ b/spec/system/admin/tags_spec.rb @@ -24,6 +24,8 @@ describe "Admin tags", :admin do click_button "Create topic" end + within("table") { expect(page).to have_content "important issues" } + visit admin_tags_path expect(page).to have_content "important issues" diff --git a/spec/system/admin/translatable_spec.rb b/spec/system/admin/translatable_spec.rb index f9bc3dcc9..0dd654e9d 100644 --- a/spec/system/admin/translatable_spec.rb +++ b/spec/system/admin/translatable_spec.rb @@ -26,6 +26,8 @@ describe "Admin edit translatable records", :admin do fill_in "Heading name", with: "Nom en Français" click_button "Save heading" + expect(page).to have_content "Heading updated successfully" + visit path expect(page).to have_field "Heading name", with: "Heading name in English" @@ -53,6 +55,8 @@ describe "Admin edit translatable records", :admin do fill_in_ckeditor "Content", with: "Contenu en Français" click_button "Update Custom page" + expect(page).to have_content "Page updated successfully" + visit path expect(page).to have_ckeditor "Content", with: "Content in English" @@ -81,6 +85,8 @@ describe "Admin edit translatable records", :admin do click_link class: "fullscreen-toggle" click_button "Save changes" + expect(page).to have_content "Draft updated successfully" + visit path click_link class: "fullscreen-toggle" @@ -111,6 +117,8 @@ describe "Admin edit translatable records", :admin do fill_in "Question", with: "Português" click_button "Save changes" + expect(page).to have_content "Question updated successfully" + visit path select "Português brasileiro", from: "Language:" @@ -201,6 +209,8 @@ describe "Admin edit translatable records", :admin do click_button "Save card" + expect(page).to have_content "Card updated successfully" + visit path expect(page).to have_field "Title", with: "Title in English" @@ -230,6 +240,8 @@ describe "Admin edit translatable records", :admin do click_button "Save" + expect(page).to have_content "Changes saved" + visit path expect(page).to have_field "Answer", with: "Answer in English" @@ -253,6 +265,8 @@ describe "Admin edit translatable records", :admin do fill_in "Summary", with: "" click_button "Update poll" + expect(page).to have_content "Poll updated successfully" + visit path expect(page).to have_field "Summary", with: "" @@ -345,6 +359,8 @@ describe "Admin edit translatable records", :admin do click_button "Save group" + expect(page).to have_content "Group updated successfully" + visit path expect(page).not_to have_select "Current language", with_options: ["Español"] @@ -443,6 +459,8 @@ describe "Admin edit translatable records", :admin do click_button "Save changes" + expect(page).to have_content "Changes saved" + visit budgets_path click_link "Name en Français" @@ -464,6 +482,8 @@ describe "Admin edit translatable records", :admin do click_link "Remove language" click_button "Save" + expect(page).to have_content "Polls description updated successfully" + visit polls_path expect(page).to have_content "Sondage en Français" diff --git a/spec/system/dashboard/polls_spec.rb b/spec/system/dashboard/polls_spec.rb index 0620cdcf3..cb9ed5821 100644 --- a/spec/system/dashboard/polls_spec.rb +++ b/spec/system/dashboard/polls_spec.rb @@ -161,6 +161,9 @@ describe "Polls" do end click_button "Update poll" + + expect(page).to have_content "Poll updated successfully" + visit edit_proposal_dashboard_poll_path(proposal, poll) expect(page).to have_css ".nested-fields", count: 1 diff --git a/spec/system/site_customization/information_texts_spec.rb b/spec/system/site_customization/information_texts_spec.rb index 016ac6417..0df49f4bc 100644 --- a/spec/system/site_customization/information_texts_spec.rb +++ b/spec/system/site_customization/information_texts_spec.rb @@ -9,10 +9,14 @@ describe "Custom information texts", :admin do fill_in "contents[content_#{debate_key}]values[value_en]", with: "Custom help with debates" click_button "Save" + expect(page).to have_content "Translation updated successfully" + visit admin_site_customization_information_texts_path(tab: "proposals") fill_in "contents[content_#{proposal_key}]values[value_en]", with: "Custom help with proposals" click_button "Save" + expect(page).to have_content "Translation updated successfully" + visit debates_path within("#section_help") do @@ -42,6 +46,8 @@ describe "Custom information texts", :admin do fill_in "contents[content_#{intro_key}]values[value_en]", with: "Custom hi to %{author}" click_button "Save" + expect(page).to have_content "Translation updated successfully" + visit admin_system_email_view_path("budget_investment_created") expect(page).to have_content "Custom hi to Rachel" diff --git a/spec/system/translatable_spec.rb b/spec/system/translatable_spec.rb index 1054808c8..215014625 100644 --- a/spec/system/translatable_spec.rb +++ b/spec/system/translatable_spec.rb @@ -202,6 +202,8 @@ describe "Public area translatable records" do click_button "Save changes" + expect(page).to have_content "Debate updated successfully" + visit path expect(page).to have_field "Debate title", with: "Title in English" diff --git a/spec/system/users_auth_spec.rb b/spec/system/users_auth_spec.rb index 5c7d35953..73f01d259 100644 --- a/spec/system/users_auth_spec.rb +++ b/spec/system/users_auth_spec.rb @@ -232,6 +232,8 @@ describe "Users" do expect(page).to have_current_path(finish_signup_path) click_link "Cancel login" + expect(page).to have_content "You have been signed out successfully" + visit "/" expect_not_to_be_signed_in end diff --git a/spec/system/users_spec.rb b/spec/system/users_spec.rb index c6ddd1d4e..4d9d1e31c 100644 --- a/spec/system/users_spec.rb +++ b/spec/system/users_spec.rb @@ -174,6 +174,8 @@ describe "Users" do uncheck "account_public_activity" click_button "Save changes" + expect(page).to have_content "Changes saved" + visit user_path(user) expect(page).not_to have_content("activity list private") end diff --git a/spec/system/valuation/budget_investments_spec.rb b/spec/system/valuation/budget_investments_spec.rb index 7b0727730..fb3849708 100644 --- a/spec/system/valuation/budget_investments_spec.rb +++ b/spec/system/valuation/budget_investments_spec.rb @@ -308,6 +308,8 @@ describe "Valuation budget investments" do choose "budget_investment_feasibility_feasible" click_button "Save changes" + expect(page).to have_content "Dossier updated" + visit edit_valuation_budget_budget_investment_path(budget, investment) expect(find("#budget_investment_feasibility_undecided")).not_to be_checked @@ -316,6 +318,8 @@ describe "Valuation budget investments" do choose "budget_investment_feasibility_undecided" click_button "Save changes" + expect(page).to have_content "Dossier updated" + visit edit_valuation_budget_budget_investment_path(budget, investment) expect(find("#budget_investment_feasibility_undecided")).to be_checked end @@ -357,6 +361,8 @@ describe "Valuation budget investments" do click_button "Save changes" + expect(page).to have_content "Dossier updated" + visit edit_valuation_budget_budget_investment_path(budget, investment) expect(find("#budget_investment_feasibility_unfeasible")).to be_checked