openpencil/packages/core/tests/editor/view-state.test.ts
Danila Poyarkov 87bff8620c
test(core): move the editor suite into the package (#792)
The 54 editor engine tests move to packages/core/tests/editor with their helpers, importing Core's public subpaths or source modules relatively. The package gains test and typecheck scripts; the first type check fixed nullable lookups, stale imports, and renderer doubles, and graph events now declare the GraphEventRenderer surface they invalidate. The engine baseline drops to 534 files.
2026-09-30 10:22:42 +04:00

38 lines
1.2 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import {
copyEditorViewState,
createDefaultEditorState,
createDefaultEditorViewState,
pickEditorViewState
} from '@open-pencil/core/editor'
describe('editor state ownership', () => {
test('composes editor state from shared and view defaults', () => {
const state = createDefaultEditorState('page')
const view = createDefaultEditorViewState('page')
expect(pickEditorViewState(state)).toEqual(view)
expect(state.activeTool).toBe('SELECT')
expect(state.documentName).toBe('Untitled')
})
test('copies mutable view state for an independent canvas surface', () => {
const state = createDefaultEditorState('page')
state.selectedIds = new Set(['selected'])
state.snapGuides = [{ axis: 'x', position: 10, from: 0, to: 20 }]
const source = pickEditorViewState(state)
const copy = copyEditorViewState(source)
copy.selectedIds.add('pane-only')
copy.snapGuides.length = 0
copy.pageColor.r = 0.5
copy.navigation.phase = 'zoom'
expect(source.selectedIds).toEqual(new Set(['selected']))
expect(source.snapGuides).toHaveLength(1)
expect(source.pageColor.r).not.toBe(0.5)
expect(source.navigation.phase).toBe('idle')
})
})