openpencil/tests/engine/vue/controls/node-preview.test.ts
Danila Poyarkov c59879105c fix(editor): close preview and history lifecycle gaps
Discard provisional undo batches on graph replacement without replaying old document edits or clearing committed history. Reset failed preview controllers and refresh selected projections for plain-state SDK consumers while pausing inactive subscriptions.

Cover the verified review findings with negative controls, fix static Vue host insertion, and preserve the shared exact renderer oracle with its independently verified sRGB selection color.
2026-09-16 03:36:44 +03:00

39 lines
1.4 KiB
TypeScript

import { expect, test } from 'bun:test'
import { createEditor } from '@open-pencil/core/editor'
import { useNodePreview } from '#vue/controls/node-preview/use'
for (const operation of ['update', 'commit'] as const) {
test(`a failed preview ${operation} releases targets for the next interaction`, () => {
const editor = createEditor()
const control = useNodePreview(editor)
try {
const node = editor.graph.createNode('COMPONENT', editor.state.currentPageId, { x: 10 })
const next = editor.graph.createNode('RECTANGLE', editor.state.currentPageId, { x: 20 })
if (operation === 'commit') control.update([node.id], { x: 50 }, 'Move')
editor.graph.updateNode(node.id, {
librarySource: {
identity: { libraryId: 'preview-test', assetKey: 'component', revisionId: 'r1' },
sourceNodeId: 'source',
readOnly: true
}
})
expect(() => {
if (operation === 'commit') control.commit()
else control.update([node.id], { x: 50 }, 'Move')
}).toThrow('Edit the source library')
expect(editor.isInteractiveEditing()).toBe(false)
control.update([next.id], { x: 90 }, 'Move')
expect(editor.graph.getNode(next.id)?.x).toBe(90)
control.commit()
expect(next.x).toBe(90)
editor.undoAction()
expect(next.x).toBe(20)
} finally {
control.cancel()
editor.dispose()
}
})
}