openpencil/tests/app/editor/session/page-switch.test.ts
Danila Poyarkov 4895e55c22
fix(app): end a page switch quietly when another one takes over (#845)
Switching pages again before the previous page finished preparing
aborted the first switch, which rejected with an AbortError. Callers
start page switches without awaiting them, so the rejection surfaced as
an error toast.
2026-10-03 20:18:15 +04:00

23 lines
803 B
TypeScript

import 'fake-indexeddb/auto'
import { expect, test } from 'bun:test'
import { createEditorStore } from '@/app/editor/session/create'
test('a page switch overtaken by another resolves instead of rejecting', async () => {
const store = createEditorStore()
// Stand in for the canvas, which acknowledges each scene it presents.
store.onPreparationEvent('preparation:updated', (preparation) => {
if (preparation.phase === 'preparing-render')
store.preparationController.acknowledgePresentation(store.state.sceneVersion)
})
const b = store.graph.addPage('B').id
const c = store.graph.addPage('C').id
const first = store.switchPage(b)
const second = store.switchPage(c)
await expect(first).resolves.toBeUndefined()
await second
expect(store.state.currentPageId).toBe(c)
})