feat: close hidden link property evidence
This commit is contained in:
71
tests/propertyLinkListHiddenFacade.test.ts
Normal file
71
tests/propertyLinkListHiddenFacade.test.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { unzipSync } from 'fflate'
|
||||
import { createWebCadFacade } from '../src/facade/mockFacade'
|
||||
import { decodeFcstdPropertyValue } from '../src/facade/fcstd'
|
||||
import { encodeFreecadPropertyStatus, isFreecadPropertyHidden } from '../src/facade/propertyStatus'
|
||||
import type { DocumentSnapshot, FacadeEvent } from '../src/facade/types'
|
||||
|
||||
const hiddenStatus = encodeFreecadPropertyStatus(['PropHidden'])
|
||||
|
||||
const fixture = (): DocumentSnapshot => ({
|
||||
id: 'property-linklisthidden-facade', label: 'PropertyLinkListHidden Facade', version: 1, dirty: false, readOnly: false, units: 'mm',
|
||||
tree: [
|
||||
{ id: 'SketchProbe', label: 'Sketch probe', type: 'sketch', state: 'valid' },
|
||||
{ id: 'SketchPythonProbe', label: 'Sketch Python probe', type: 'sketch', state: 'valid' },
|
||||
{ id: 'ExportA', label: 'Export A', type: 'feature', state: 'valid' },
|
||||
{ id: 'ExportB', label: 'Export B', type: 'feature', state: 'valid' },
|
||||
],
|
||||
objects: [
|
||||
{ id: 'SketchProbe', typeId: 'Sketcher::SketchObject', properties: [{ name: 'Exports', label: 'Exports', group: 'Sketch', scope: 'data', type: 'App::PropertyLinkListHidden', value: ['ExportA', 'ExportB'], nativeStatus: hiddenStatus, recompute: true }] },
|
||||
{ id: 'SketchPythonProbe', typeId: 'Sketcher::SketchObjectPython', properties: [{ name: 'Exports', label: 'Exports', group: 'Sketch', scope: 'data', type: 'App::PropertyLinkListHidden', value: ['ExportA'], nativeStatus: hiddenStatus, recompute: true }] },
|
||||
{ id: 'ExportA', typeId: 'Part::Feature', properties: [] },
|
||||
{ id: 'ExportB', typeId: 'Part::Feature', properties: [] },
|
||||
],
|
||||
dependencies: [],
|
||||
recompute: { generation: 0, status: 'idle', objectStates: { SketchProbe: 'up-to-date', SketchPythonProbe: 'up-to-date', ExportA: 'up-to-date', ExportB: 'up-to-date' }, dirtyObjects: [], order: [], errors: [] },
|
||||
})
|
||||
|
||||
const valueOf = (facade: ReturnType<typeof createWebCadFacade>) => facade.app.document.getObject('SketchProbe')?.properties.find((property) => property.name === 'Exports')?.value
|
||||
|
||||
test('App::PropertyLinkListHidden preserves ordered links without adding dependency edges', () => {
|
||||
const facade = createWebCadFacade({ initialDocument: fixture(), initialSelectedObjectIds: ['SketchProbe'], runtimeMode: 'mock' })
|
||||
const events: FacadeEvent[] = []
|
||||
facade.subscribe((event) => { if (event.type === 'property.before-change' || event.type === 'property.changed' || event.type === 'transaction.committed') events.push(event) })
|
||||
|
||||
facade.app.document.setProperty({ objectId: 'SketchProbe', propertyName: 'Exports', value: ['ExportB', 'ExportA', 'ExportB'] })
|
||||
assert.deepEqual(valueOf(facade), ['ExportB', 'ExportA', 'ExportB'])
|
||||
assert.equal(facade.app.document.getActive().version, 2)
|
||||
assert.equal(facade.app.document.getActive().recompute?.objectStates.SketchProbe, 'touched')
|
||||
assert.deepEqual(facade.app.document.getDependencies(), [])
|
||||
assert.deepEqual(events.map((event) => event.type), ['property.before-change', 'property.changed', 'transaction.committed'])
|
||||
assert.equal(isFreecadPropertyHidden(hiddenStatus), true)
|
||||
|
||||
const beforeFailure = facade.app.document.getActive()
|
||||
assert.throws(() => facade.app.document.setProperty({ objectId: 'SketchProbe', propertyName: 'Exports', value: ['MissingExport'] }), /target that does not exist/)
|
||||
assert.throws(() => facade.app.document.setProperty({ objectId: 'SketchProbe', propertyName: 'Exports', value: [1] as unknown as string[] }), /string list/)
|
||||
assert.deepEqual(facade.app.document.getActive(), beforeFailure)
|
||||
|
||||
const archive = facade.project.fcstd.serializeMetadata(facade.app.document.getActive())
|
||||
const xml = new TextDecoder().decode(unzipSync(archive)['Document.xml'])
|
||||
assert.match(xml, /<ObjectDeps Name="SketchProbe" Count="0"\/>/)
|
||||
assert.match(xml, /<ObjectDeps Name="SketchPythonProbe" Count="0"\/>/)
|
||||
assert.match(xml, new RegExp(`<Property name="Exports" type="App::PropertyLinkListHidden" status="${hiddenStatus}"><LinkList count="3"><Link value="ExportB"\/><Link value="ExportA"\/><Link value="ExportB"\/><\/LinkList><\/Property>`))
|
||||
assert.doesNotMatch(xml, /<Property name="Exports"[^>]+(?:group|doc|attr|ro|hide)=/)
|
||||
const object = facade.project.fcstd.inspect(archive).objects.find(({ name }) => name === 'SketchProbe')
|
||||
assert.equal(object?.support, 'recognized')
|
||||
const summary = object?.properties.find(({ name }) => name === 'Exports')
|
||||
assert.deepEqual({ typeId: summary?.typeId, element: summary?.element, nativeStatus: summary?.nativeStatus, statusNames: summary?.statusNames }, { typeId: 'App::PropertyLinkListHidden', element: 'LinkList', nativeStatus: hiddenStatus, statusNames: ['PropHidden'] })
|
||||
assert.deepEqual(decodeFcstdPropertyValue(summary!), { value: ['ExportB', 'ExportA', 'ExportB'], decoded: true })
|
||||
const pythonObject = facade.project.fcstd.inspect(archive).objects.find(({ name }) => name === 'SketchPythonProbe')
|
||||
const pythonSummary = pythonObject?.properties.find(({ name }) => name === 'Exports')
|
||||
assert.equal(pythonObject?.support, 'recognized')
|
||||
assert.deepEqual({ typeId: pythonSummary?.typeId, element: pythonSummary?.element, nativeStatus: pythonSummary?.nativeStatus }, { typeId: 'App::PropertyLinkListHidden', element: 'LinkList', nativeStatus: hiddenStatus })
|
||||
assert.deepEqual(decodeFcstdPropertyValue(pythonSummary!), { value: ['ExportA'], decoded: true })
|
||||
|
||||
const rewritten = facade.project.fcstd.rewriteLinkListHidden(archive, { objectName: 'SketchProbe', propertyName: 'Exports', value: ['ExportA', 'ExportB', 'ExportA'], expectedValue: ['ExportB', 'ExportA', 'ExportB'] })
|
||||
const rewrittenSummary = facade.project.fcstd.inspect(rewritten).objects.find(({ name }) => name === 'SketchProbe')?.properties.find(({ name }) => name === 'Exports')
|
||||
assert.deepEqual(decodeFcstdPropertyValue(rewrittenSummary!), { value: ['ExportA', 'ExportB', 'ExportA'], decoded: true })
|
||||
assert.throws(() => facade.project.fcstd.rewriteLinkListHidden(archive, { objectName: 'SketchProbe', propertyName: 'Exports', value: ['MissingExport'], expectedValue: ['ExportB', 'ExportA', 'ExportB'] }), /target does not exist/)
|
||||
assert.throws(() => facade.project.fcstd.rewriteLinkListHidden(archive, { objectName: 'SketchProbe', propertyName: 'Exports', value: ['ExportA'], expectedValue: ['ExportA'] }), /does not match expectedValue/)
|
||||
})
|
||||
79
tests/propertyLinkListHiddenTransaction.test.ts
Normal file
79
tests/propertyLinkListHiddenTransaction.test.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { createWebCadFacade } from '../src/facade/mockFacade'
|
||||
import { encodeFreecadPropertyStatus } from '../src/facade/propertyStatus'
|
||||
import type { DocumentSnapshot, FacadeEvent } from '../src/facade/types'
|
||||
|
||||
const fixture = (): DocumentSnapshot => ({
|
||||
id: 'property-linklisthidden-transaction', label: 'PropertyLinkListHidden Transaction', version: 1, dirty: false, readOnly: false, units: 'mm',
|
||||
tree: [
|
||||
{ id: 'SketchProbe', label: 'Sketch probe', type: 'sketch', state: 'valid' },
|
||||
{ id: 'ExportA', label: 'Export A', type: 'feature', state: 'valid' },
|
||||
{ id: 'ExportB', label: 'Export B', type: 'feature', state: 'valid' },
|
||||
],
|
||||
objects: [
|
||||
{ id: 'SketchProbe', typeId: 'Sketcher::SketchObject', properties: [{ name: 'Exports', label: 'Exports', group: 'Sketch', scope: 'data', type: 'App::PropertyLinkListHidden', value: ['ExportA', 'ExportB'], nativeStatus: encodeFreecadPropertyStatus(['PropHidden']), recompute: true }] },
|
||||
{ id: 'ExportA', typeId: 'Part::Feature', properties: [] },
|
||||
{ id: 'ExportB', typeId: 'Part::Feature', properties: [] },
|
||||
],
|
||||
dependencies: [],
|
||||
recompute: { generation: 0, status: 'idle', objectStates: { SketchProbe: 'up-to-date', ExportA: 'up-to-date', ExportB: 'up-to-date' }, dirtyObjects: [], order: [], errors: [] },
|
||||
})
|
||||
|
||||
const valueOf = (facade: ReturnType<typeof createWebCadFacade>) => facade.app.document.getObject('SketchProbe')?.properties.find((property) => property.name === 'Exports')?.value as string[]
|
||||
|
||||
test('App::PropertyLinkListHidden transaction closes undo, redo, stale, cancel, failure, hidden dependencies and resources', async () => {
|
||||
const facade = createWebCadFacade({ initialDocument: fixture(), runtimeMode: 'mock' })
|
||||
const events: FacadeEvent[] = []
|
||||
facade.subscribe((event) => { if (event.type === 'property.before-change' || event.type === 'property.changed' || event.type === 'transaction.committed') events.push(event) })
|
||||
const resourcesBefore = facade.geometry.capabilities()
|
||||
const requested = ['ExportB', 'ExportA', 'ExportB']
|
||||
facade.app.document.setProperty({ objectId: 'SketchProbe', propertyName: 'Exports', value: requested, expectedDocumentVersion: 1 })
|
||||
requested[0] = 'ExportA'
|
||||
assert.deepEqual(valueOf(facade), ['ExportB', 'ExportA', 'ExportB'])
|
||||
const exposed = valueOf(facade)
|
||||
exposed[0] = 'ExportA'
|
||||
assert.deepEqual(valueOf(facade), ['ExportB', 'ExportA', 'ExportB'])
|
||||
assert.equal(facade.app.document.getActive().version, 2)
|
||||
assert.equal(facade.app.document.getActive().dirty, true)
|
||||
assert.equal(facade.app.document.getActive().recompute?.objectStates.SketchProbe, 'touched')
|
||||
assert.deepEqual(facade.app.document.getDependencies(), [])
|
||||
assert.deepEqual(events.map(({ type }) => type), ['property.before-change', 'property.changed', 'transaction.committed'])
|
||||
assert.equal(new Set(events.map((event) => 'transactionId' in event ? event.transactionId : '')).size, 1)
|
||||
const committed = events[2]
|
||||
assert.equal(committed.type, 'transaction.committed')
|
||||
if (committed.type === 'transaction.committed') assert.deepEqual({ operation: committed.operation, beforeVersion: committed.beforeVersion, afterVersion: committed.afterVersion }, { operation: 'property.set', beforeVersion: 1, afterVersion: 2 })
|
||||
|
||||
facade.history.undo()
|
||||
assert.deepEqual(valueOf(facade), ['ExportA', 'ExportB'])
|
||||
assert.equal(facade.app.document.getActive().version, 1)
|
||||
assert.deepEqual(facade.app.document.getDependencies(), [])
|
||||
assert.equal(facade.history.canUndo(), false)
|
||||
assert.equal(facade.history.canRedo(), true)
|
||||
facade.history.redo()
|
||||
assert.deepEqual(valueOf(facade), ['ExportB', 'ExportA', 'ExportB'])
|
||||
assert.equal(facade.app.document.getActive().version, 2)
|
||||
assert.deepEqual(facade.app.document.getDependencies(), [])
|
||||
assert.equal(facade.history.canUndo(), true)
|
||||
assert.equal(facade.history.canRedo(), false)
|
||||
|
||||
const stable = JSON.stringify(facade.app.document.getActive())
|
||||
const eventCount = events.length
|
||||
assert.throws(() => facade.app.document.setProperty({ objectId: 'SketchProbe', propertyName: 'Exports', value: ['ExportA'], expectedDocumentVersion: 1 }), /Stale document version: expected 1, current 2/)
|
||||
const cancelled = new AbortController()
|
||||
cancelled.abort()
|
||||
assert.throws(() => facade.app.document.setProperty({ objectId: 'SketchProbe', propertyName: 'Exports', value: ['ExportA'], expectedDocumentVersion: 2, signal: cancelled.signal }), (error: unknown) => error instanceof DOMException && error.name === 'AbortError')
|
||||
assert.throws(() => facade.app.document.setProperty({ objectId: 'SketchProbe', propertyName: 'Exports', value: ['MissingExport'] }), /target that does not exist/)
|
||||
assert.throws(() => facade.app.document.setProperty({ objectId: 'SketchProbe', propertyName: 'Exports', value: [1] as unknown as string[] }), /string list/)
|
||||
assert.equal(JSON.stringify(facade.app.document.getActive()), stable)
|
||||
assert.equal(events.length, eventCount)
|
||||
assert.equal(facade.history.canUndo(), true)
|
||||
assert.equal(facade.history.canRedo(), false)
|
||||
|
||||
const resourcesAfter = facade.geometry.capabilities()
|
||||
assert.deepEqual(
|
||||
{ shapeCount: resourcesAfter.shapeCount, kernelReferenceCount: resourcesAfter.kernelReferenceCount, releasedShapeCount: resourcesAfter.releasedShapeCount },
|
||||
{ shapeCount: resourcesBefore.shapeCount, kernelReferenceCount: resourcesBefore.kernelReferenceCount, releasedShapeCount: resourcesBefore.releasedShapeCount },
|
||||
)
|
||||
await facade.project.dispose()
|
||||
})
|
||||
Reference in New Issue
Block a user