test(admin): list state round trip and storage coverage

- Form back, cancel, save-and-close and delete land on the list with the stored query; every list request after the return carries it
- listState helpers: key prefix, malformed stored values removed, empty query stores nothing, throwing storage
- ListView entry: URL wins, cleared controls forget the query, same-list navigation, 422 forgets, page clamp
- Logout removes every list key and keeps the sidebar preference
This commit is contained in:
2026-10-09 22:42:36 +02:00
parent 3b8527b397
commit a8bce9c01f
4 changed files with 404 additions and 0 deletions

View File

@@ -9,7 +9,9 @@ import {
setCurrentUser,
useAuth,
} from '../../src/state/useAuth'
import { writeListState } from '../../src/state/listState'
import { navigation, setNavigation } from '../../src/state/useNavigation'
import { SIDEBAR_KEY } from '../../src/state/useSidebar'
import { setSettings, settings } from '../../src/state/useSettings'
import { navigationFixture, settingsFixture } from '../fixtures/typed'
import { API, mockApi, profile, requestsTo, resetState } from '../helpers'
@@ -129,6 +131,24 @@ describe('logout (T-10-23)', () => {
}
})
it.each([
['succeeds', { body: { data: { status: 'logged_out' }, meta: {} } }],
['answers 500', { status: 500, body: { error: { code: 'server', message: 'x', details: {} } } }],
['fails on the network', 'throw' as const],
])('removes every stored list query and keeps the sidebar preference when the call %s', async (_label, route) => {
await signedIn(route)
window.localStorage.setItem(SIDEBAR_KEY, 'true')
writeListState('acme.demo.widgets', { search: 'blue', sort: 'code', dir: 'desc' })
writeListState('acme.demo.gadgets', { filter: { active: 'true' } })
expect(Object.keys(window.localStorage).filter((key) => key.startsWith('summer-admin.list:'))).toHaveLength(2)
await logout({ replace: vi.fn().mockResolvedValue(undefined) })
expect(Object.keys(window.localStorage).filter((key) => key.startsWith('summer-admin.list:'))).toEqual([])
expect(Object.keys(window.localStorage)).toEqual([SIDEBAR_KEY])
expect(window.localStorage.getItem(SIDEBAR_KEY)).toBe('true')
})
it('works without a router and swallows a failed navigation', async () => {
await signedIn({ body: { data: { status: 'logged_out' }, meta: {} } })
await expect(logout()).resolves.toBeUndefined()