From 1bfbfdd720685a15f99205c5cf4405b8acce54be Mon Sep 17 00:00:00 2001 From: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com> Date: Sat, 10 Oct 2026 16:38:07 +0800 Subject: [PATCH] test(auth): cover concurrent settings update in UI Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com> --- web/src/pages/admin/system-config.test.tsx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/web/src/pages/admin/system-config.test.tsx b/web/src/pages/admin/system-config.test.tsx index ab3db4c0..bf84dac6 100644 --- a/web/src/pages/admin/system-config.test.tsx +++ b/web/src/pages/admin/system-config.test.tsx @@ -21,6 +21,7 @@ vi.mock('@/api/client', () => ({ })) vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) })) +import { ApiError } from '@/api/client' import { SystemConfigPage } from './system-config' describe('SystemConfigPage', () => { @@ -81,6 +82,21 @@ describe('SystemConfigPage', () => { await waitFor(() => expect(api.updateLocalAuth).toHaveBeenCalledTimes(2)) }) + it('reloads current settings after a concurrent administrator changes them', async () => { + api.getLocalAuth.mockResolvedValueOnce({ passwordLoginEnabled: true, selfRegistrationEnabled: true, version: 3 }) + .mockResolvedValueOnce({ passwordLoginEnabled: true, selfRegistrationEnabled: false, version: 4 }) + api.updateLocalAuth.mockRejectedValue(new ApiError('Version conflict', 409)) + setup() + fireEvent.click(await screen.findByRole('checkbox', { name: 'systemConfig.passwordLogin' })) + fireEvent.click(screen.getByRole('button', { name: 'systemConfig.saveChanges' })) + fireEvent.click(within(await screen.findByRole('dialog')).getByRole('button', { name: 'systemConfig.confirmDisableLogin' })) + await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull()) + expect((await screen.findByRole('alert')).textContent).toBe('systemConfig.changedElsewhere') + expect((screen.getByRole('checkbox', { name: 'systemConfig.passwordLogin' }) as HTMLInputElement).checked).toBe(true) + expect((screen.getByRole('checkbox', { name: 'systemConfig.selfRegistration' }) as HTMLInputElement).checked).toBe(false) + expect(api.updateLocalAuth).toHaveBeenCalledTimes(1) + }) + it('saves a registration change only after Save, without a lockout confirmation', async () => { api.updateLocalAuth.mockResolvedValue({ passwordLoginEnabled: true, selfRegistrationEnabled: false, version: 4 }) setup()