2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-03-04 01:15:08 +08:00
discourse/spec/system/admin_site_setting_bulk_action_spec.rb
Martin Brennan 58a8668d04
UX: Require confirmation for clean_up_inactive_users_after_days setting (#36898)
This is a constant source of pain for admins and our support team, since
the users deleted by this setting are not recoverable. We are making
this require confirmation so that at least admins must be double-aware
of the consequences of enabling this setting.
2025-12-30 15:19:43 +10:00

152 lines
4.7 KiB
Ruby

# frozen_string_literal: true
describe "Admin Site Setting Bulk Action", type: :system do
let(:settings_page) { PageObjects::Pages::AdminSiteSettings.new }
let(:banner) { PageObjects::Components::AdminChangesBanner.new }
let(:dialog) { PageObjects::Components::Dialog.new }
fab!(:admin)
before { sign_in(admin) }
it "saves multiple site settings" do
settings_page.visit
expect(banner).to be_hidden
settings_page.fill_setting("title", "The Shell")
settings_page.fill_setting("site_description", "A cool place")
expect(banner).to be_visible
expect(banner.element).to have_text("You have 2 unsaved changes")
banner.click_save
expect(banner).to be_hidden
expect(settings_page).to have_overridden_setting("title", value: "The Shell")
expect(settings_page).to have_overridden_setting("site_description", value: "A cool place")
end
it "shows a confirmation message for settings that require it" do
settings_page.visit("min_password")
settings_page.fill_setting("min_password_length", 12)
settings_page.fill_setting("min_admin_password_length", 13)
expect(banner).to be_visible
expect(banner.element).to have_text("You have 2 unsaved changes")
banner.click_save
expect(dialog).to be_open
expect(dialog).to have_content(
I18n.t(
"admin_js.admin.site_settings.requires_confirmation_messages.min_password_length.prompt",
),
)
dialog.click_yes
expect(dialog).to be_open
expect(dialog).to have_content(
I18n.t(
"admin_js.admin.site_settings.requires_confirmation_messages.min_admin_password_length.prompt",
),
)
dialog.click_yes
expect(settings_page).to have_overridden_setting("min_password_length", value: 12)
expect(settings_page).to have_overridden_setting("min_admin_password_length", value: 13)
end
it "cancels saving if rejecting a confirmation" do
settings_page.visit("min_password")
settings_page.fill_setting("min_password_length", 12)
settings_page.fill_setting("min_admin_password_length", 13)
expect(banner).to be_visible
expect(banner.element).to have_text("You have 2 unsaved changes")
banner.click_save
expect(dialog).to be_open
expect(dialog).to have_content(
I18n.t(
"admin_js.admin.site_settings.requires_confirmation_messages.min_password_length.prompt",
),
)
dialog.click_yes
expect(dialog).to be_open
expect(dialog).to have_content(
I18n.t(
"admin_js.admin.site_settings.requires_confirmation_messages.min_admin_password_length.prompt",
),
)
dialog.click_no
expect(banner).to be_visible
expect(banner.element).to have_text("You have 2 unsaved changes")
end
it "pops up an error when saving invalid settings" do
settings_page.visit
settings_page.fill_setting("title", "The Shell")
settings_page.fill_setting("contact_email", "Ooops")
expect(banner).to be_visible
expect(banner.element).to have_text("You have 2 unsaved changes")
banner.click_save
expect(dialog).to be_open
expect(dialog).to have_content(
I18n.t("js.generic_error_with_reason", error: "contact_email: Invalid email address."),
)
dialog.click_ok
expect(banner).to be_visible
expect(banner.element).to have_text("You have 2 unsaved changes")
end
it "persists unsaved settings when browsing categories" do
settings_page.visit
settings_page.fill_setting("title", "The Shell")
settings_page.fill_setting("site_description", "A cool place")
expect(banner).to be_visible
expect(banner.element).to have_text("You have 2 unsaved changes")
settings_page.navigate_to_category(:branding)
expect(banner).to be_visible
expect(banner.element).to have_text("You have 2 unsaved changes")
settings_page.navigate_to_category(:required)
expect(banner).to be_visible
expect(banner.element).to have_text("You have 2 unsaved changes")
expect(settings_page).to have_overridden_setting("title", value: "The Shell")
expect(settings_page).to have_overridden_setting("site_description", value: "A cool place")
end
it "prompts about unsaved settings when navigating away" do
settings_page.visit
settings_page.fill_setting("title", "The Shell")
settings_page.fill_setting("site_description", "A cool place")
expect(banner).to be_visible
expect(banner.element).to have_text("You have 2 unsaved changes")
settings_page.find(".admin-sidebar-nav-link", text: "Dashboard").click
expect(settings_page).to have_current_path("/admin/site_settings/category/required")
expect(dialog).to be_open
expect(dialog).to have_content("You have 2 unsaved changes")
dialog.click_no
expect(settings_page).to have_current_path("/admin")
end
end