Files
grecia/spec/system/admin/feature_flags_spec.rb
Javi Martín fabe97e506 Use a switch control to enable/disable features
We were using buttons with the "Enable" and "Disable" texts to
enable/disable settings. However, when machine learning settings were
introduced in commit 4d27bbeba, a switch control was introduced to
enable/disable them.

In order to keep the interface consistent, we're now using switch
controls in other sections where settings are enabled/disabled. We can
even use the same code in the machine learning settings as well.

We're also removing the confirmation dialog to enable/disable a setting,
since the dialog is really annoying when changing several settings and
this action can be undone immediately. The only setting which might need
a confirmation is the "Skip user verification" one; we might add it in
the future. Removing the confirmation here doesn't make things worse,
though; the "Are you sure?" confirmation dialog was also pretty useless
and users would most likely blindly accept it.

Note Capybara doesn't support finding a button by its `aria-labelledby`
atrribute. Ideally we'd write `click_button "Participatory budgeting"`
instead of `click_button "Yes"`, since from the user's point of view the
"Yes" or "No" texts aren't button labels but indicators of the status of
the setting. This makes the code a little brittle since tests would pass
even if the element referenced by `aria-labelledby` didn't exist.
2021-09-23 13:25:20 +02:00

89 lines
2.2 KiB
Ruby

require "rails_helper"
describe "Admin feature flags", :admin do
before do
Setting["process.budgets"] = true
end
scenario "Enabled features are listed on menu" do
visit admin_root_path
within("#side_menu") do
expect(page).to have_link "Participatory budgets"
expect(page).to have_link "Debates"
end
end
scenario "Disable a participatory process", :show_exceptions do
budget = create(:budget)
visit admin_settings_path
within("#settings-tabs") { click_link "Participation processes" }
within("tr", text: "Participatory budgeting") { click_button "Yes" }
expect(page).to have_content "Value updated"
within("#side_menu") do
expect(page).not_to have_link "Participatory budgets"
end
visit budget_path(budget)
expect(page).to have_title "Forbidden"
visit admin_budgets_path
expect(page).to have_current_path admin_budgets_path
expect(page).to have_title "Forbidden"
end
scenario "Enable a disabled participatory process" do
Setting["process.budgets"] = nil
visit admin_root_path
within("#side_menu") do
expect(page).not_to have_link "Participatory budgets"
end
visit admin_settings_path
within("#settings-tabs") { click_link "Participation processes" }
within("tr", text: "Participatory budgeting") { click_button "No" }
expect(page).to have_content "Value updated"
within("#side_menu") do
expect(page).to have_link "Participatory budgets"
end
end
scenario "Disable a feature" do
visit admin_settings_path
click_link "Features"
within("tr", text: "Twitter login") { click_button "Yes" }
expect(page).to have_content "Value updated"
within("tr", text: "Twitter login") do
expect(page).to have_button "No"
expect(page).not_to have_button "Yes"
end
end
scenario "Enable a disabled feature" do
visit admin_settings_path
click_link "Features"
within("tr", text: "Proposals and budget investments geolocation") { click_button "No" }
expect(page).to have_content "Value updated"
within("tr", text: "Proposals and budget investments geolocation") do
expect(page).to have_button "Yes"
expect(page).not_to have_button "No"
end
end
end