Add AC/BC RTCP programs and 3D machine manager
This commit is contained in:
@@ -3,7 +3,7 @@ import { mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { pathToFileURL } from "node:url";
|
||||
|
||||
const { chromium } = await import(pathToFileURL(process.env.PLAYWRIGHT_MODULE).href);
|
||||
const output = new URL("../coverage/trt-parametric/", import.meta.url);
|
||||
const output = process.env.TRT_EVIDENCE_DIR ? pathToFileURL(`${process.env.TRT_EVIDENCE_DIR.replace(/\/$/, "")}/`) : new URL("../coverage/trt-parametric/", import.meta.url);
|
||||
await mkdir(output, { recursive: true });
|
||||
const browser = await chromium.launch({ executablePath: "/usr/bin/google-chrome", headless: true, args: ["--no-sandbox", "--use-angle=swiftshader", "--enable-unsafe-swiftshader"] });
|
||||
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
||||
@@ -13,6 +13,12 @@ page.on("pageerror", (error) => errors.push(error.message));
|
||||
const control = (id) => page.locator(`[data-axis-control="${id}"]`);
|
||||
const machine = page.locator(".xyzac-machine-view");
|
||||
const panel = page.locator(".trt-geometry");
|
||||
const openGeometry = async () => {
|
||||
if (!(await page.locator(".geometry-dialog[open]").count())) await control("geometry-settings").click();
|
||||
};
|
||||
const closeGeometry = async () => {
|
||||
if (await page.locator(".geometry-dialog[open]").count()) await page.locator(".geometry-dialog [aria-label=\"关闭机床几何参数\"]").click();
|
||||
};
|
||||
const settled = async () => {
|
||||
await page.waitForFunction(() => document.querySelector("main")?.dataset.axisProgramLoading === "false" && document.querySelector(".trt-geometry")?.getAttribute("aria-busy") === "false");
|
||||
await page.waitForTimeout(350);
|
||||
@@ -30,6 +36,7 @@ try {
|
||||
for (const [id, unsupported] of [["xyzac-trt", "x-offset"], ["xyzbc-trt", "y-offset"]]) {
|
||||
if (id === "xyzbc-trt") { await control("machine-type-select").selectOption({ label: "XYZBC TRT" }); await settled(); }
|
||||
assert.equal(await machine.getAttribute("data-xyzac-model-id"), id);
|
||||
await openGeometry();
|
||||
assert.equal(await panel.getByLabel(unsupported, { exact: true }).isDisabled(), true);
|
||||
const beforePath = await page.locator("main").getAttribute("data-axis-program-path");
|
||||
const original = JSON.parse(await machine.getAttribute("data-xyzac-offsets"));
|
||||
@@ -38,11 +45,13 @@ try {
|
||||
await panel.getByLabel("y-rot-point", { exact: true }).fill("-12");
|
||||
await panel.getByLabel("z-rot-point", { exact: true }).fill("8");
|
||||
await control("geometry-apply").click(); await settled();
|
||||
await closeGeometry();
|
||||
const offsets = JSON.parse(await machine.getAttribute("data-xyzac-offsets"));
|
||||
assert.equal(offsets.x_rot_point, 24); assert.equal(offsets.y_rot_point, -12); assert.equal(offsets.z_rot_point, 8);
|
||||
assert.equal(await page.locator("main").getAttribute("data-axis-program-path"), beforePath);
|
||||
assert.notEqual((await pixels()).hash, before.hash);
|
||||
await machine.screenshot({ path: new URL(`${id}-model.png`, output).pathname });
|
||||
await openGeometry();
|
||||
const downloading = page.waitForEvent("download"); await control("geometry-save").click();
|
||||
const download = await downloading;
|
||||
assert.equal(download.suggestedFilename(), `${id}.ini`);
|
||||
@@ -50,11 +59,13 @@ try {
|
||||
assert.match(exported, /x-rot-point\s+24/); assert.match(exported, /LIB:basic_sim.tcl/);
|
||||
assert.doesNotMatch(exported, /HALFILE = .*_cmds.hal/);
|
||||
await control("geometry-reload").click(); await settled();
|
||||
await openGeometry();
|
||||
assert.deepEqual(JSON.parse(await machine.getAttribute("data-xyzac-offsets")), original);
|
||||
await panel.locator('input[type="file"]').setInputFiles({ name: `${id}.ini`, mimeType: "text/plain", buffer: Buffer.from(exported) });
|
||||
await page.waitForFunction(() => document.querySelector('.trt-geometry input[aria-label="x-rot-point"]')?.value === "24");
|
||||
await control("geometry-apply").click(); await settled();
|
||||
assert.equal(JSON.parse(await machine.getAttribute("data-xyzac-offsets")).x_rot_point, 24);
|
||||
await closeGeometry();
|
||||
await control("toolbar-power").click();
|
||||
await page.waitForFunction(() => document.querySelector('.trt-geometry input[aria-label="x-rot-point"]')?.disabled === true);
|
||||
assert.equal(await panel.getByLabel("x-rot-point", { exact: true }).isDisabled(), true);
|
||||
@@ -66,11 +77,13 @@ try {
|
||||
for (const [width, height] of [[1440, 1000], [390, 844]]) {
|
||||
await page.setViewportSize({ width, height }); await panel.scrollIntoViewIfNeeded(); await page.waitForTimeout(400);
|
||||
const canvas = await pixels(); assert.ok(canvas.colors > 100 && canvas.width > 100 && canvas.height >= 220);
|
||||
const boxes = await panel.locator("label, input:not([hidden]), button").evaluateAll((elements) => elements.map((element) => {
|
||||
await openGeometry();
|
||||
const boxes = await page.locator(".geometry-dialog").locator("label, input:not([hidden]), button").evaluateAll((elements) => elements.map((element) => {
|
||||
const r = element.getBoundingClientRect(); return { x: r.x, right: r.right, width: r.width };
|
||||
}));
|
||||
assert.ok(boxes.every((r) => r.width > 0 && r.x >= 0 && r.right <= width), JSON.stringify(boxes));
|
||||
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth));
|
||||
await closeGeometry();
|
||||
const before = await pixels();
|
||||
await control("machine-rotateLeft").click(); await page.waitForTimeout(400);
|
||||
assert.notEqual((await pixels()).hash, before.hash);
|
||||
|
||||
Reference in New Issue
Block a user