openpencil/packages/scene-graph/tests/undo/batch.test.ts
Danila Poyarkov 7b9f506f4a
test: migrate Scene Graph tests into the package and gate new tests/engine files (#790)
Scene Graph unit tests move to packages/scene-graph/tests with a package-local assert helper and test type-checking; five Core- and fig-owned tests move to their owners' engine homes. check:test-homes rejects any new test under tests/engine against a reviewed baseline so the migration debt only shrinks.
2026-09-30 04:53:28 +04:00

39 lines
976 B
TypeScript

import { expect, test } from 'bun:test'
import { UndoManager } from '@open-pencil/scene-graph'
test('discarding nested batches preserves committed undo/redo without replay or notifications', () => {
let changes = 0
let replayed = 0
const undo = new UndoManager({
onChange: () => {
changes++
}
})
const noop = () => undefined
undo.push({ label: 'First', forward: noop, inverse: noop })
undo.push({ label: 'Second', forward: noop, inverse: noop })
undo.undo()
const pending = {
label: 'Pending',
forward: () => {
replayed++
},
inverse: () => {
replayed++
}
}
undo.beginBatch('Outer')
undo.push(pending)
undo.beginBatch('Inner')
undo.push(pending)
undo.discardBatches()
expect(undo.isBatching).toBe(false)
expect(replayed).toBe(0)
expect(changes).toBe(3)
expect(undo.undoLabel).toBe('First')
expect(undo.redoLabel).toBe('Second')
undo.commitBatch()
expect(undo.redo()).toBe('Second')
})