Files
nairobi/spec/system/admin/feature_flags_spec.rb
Javi Martín ead5eac67f Update settings using an AJAX requests
Having to wait for a whole page refresh after updating each setting was
painful when modifying several settings.

Even though the navigation is updated immediately to reflect which
sections have been enabled/disabled, there's one gotcha. Changing the
"SDG" setting will not update the user menu (which contains a link to
SDG content) nor the "SDG Configuration" tab; refreshing the page will
be necessary to check these changes. The same happens with the map and
remote census tabs. So in these cases we're making an exception and
sending the form. We might find a better solution in the future.

For this reason, we aren't using the `switch` ARIA role. Some users
might not expect a switch control to refresh the page, just like they
usually don't expect checkboxes to refresh the page. Furthermore, screen
reader support for the `switch` role seems to be inconsistent. For
instance, NVDA with Chrome announces the control as a checkbox instead
of a switch.

Note AJAX is only used for feature settings. Other settings are still
updated with regular HTTP requests.

Since we're now using AJAX requests, we have to make sure to add an
expectation in the homepage tests in order to make sure the request has
finished before starting a new one.
2021-09-23 13:25:22 +02:00

90 lines
2.0 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") do
click_button "Yes"
expect(page).to have_button "No"
end
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") do
click_button "No"
expect(page).to have_button "Yes"
end
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") do
click_button "Yes"
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") do
click_button "No"
expect(page).to have_button "Yes"
expect(page).not_to have_button "No"
end
end
end