Files
nairobi/spec/system/admin/budgets_wizard/budgets_spec.rb
Javi Martín f63be041c1 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)
```
2025-03-26 16:27:08 +01:00

139 lines
4.8 KiB
Ruby

require "rails_helper"
describe "Budgets wizard, first step", :admin do
describe "New" do
scenario "Create budget - Knapsack voting (default)" do
visit admin_budgets_path
click_button "Create new budget"
click_link "Create multiple headings budget"
fill_in "Name", with: "M30 - Summer campaign"
fill_in "Text on the link", with: "Participate now!"
fill_in "The link takes you to (add a link)", with: "https://consuldemocracy.org"
fill_in "Name", with: "M30 - Summer campaign"
click_button "Continue to groups"
expect(page).to have_content "New participatory budget created successfully!"
click_link "Go back to edit budget"
expect(page).to have_field "Name", with: "M30 - Summer campaign"
expect(page).to have_select "Final voting style", selected: "Knapsack"
end
scenario "Create budget - Approval voting" do
admin = Administrator.first
visit admin_budgets_path
click_button "Create new budget"
click_link "Create multiple headings budget"
fill_in "Name", with: "M30 - Summer campaign"
select "Approval", from: "Final voting style"
click_button "Continue to groups"
expect(page).to have_content "New participatory budget created successfully!"
click_link "Go back to edit budget"
expect(page).to have_field "Name", with: "M30 - Summer campaign"
expect(page).to have_select "Final voting style", selected: "Approval"
click_link "Select administrators"
expect(page).to have_field admin.name
end
scenario "Submit the form with errors" do
visit new_admin_budgets_wizard_budget_path
click_button "Continue to groups"
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
create(:budget, name: "Existing Name")
visit new_admin_budgets_wizard_budget_path
fill_in "Name", with: "Existing Name"
click_button "Continue to groups"
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
visit new_admin_budgets_wizard_budget_path
expect(page).not_to have_content "Show results and stats"
expect(page).not_to have_field "Show results"
expect(page).not_to have_field "Show stats"
expect(page).not_to have_field "Show advanced stats"
end
end
describe "Create" do
scenario "A new budget is always created in draft mode" do
visit admin_budgets_path
click_button "Create new budget"
click_link "Create multiple headings budget"
fill_in "Name", with: "M30 - Summer campaign"
click_button "Continue to groups"
expect(page).to have_content "New participatory budget created successfully!"
within("#side_menu") { click_link "Participatory budgets" }
within("tr", text: "M30 - Summer campaign") { click_link "Edit" }
expect(page).to have_content "This participatory budget is in draft mode"
expect(page).to have_link "Preview"
expect(page).to have_button "Publish budget"
end
end
describe "Edit" do
scenario "update budget" do
budget = create(:budget, name: "Budget wiht typo")
visit admin_budgets_wizard_budget_groups_path(budget)
click_link "Go back to edit budget"
expect(page).to have_content "Edit Participatory budget"
expect(page).to have_css ".creation-timeline"
expect(page).to have_field "Name", with: "Budget wiht typo"
fill_in "Name", with: "Budget without typos"
click_button "Continue to groups"
expect(page).to have_content "Participatory budget updated successfully"
expect(page).to have_content "Budget without typos"
expect(page).to have_css ".creation-timeline"
expect(page).to have_content "There are no groups"
end
scenario "submit the form with errors and then without errors" do
budget = create(:budget, name: "Budget wiht typo")
visit edit_admin_budgets_wizard_budget_path(budget)
fill_in "Name", with: ""
click_button "Continue to groups"
expect(page).to have_css "#error_explanation"
fill_in "Name", with: "Budget without typos"
click_button "Continue to groups"
expect(page).to have_content "Participatory budget updated successfully"
expect(page).to have_content "Budget without typos"
expect(page).to have_css ".creation-timeline"
expect(page).to have_content "There are no groups"
end
end
end