test(10-05): bring every SPA module, composable and component under Vitest
- 41 unit and component suites under admin/tests/{app,state,shell,list,form,relation,views,ui}
covering states and a11y roles; every src module is imported by a test
- typed fixture helper assigns each JSON fixture to its generated OpenAPI type
- fix: iconFor ignores inherited object members such as "constructor"
- fix: field controls import ./control instead of the registry (import cycle
left a renderer unregistered depending on module load order)
- fix: dropdown shows the placeholder for an unknown stored value next to an emptyOption
- fix: list announces a failed schema load even when the rows arrive after it
- tailwind no longer scans admin/tests; boardwalk/dist rebuilt
This commit is contained in:
54
admin/tests/state/useToasts.test.ts
Normal file
54
admin/tests/state/useToasts.test.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { clearToasts, dismissToast, showToast, TOAST_TIMEOUT, toasts, useToasts } from '../../src/state/useToasts'
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
clearToasts()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
clearToasts()
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
describe('toast queue', () => {
|
||||
it('queues newest first with success as the default tone', () => {
|
||||
const first = showToast('Saved')
|
||||
const second = showToast('Failed', 'danger')
|
||||
expect(second).toBeGreaterThan(first)
|
||||
expect(toasts.value.map((item) => [item.text, item.tone])).toEqual([
|
||||
['Failed', 'danger'],
|
||||
['Saved', 'success'],
|
||||
])
|
||||
})
|
||||
|
||||
it('dismisses each toast after about 4 seconds', () => {
|
||||
expect(TOAST_TIMEOUT).toBe(4000)
|
||||
showToast('one')
|
||||
vi.advanceTimersByTime(1000)
|
||||
showToast('two')
|
||||
vi.advanceTimersByTime(TOAST_TIMEOUT - 1000)
|
||||
expect(toasts.value.map((item) => item.text)).toEqual(['two'])
|
||||
vi.advanceTimersByTime(1000)
|
||||
expect(toasts.value).toEqual([])
|
||||
})
|
||||
|
||||
it('dismisses on request and cancels that toast timer', () => {
|
||||
const id = showToast('bye')
|
||||
const other = showToast('stay')
|
||||
dismissToast(id)
|
||||
expect(toasts.value.map((item) => item.id)).toEqual([other])
|
||||
dismissToast(id)
|
||||
dismissToast(999_999)
|
||||
expect(vi.getTimerCount()).toBe(1)
|
||||
})
|
||||
|
||||
it('clears every toast and timer', () => {
|
||||
showToast('a')
|
||||
showToast('b')
|
||||
clearToasts()
|
||||
expect(toasts.value).toEqual([])
|
||||
expect(vi.getTimerCount()).toBe(0)
|
||||
expect(useToasts().showToast).toBe(showToast)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user