test(settings): wait for async config before asserting Save payload
The Proxmox/Zigbee auto-sync Save tests clicked Save after only waiting for an unrelated field, so under CI load getConfig could resolve after the click and Save fired with the default sync_enabled=false. Wait for the toggle to reflect the loaded state first.
This commit is contained in:
@@ -131,6 +131,9 @@ describe('SettingsModal', () => {
|
|||||||
vi.mocked(proxmoxApi.saveConfig).mockResolvedValue({ data: {} } as never)
|
vi.mocked(proxmoxApi.saveConfig).mockResolvedValue({ data: {} } as never)
|
||||||
render(<SettingsModal open onClose={vi.fn()} />)
|
render(<SettingsModal open onClose={vi.fn()} />)
|
||||||
await screen.findByDisplayValue('60')
|
await screen.findByDisplayValue('60')
|
||||||
|
// Wait for the async proxmox getConfig to hydrate the toggle before saving —
|
||||||
|
// otherwise Save can fire with the default sync_enabled=false under CI load.
|
||||||
|
await waitFor(() => expect(screen.getByLabelText('Toggle Proxmox auto-sync')).toBeChecked())
|
||||||
fireEvent.click(screen.getByRole('button', { name: 'Save' }))
|
fireEvent.click(screen.getByRole('button', { name: 'Save' }))
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(proxmoxApi.saveConfig).toHaveBeenCalledWith({ sync_enabled: true, sync_interval: 3600 })
|
expect(proxmoxApi.saveConfig).toHaveBeenCalledWith({ sync_enabled: true, sync_interval: 3600 })
|
||||||
@@ -174,6 +177,9 @@ describe('SettingsModal', () => {
|
|||||||
render(<SettingsModal open onClose={vi.fn()} />)
|
render(<SettingsModal open onClose={vi.fn()} />)
|
||||||
await screen.findByDisplayValue('60')
|
await screen.findByDisplayValue('60')
|
||||||
await screen.findByText('Zigbee auto-sync')
|
await screen.findByText('Zigbee auto-sync')
|
||||||
|
// Wait for the async zigbee getConfig to hydrate the toggle before saving —
|
||||||
|
// otherwise Save can fire with the default sync_enabled=false under CI load.
|
||||||
|
await waitFor(() => expect(screen.getByLabelText('Toggle Zigbee auto-sync')).toBeChecked())
|
||||||
fireEvent.click(screen.getByRole('button', { name: 'Save' }))
|
fireEvent.click(screen.getByRole('button', { name: 'Save' }))
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(zigbeeApi.saveConfig).toHaveBeenCalledWith({ sync_enabled: true, sync_interval: 1800 })
|
expect(zigbeeApi.saveConfig).toHaveBeenCalledWith({ sync_enabled: true, sync_interval: 1800 })
|
||||||
|
|||||||
Reference in New Issue
Block a user