openpencil/tools/generate/visual-oracles/tests/document/capture.test.ts
Danila Poyarkov 2101279e1d
refactor(fig): group prefixed siblings into folders
* 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.
2026-10-01 16:52:40 +04:00

27 lines
1.1 KiB
TypeScript

import { expect, test } from 'bun:test'
import { captureDocumentOracle } from '#visual/capture/document'
import { SceneGraph } from '@open-pencil/scene-graph'
/** Two captures only line up if every node is addressed by page as well as position. */
test('each page keeps its own node paths under a page prefix', () => {
const graph = new SceneGraph()
const first = graph.getPages()[0]
graph.createNode('FRAME', first.id, { name: 'Only' })
const second = graph.addPage('Second')
const frame = graph.createNode('FRAME', second.id, { name: 'Outer' })
graph.createNode('TEXT', frame.id, { name: 'Inner', text: 'Hello' })
const nodes = captureDocumentOracle(graph, new Map())
const paths = nodes.map((node) => node.path.join(','))
expect(paths).toEqual(['0', '0,0', '1', '1,0', '1,0,0'])
expect(nodes.find((node) => node.path.join(',') === '1,0,0')?.text).toBe('Hello')
})
test('an unchanged document captures identically', () => {
const graph = new SceneGraph()
graph.createNode('FRAME', graph.getPages()[0].id, { name: 'Frame' })
expect(captureDocumentOracle(graph, new Map())).toEqual(captureDocumentOracle(graph, new Map()))
})