Files
FreeCADWasmDev/tools/test_part_box_selection_owners.mjs

34 lines
2.4 KiB
JavaScript

import assert from 'node:assert/strict';
import fs from 'node:fs';
import { loadWasmProbe } from './wasm-probe-runtime.mjs';
const checks = [];
for (const [owner, stem, endpoint] of [['DocumentProbe', 'FreeCADWebDocumentProbe', 'part.documentViewCommand'],
['PartBox', 'FreeCADWebPartBoxProbe', 'part.viewCommand']]) {
const { kernel } = await loadWasmProbe('web/public/kernel', stem);
try {
const document = 'BoxSelectionOwner';
const call = (command, parameters) => JSON.parse(kernel.ccall('fc_web_dispatch_json', 'string', ['string'], [JSON.stringify({
cmd: endpoint, args: { owner, document, command, parameters },
})]));
const source = "import FreeCAD as App, Part; d=App.newDocument('BoxSelectionOwner'); o=d.addObject('Part::Feature','Cube'); o.Shape=Part.makeBox(1,1,1); d.recompute()";
const created = call('Std_CommandLine', { operation: 'submit', source });
assert.equal(created.ok, true, JSON.stringify(created)); assert.equal(created.result.stderr, '');
const input = { selection: [], elementType: 'Face', rectangle: [-1, -1, 1, 1],
viewProjection: [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1] };
const selected = call('Std_BoxElementSelection', input);
assert.equal(selected.ok, true, JSON.stringify(selected)); assert.equal(selected.result.selection[0].subelements.length, 6);
const invalid = call('Std_BoxElementSelection', { ...input, selection: [{ documentId: document, object: 'Cube', subelements: ['Edge999'] }] });
assert.equal(invalid.ok, false); assert.match(JSON.stringify(invalid), /out of range/);
const hidden = call('Std_HideSelection', { selection: [{ documentId: document, object: 'Cube', subelements: [] }] });
assert.equal(hidden.ok, true, JSON.stringify(hidden));
assert.deepEqual(call('Std_BoxElementSelection', input).result.selection, []);
assert.equal(call('Std_ShowObjects', {}).ok, true);
assert.equal(call('Std_BoxElementSelection', input).result.selection[0].subelements.length, 6);
checks.push({ owner, selected: selected.result.selection, invalid: invalid.error, hiddenExcluded: true, recovered: true });
} finally { kernel.PThread?.terminateAllThreads(); }
}
fs.writeFileSync('docs/current/part-box-selection-owners.json', JSON.stringify({ status: 'passed', checks }, null, 2));
console.log(JSON.stringify({ status: 'passed', owners: checks.map(item => item.owner) }));
process.exit(0);