* refactor(tools): group the oracle captures and mirror the bindings tests
Two names broke the rule that a multi-file domain gets a subfolder
rather than repeated sibling prefixes. `document-capture.ts` repeated
its own folder and sat beside `capture-scene.ts`, so both become
`document/capture/{document,scene}.ts` behind `#visual/capture/*`.
The document bindings tests were split between `document/binding/` and
a `text-bindings.test.ts` one level above, while their source is
`document/bindings/`. They move into `document/bindings/` and take the
source file names, so the test tree mirrors it.
* refactor(fig): group the node-change prefix families into folders
`node-change/` held five pairs of files sharing a leading segment —
derived-text, style, text, variable, vector — plus `instance-geometry`
beside an `instance-linkage/` folder. The guide asks for a subfolder
rather than a repeated prefix, so each becomes one: `style/{refs,runs}`,
`variable/{bindings,expression}`, and so on, with `instance-linkage/`
folded in beside `instance/geometry.ts`.
Imports across seventeen files follow. Two of the moved files reached
out of the package tree with `../../` once they were a level deeper;
those use `#fig/*` instead.
45 lines
1.8 KiB
TypeScript
45 lines
1.8 KiB
TypeScript
import { expect, test } from 'bun:test'
|
|
|
|
import type { DerivedSymbolOverride } from '#fig/instance-overrides/types'
|
|
import { snapshotInstanceGeometry } from '#fig/node-change/instance/geometry'
|
|
|
|
import { stringToGuid } from '@open-pencil/kiwi/fig/guid'
|
|
import { SceneGraph } from '@open-pencil/scene-graph'
|
|
|
|
import { expectDefined } from '../helpers/assert'
|
|
|
|
function fixture() {
|
|
const graph = new SceneGraph()
|
|
const component = graph.createNode('COMPONENT', graph.getPages()[0].id)
|
|
const source = graph.createNode('RECTANGLE', component.id, { width: 10, height: 20 })
|
|
const owner = expectDefined(graph.createInstance(component.id, graph.getPages()[0].id))
|
|
return { graph, source, owner }
|
|
}
|
|
|
|
test('geometry snapshots merge retained fields without authoring claims or mutating retained data', () => {
|
|
const { graph, source, owner } = fixture()
|
|
const guidPath = { guids: [stringToGuid(source.id)] }
|
|
const retained: DerivedSymbolOverride[] = [
|
|
{ guidPath, fontSize: 12 },
|
|
{ guidPath, size: { x: 1, y: 1 } },
|
|
{ fontSize: 24 }
|
|
]
|
|
const before = structuredClone(retained)
|
|
const result = snapshotInstanceGeometry(graph, owner, stringToGuid, retained, (node) => ({
|
|
size: { x: node.width, y: node.height }
|
|
}))
|
|
expect(result).toEqual([{ fontSize: 24 }, { guidPath, fontSize: 12, size: { x: 10, y: 20 } }])
|
|
expect(retained).toEqual(before)
|
|
expect(owner.instanceOverrides.self.size).toBe(0)
|
|
})
|
|
|
|
test('geometry snapshots reject ambiguous occurrence addresses', () => {
|
|
const { graph, source, owner } = fixture()
|
|
graph.createNode('RECTANGLE', owner.id, { componentId: source.id })
|
|
expect(() =>
|
|
snapshotInstanceGeometry(graph, owner, stringToGuid, [], (node) => ({
|
|
size: { x: node.width, y: node.height }
|
|
}))
|
|
).toThrow('Ambiguous instance geometry address')
|
|
})
|