32 lines
1.5 KiB
JavaScript
32 lines
1.5 KiB
JavaScript
// Example actions for shot.js: a 3D editor with a left shape menu, a canvas
|
|
// in the middle and a properties panel on the right. Adapt selectors/coords.
|
|
module.exports = async (h) => {
|
|
await h.clickEl('#add-box');
|
|
await h.clickEl('#add-cylinder');
|
|
await h.shot('two_shapes');
|
|
|
|
// select both via shift-click in the canvas, then group
|
|
await h.click(640, 420);
|
|
await h.click(720, 420, { shift: true });
|
|
await h.shot('multi_selected');
|
|
await h.clickEl('#group');
|
|
|
|
// verify through the app's test hook instead of guessing from pixels
|
|
const groups = await h.eval(() => window.__app.objects.filter(o => o.type === 'group').length);
|
|
if (groups !== 1) throw new Error(`expected 1 group, got ${groups}`);
|
|
await h.shot('grouped');
|
|
|
|
// import through the REAL file dialog (button -> <input type=file> -> app code)
|
|
await h.upload('#import-svg', 'fixtures/circle.svg');
|
|
const types = await h.eval(() => window.__app.state.objects.map(o => o.type));
|
|
if (!types.includes('svg')) throw new Error('SVG import via button added nothing: ' + types);
|
|
await h.shot('svg_imported');
|
|
|
|
// export through the REAL button (-> <a download> -> file on disk)
|
|
const json = await h.download('#save-json');
|
|
const data = JSON.parse(json.text);
|
|
if (!data.objects?.[0]?.position) throw new Error('saved JSON has no position: ' + json.text.slice(0, 200));
|
|
const stl = await h.download('#export-stl');
|
|
if (!stl.text.startsWith('solid')) throw new Error('STL export is not ASCII STL');
|
|
};
|