Files
OneCAD-Draft/scripts/test_web_clipboard.cjs
T
Hakan Seven 9b112e3ac0 fix: finalize reviewed drawing and interaction paths
Reset stale geometry when automation replaces a drawing and resolve material paths from its directory. Cover precise indexed snapping, large-coordinate line intersections, leader ordering, invalid image buffers and browser clipboard fallback. Preserve Options dialog resizing.

Validation: cargo test --workspace --all-features (866 passed); wasm32 application check; Node clipboard regression check; Python binding tests (3 passed).
2026-09-09 13:33:14 +03:00

43 lines
2.0 KiB
JavaScript

const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
(async () => {
const source = fs.readFileSync(path.join(__dirname, '../web/clipboard.js'), 'utf8');
const { copyHistory } = await import(`data:text/javascript;base64,${Buffer.from(source).toString('base64')}`);
const text = 'LINE\n0,0\n10,10\n<unchanged & literal>\n';
let copied;
Object.defineProperty(globalThis, 'navigator', { configurable: true, value: {
clipboard: { writeText: async value => { copied = value; } },
}});
assert.equal(await copyHistory(text, 'Copy manually', 'Close'), true);
assert.equal(copied, text);
const dialogs = [];
globalThis.document = {
body: { append: dialog => dialogs.push(dialog) },
createElement: tag => ({
tag, style: {}, events: {},
setAttribute(key, value) { this[key] = value; },
append(...children) { this.children = children; },
addEventListener(event, handler) { this.events[event] = handler; },
showModal() { this.open = true; },
focus() { this.focused = true; },
select() { this.selected = true; },
close() { this.events.close(); },
remove() { this.removed = true; },
}),
};
for (const clipboard of [{ writeText: async () => { throw Error('Denied'); } }, undefined]) {
navigator.clipboard = clipboard;
assert.equal(await copyHistory(text, 'Copy manually', 'Close'), false);
const dialog = dialogs.at(-1);
const [label, field, close] = dialog.children;
assert.equal(label.textContent, 'Copy manually');
assert.equal(field.value, text);
assert.ok(field.readOnly && field.focused && field.selected && dialog.open);
close.onclick();
assert.ok(dialog.removed);
}
console.log('Browser clipboard: success, denied and unavailable paths passed.');
})().catch(error => { console.error(error); process.exitCode = 1; });