0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-08 16:57:36 +08:00
discourse/spec/system/admin_site_setting_requires_confirmation_spec.rb
Régis Hanol ce98cf12e2
DEV: Render bool and integer site settings with FormKit (#41809)
Previously, the admin site settings page rendered every setting with
bespoke per-type controls layered on a buffered proxy, separate from the
shared FormKit field infrastructure (`SettingDefinitionField` and the
setting-field registry) that category-type and plugin settings already
use.

This change renders `bool` and `integer` settings through that shared
infrastructure — gated per-type by an `adminReady` registry flag so the
remaining types keep their current controls until they are converted in
turn — by wrapping each row's control in a single-field `<Form>` whose
`@onSet` writes back into the existing buffered proxy, so dirty
tracking, the changes banner, and the route guard keep working
unchanged. It also fixes two latent issues it surfaced: pressing Enter
now submits through the row's full save path (including the confirmation
dialog) instead of bypassing it, and `FKControlInput` no longer keeps a
stale raw-text buffer that stopped Cancel and Reset from reverting a
number field.
2026-08-06 09:19:57 +02:00

86 lines
3 KiB
Ruby
Vendored

# frozen_string_literal: true
describe "Admin Site Setting Requires Confirmation" do
let(:settings_page) { PageObjects::Pages::AdminSiteSettings.new }
let(:dialog) { PageObjects::Components::Dialog.new }
fab!(:admin)
before do
SiteSetting.min_password_length = 10
sign_in(admin)
end
it "requires confirmation and shows the correct message" do
settings_page.visit("min_password_length")
settings_page.change_number_setting("min_password_length", 12)
expect(dialog).to be_open
expect(dialog).to have_content(
I18n.t(
"admin_js.admin.site_settings.requires_confirmation_messages.min_password_length.prompt",
),
)
expect(dialog).to have_content(
I18n.t(
"admin_js.admin.site_settings.requires_confirmation_messages.min_password_length.confirm",
),
)
dialog.click_yes
expect(dialog).to be_closed
expect(settings_page).to have_overridden_setting("min_password_length", value: 12)
end
it "shows the confirmation when submitting the change with the Enter key" do
settings_page.visit("min_password_length")
settings_page.submit_setting_with_keyboard("min_password_length", 12)
expect(dialog).to be_open
end
it "does not save the new setting value if the admin cancels confirmation" do
settings_page.visit("min_password_length")
settings_page.change_number_setting("min_password_length", 12)
expect(dialog).to be_open
dialog.click_no
expect(dialog).to be_closed
expect(settings_page).to have_no_overridden_setting("min_password_length")
end
context "with simple_on_enable confirmation type" do
it "shows confirmation when enabling the setting" do
settings_page.visit("can_permanently_delete")
settings_page.toggle_bool_setting("can_permanently_delete")
expect(dialog).to be_open
expect(dialog).to have_content(
I18n.t(
"admin_js.admin.site_settings.requires_confirmation_messages.can_permanently_delete.prompt",
),
)
end
it "does not show confirmation when disabling the setting" do
SiteSetting.can_permanently_delete = true
settings_page.visit("can_permanently_delete")
settings_page.toggle_bool_setting("can_permanently_delete")
expect(dialog).to be_closed
end
end
context "with simple_on_disable confirmation type" do
it "shows confirmation when disabling the setting but not when enabling it" do
settings_page.visit("content_security_policy")
settings_page.toggle_bool_setting("content_security_policy")
expect(dialog).to be_open
expect(dialog).to have_content(
I18n.t(
"admin_js.admin.site_settings.requires_confirmation_messages.content_security_policy.prompt",
),
)
dialog.click_yes
expect(dialog).to be_closed
expect(settings_page).to have_overridden_setting("content_security_policy")
settings_page.toggle_bool_setting("content_security_policy")
expect(dialog).to be_closed
expect(settings_page).to have_no_overridden_setting("content_security_policy")
end
end
end