From df716c3de62aee0db5aa290d2dc380ac7ee1bdad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 25 Oct 2024 20:56:24 +0200 Subject: [PATCH] Add missing expectations in users tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One of these tests has failed in our CI with the following message: ``` 1) Users Public activity user can hide public page Failure/Error: expect(page).to have_content("activity list private") expected to find text "activity list private" in "Language: \n \nEnglish\nDeutsch\nEspañol\nFrançais\nNederlands\nPortuguês brasileiro\n中文\n Notifications\nYou are in\nMy content\nMy account\nSign out\nDebates\nProposals\nVoting\nCollaborative legislation\nParticipatory budgeting\nSDG\nHelp\nM\nManuela124\nUser has no public activity\nOpen government\nThis portal uses the CONSUL DEMOCRACY application which is open-source software.\nParticipation\nDecide how to shape the city you want to live in.\nCONSUL DEMOCRACY, 2024 Privacy Policy Terms and conditions of use Accessibility" ``` Note how the text "User has no public activity" is present, which is a message that appears when the user's activity is public. A possible explanation is that we didn't check that the request done by the "Save changes" button had finished before continuing with the tests. Back when we wrote this test, submitting a form in a test would always wait for the request to be finished before continuing, but a lot has changed since then. So we're adding an expectation to make sure the the changes have been saved before making a new request. We're also rearraging the blank lines in these tests and removing the parenthesis in `have_content` expectations to be consistent with the expectations we're adding. --- spec/system/users_spec.rb | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/spec/system/users_spec.rb b/spec/system/users_spec.rb index 6e35977b9..34e3c19c4 100644 --- a/spec/system/users_spec.rb +++ b/spec/system/users_spec.rb @@ -159,10 +159,12 @@ describe "Users" do uncheck "account_public_activity" click_button "Save changes" - logout + expect(page).to have_content "Changes saved" + logout visit user_path(user) - expect(page).to have_content("activity list private") + + expect(page).to have_content "activity list private" end scenario "is always visible for the owner" do @@ -183,11 +185,13 @@ describe "Users" do uncheck "account_public_activity" click_button "Save changes" - logout + expect(page).to have_content "Changes saved" + logout login_as(create(:administrator).user) visit user_path(user) - expect(page).not_to have_content("activity list private") + + expect(page).not_to have_content "activity list private" end scenario "is always visible for moderators" do @@ -197,11 +201,13 @@ describe "Users" do uncheck "account_public_activity" click_button "Save changes" - logout + expect(page).to have_content "Changes saved" + logout login_as(create(:moderator).user) visit user_path(user) - expect(page).not_to have_content("activity list private") + + expect(page).not_to have_content "activity list private" end describe "User email" do @@ -461,8 +467,9 @@ describe "Users" do check "account_public_interests" click_button "Save changes" - logout + expect(page).to have_content "Changes saved" + logout visit user_path(user, filter: "follows") expect(page).to have_css "#public_interests" @@ -479,10 +486,12 @@ describe "Users" do check "account_public_interests" click_button "Save changes" - logout + expect(page).to have_content "Changes saved" + logout visit user_path(user) - expect(page).not_to have_content("Sport") + + expect(page).not_to have_content "Sport" end end end