test: fix heavy unit-test measurement and round-trip checks (#655)

* test: use core page switching for imported text measurement

* test: correct FIG round-trip equivalence checks
This commit is contained in:
Danila Poyarkov 2026-09-07 00:33:12 +03:00 committed by GitHub
parent c946337f3d
commit 9dac52da13
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 80 additions and 4 deletions

View file

@ -97,7 +97,11 @@ function sameNodeReferences(
a.length === b.length &&
a.every((value, index) => {
const other = b[index]
return other !== undefined && sameNodeReference(ctx, value, other)
return (
other !== undefined &&
(sameNodeReference(ctx, value, other) ||
(!ctx.aGraph.getNode(value) && !ctx.bGraph.getNode(other) && value === other))
)
})
)
}
@ -400,6 +404,7 @@ export const RAW_VERIFIERS = new Map<string, Verifier>([
return true
}
],
['textAlignHorizontal', defaultEqual('LEFT')],
['borderRightWeight', defaultEqual(0)],
['borderLeftWeight', defaultEqual(0)],
['borderTopWeight', defaultEqual(0)],

View file

@ -0,0 +1,72 @@
import { expect, test } from 'bun:test'
import { SceneGraph } from '@open-pencil/scene-graph'
import { RAW_VERIFIERS, SCENE_VERIFIERS, type VerifierContext } from './helpers'
function context(a: unknown, b: unknown, generation = 0): VerifierContext {
return {
a,
b,
generation,
key: '',
path: '',
label: 'verifier regression',
aGraph: new SceneGraph(),
bGraph: new SceneGraph(),
aNodes: new Map(),
bNodes: new Map(),
aNodePaths: new Map(),
bNodePaths: new Map(),
aComponentPropertyDefinitions: new Map(),
bComponentPropertyDefinitions: new Map(),
errors: [],
fixture: {
file: '',
fileSize: 0,
nodeCount: 0,
nodeTypes: {},
schemaSize: 0,
thumbnailSize: 0,
thumbnailWidth: 0,
thumbnailHeight: 0,
imageCount: 0,
figKiwiVersion: 0,
g1ExportSize: 0,
g2ExportSize: 0
}
}
}
test('alignment normalization accepts only default LEFT on the first round trip', () => {
const verify = RAW_VERIFIERS.get('textAlignHorizontal')
expect(verify).toBeDefined()
expect(verify?.(context(undefined, 'LEFT'))).toBe(true)
expect(verify?.(context(undefined, 'RIGHT'))).toBe(false)
expect(verify?.(context(undefined, 'LEFT', 1))).toBe(false)
expect(verify?.(context('LEFT', 'LEFT', 1))).toBe(true)
})
test('preferred component keys must remain identical while local IDs follow node paths', () => {
const definition = {
id: 'property',
name: 'Avatar',
type: 'INSTANCE_SWAP',
defaultValue: 'old',
preferredValues: ['external-key']
}
const other = { ...definition, defaultValue: 'new', preferredValues: ['external-key'] }
const ctx = context([definition], [other])
ctx.aNodePaths = new Map([['old', '0/0']])
ctx.bNodePaths = new Map([['new', '0/0']])
const verify = SCENE_VERIFIERS.get('componentPropertyDefinitions')
expect(verify).toBeDefined()
expect(verify?.(ctx)).toBe(true)
other.preferredValues = ['different-key']
expect(verify?.(ctx)).toBe(false)
definition.preferredValues = ['old']
other.preferredValues = ['new']
expect(verify?.(ctx)).toBe(true)
ctx.bNodePaths = new Map([['new', '0/1']])
expect(verify?.(ctx)).toBe(false)
})

View file

@ -1,8 +1,7 @@
import { describe, expect, test } from 'bun:test'
import { computeAllLayouts, SceneGraph, setTextMeasurer } from '@open-pencil/core'
import { createEditorStore } from '@/app/editor/session'
import { createEditor } from '@open-pencil/core/editor'
import { getNodeOrThrow } from '#tests/helpers/assert'
import { autoFrame, loadFixtureGraph, pageId, rect } from '#tests/helpers/layout'
@ -132,7 +131,7 @@ describe('text measurement', () => {
{ timeout: HEAVY_TEST_TIMEOUT_MS },
async () => {
const graph = await loadFixtureGraph('gold-preview.fig')
const store = createEditorStore(graph)
const store = createEditor({ graph, skipInitialGraphSetup: true })
const title = [...store.graph.getAllNodes()].find(
(node) => node.type === 'TEXT' && node.text === "World's largest"
)