* build: typecheck the test suites Tests were in no TypeScript program: no tsconfig included tests/** or packages/*/tests/**, and bun strips types without checking them, so a fixture could drop a required field and keep passing until something read it. @types/bun moves to the root because it was installed per package only, and #cli-tests/* joins the paths the root config already carries. * test: fix the type errors the test suites were hiding Typechecking the tests turned up 1123 errors. Most were ordinary strictness, but some were real: `NodeChange` bound to Figma's plugin typings rather than the Kiwi codec in thirteen .fig tests, materializeInstance was called with six arguments against five so the blobs and source children were dropped, CanvasKit pixels were written to a plain object that never reached WASM, and assertions were made through accessors that do not exist, so they asserted nothing. Fixtures that had quietly lost a required field now carry it, nullable results are narrowed through the existing expectDefined helper rather than assumed, and stand-ins for CanvasKit and the editor go through one named helper instead of an unexplained cast at each site. No test was deleted, skipped, or weakened, and no `any`, non-null assertion, or ts-expect-error was introduced. * docs: record what typechecking the tests established Pins the app program's global types with an assertion rather than a note, since an unpinned types list lets any root @types package decide which platform src/** is judged against. The two environment faults that look like code regressions — Vite's dependency pre-bundle outliving a package rebuild, and heavy .fig suites failing under load — go to the development docs, where an explanation belongs. * fix: align @types/bun and keep node types resolvable when extended The root manifest declared a newer @types/bun than every package, which check:monorepo rejects, and pinning the app program's types left them unresolvable from a config that extends this one out of tree. * fix: fail the test typecheck when the compiler itself fails The gate matched diagnostics by substring, so a compiler or config failure that named no test file printed a pass while having checked nothing. Diagnostics are now split by whether they name a file: an unscoped one is the run failing and stops the gate, a test file's is a finding, and a source file's stays out by design. Also drops the parameter planComponentConstruction never read, and makes the inner-shadow verification script exit non-zero when it renders no image instead of logging and succeeding. * chore: merge master into tests-typecheck
198 lines
6.8 KiB
TypeScript
198 lines
6.8 KiB
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
|
|
import { computed, ref } from 'vue'
|
|
|
|
import { createEditor } from '@open-pencil/core/editor'
|
|
import type { SceneNode } from '@open-pencil/scene-graph'
|
|
import { MIXED, type MixedValue } from '@open-pencil/vue'
|
|
|
|
import { createAppearanceActions, createAppearanceState } from '#vue/controls/appearance/helpers'
|
|
|
|
import { createRect, firstPageId, makeSceneGraph } from '#tests/helpers/scene'
|
|
|
|
function appearanceState(node: SceneNode, multi = false) {
|
|
const selected = ref<SceneNode | null>(node)
|
|
const nodes = ref<SceneNode[]>([node])
|
|
const isMulti = ref(multi)
|
|
|
|
function merged<K extends keyof SceneNode>(key: K): MixedValue<SceneNode[K]> {
|
|
const current = selected.value
|
|
if (!current) throw new Error('Expected selected node')
|
|
return current[key]
|
|
}
|
|
|
|
return createAppearanceState({
|
|
node: computed(() => selected.value),
|
|
nodes: computed(() => nodes.value),
|
|
isMulti: computed(() => isMulti.value),
|
|
merged
|
|
})
|
|
}
|
|
|
|
function rectangle() {
|
|
const graph = makeSceneGraph()
|
|
return createRect(graph, firstPageId(graph))
|
|
}
|
|
|
|
describe('appearance control state', () => {
|
|
test('keeps equal uniform corners collapsed', () => {
|
|
const state = appearanceState(rectangle())
|
|
expect(state.showIndependentCorners.value).toBe(false)
|
|
})
|
|
|
|
test('expands corners when the explicit independent flag is set', () => {
|
|
const node = rectangle()
|
|
node.independentCorners = true
|
|
const state = appearanceState(node)
|
|
expect(state.showIndependentCorners.value).toBe(true)
|
|
})
|
|
|
|
test('collapses equal independent corners when they share one binding', () => {
|
|
const node = rectangle()
|
|
node.independentCorners = true
|
|
node.boundVariables = {
|
|
topLeftRadius: 'radius',
|
|
topRightRadius: 'radius',
|
|
bottomRightRadius: 'radius',
|
|
bottomLeftRadius: 'radius'
|
|
}
|
|
expect(appearanceState(node).showIndependentCorners.value).toBe(false)
|
|
})
|
|
|
|
test('collapsed bound corners display their actual shared radius', () => {
|
|
const node = rectangle()
|
|
node.independentCorners = true
|
|
node.cornerRadius = 0
|
|
node.topLeftRadius = node.topRightRadius = node.bottomLeftRadius = node.bottomRightRadius = 12
|
|
node.boundVariables = {
|
|
topLeftRadius: 'radius',
|
|
topRightRadius: 'radius',
|
|
bottomLeftRadius: 'radius',
|
|
bottomRightRadius: 'radius'
|
|
}
|
|
const state = appearanceState(node)
|
|
expect(state.cornerRadiusValue.value).toBe(12)
|
|
expect(state.cornerRadiusBindingPaths.value).toEqual([
|
|
'topLeftRadius',
|
|
'topRightRadius',
|
|
'bottomRightRadius',
|
|
'bottomLeftRadius'
|
|
])
|
|
})
|
|
|
|
test('collapsed bound corners can be expanded without detaching their bindings', () => {
|
|
const graph = makeSceneGraph()
|
|
const rect = graph.createNode('RECTANGLE', firstPageId(graph), {
|
|
independentCorners: true,
|
|
boundVariables: {
|
|
topLeftRadius: 'radius',
|
|
topRightRadius: 'radius',
|
|
bottomLeftRadius: 'radius',
|
|
bottomRightRadius: 'radius'
|
|
}
|
|
})
|
|
const editor = createEditor({ graph })
|
|
const options = {
|
|
expandedCornerNodeId: ref<string | null>(null),
|
|
editor,
|
|
node: computed(() => graph.getNode(rect.id) ?? null),
|
|
nodes: computed(() => []),
|
|
isMulti: computed(() => false),
|
|
merged: <K extends keyof SceneNode>(): MixedValue<SceneNode[K]> => MIXED
|
|
}
|
|
const actions = createAppearanceActions(options)
|
|
actions.toggleIndependentCorners()
|
|
expect(createAppearanceState(options).showIndependentCorners.value).toBe(true)
|
|
expect(graph.getNode(rect.id)?.boundVariables.topLeftRadius).toBe('radius')
|
|
expect(editor.undo.canUndo).toBe(false)
|
|
actions.toggleIndependentCorners()
|
|
expect(createAppearanceState(options).showIndependentCorners.value).toBe(false)
|
|
})
|
|
|
|
test('keeps equal independent corners expanded for distinct bindings', () => {
|
|
const node = rectangle()
|
|
node.independentCorners = true
|
|
node.boundVariables = {
|
|
topLeftRadius: 'radius-a',
|
|
topRightRadius: 'radius-b',
|
|
bottomRightRadius: 'radius-a',
|
|
bottomLeftRadius: 'radius-a'
|
|
}
|
|
expect(appearanceState(node).showIndependentCorners.value).toBe(true)
|
|
})
|
|
|
|
test('expands imported unequal corners when the explicit flag is stale', () => {
|
|
const node = rectangle()
|
|
node.independentCorners = false
|
|
node.topLeftRadius = 4
|
|
node.topRightRadius = 12
|
|
const state = appearanceState(node)
|
|
expect(state.showIndependentCorners.value).toBe(true)
|
|
})
|
|
|
|
test('leaves the per-corner editor collapsed for multi-selection', () => {
|
|
const node = rectangle()
|
|
node.independentCorners = true
|
|
const state = appearanceState(node, true)
|
|
expect(state.showIndependentCorners.value).toBe(false)
|
|
})
|
|
|
|
test('presents normalized corner smoothing as a percentage', () => {
|
|
const node = rectangle()
|
|
node.cornerSmoothing = 0.735
|
|
const state = appearanceState(node)
|
|
expect(state.cornerSmoothingPercent.value).toBe(74)
|
|
})
|
|
|
|
test('keeps independent corner preview and undo behavior', () => {
|
|
const graph = makeSceneGraph()
|
|
const pageId = firstPageId(graph)
|
|
const rect = graph.createNode('RECTANGLE', pageId, {
|
|
independentCorners: true,
|
|
topLeftRadius: 8
|
|
})
|
|
const editor = createEditor({ graph })
|
|
const actions = createAppearanceActions({
|
|
editor,
|
|
node: computed(() => graph.getNode(rect.id) ?? null),
|
|
nodes: computed(() => []),
|
|
isMulti: computed(() => false),
|
|
merged: (key) => graph.getNode(rect.id)?.[key] ?? MIXED
|
|
})
|
|
|
|
actions.updateCornerProp('topLeftRadius', 20)
|
|
actions.commitCornerProp('topLeftRadius', 20, 8)
|
|
expect(graph.getNode(rect.id)?.topLeftRadius).toBe(20)
|
|
editor.undo.undo()
|
|
expect(graph.getNode(rect.id)?.topLeftRadius).toBe(8)
|
|
})
|
|
|
|
test('restores each mixed smoothing value in one undo step', () => {
|
|
const graph = makeSceneGraph()
|
|
const pageId = firstPageId(graph)
|
|
const first = graph.createNode('RECTANGLE', pageId, { cornerSmoothing: 0.2 })
|
|
const second = graph.createNode('RECTANGLE', pageId, { cornerSmoothing: 0.8 })
|
|
const editor = createEditor({ graph })
|
|
const nodes = computed(() => {
|
|
const selected = [graph.getNode(first.id), graph.getNode(second.id)]
|
|
return selected.filter((value): value is SceneNode => value !== undefined)
|
|
})
|
|
const actions = createAppearanceActions({
|
|
editor,
|
|
node: computed(() => null),
|
|
nodes,
|
|
isMulti: computed(() => true),
|
|
merged: <K extends keyof SceneNode>(): MixedValue<SceneNode[K]> => MIXED
|
|
})
|
|
|
|
actions.updateCornerProp('cornerSmoothing', 1.4)
|
|
expect(graph.getNode(first.id)?.cornerSmoothing).toBe(1)
|
|
expect(graph.getNode(second.id)?.cornerSmoothing).toBe(1)
|
|
actions.commitCornerProp('cornerSmoothing', 1, 0)
|
|
|
|
editor.undo.undo()
|
|
expect(graph.getNode(first.id)?.cornerSmoothing).toBe(0.2)
|
|
expect(graph.getNode(second.id)?.cornerSmoothing).toBe(0.8)
|
|
})
|
|
})
|