Files
linuxcncWebWASM/web/app/test_editor_workflow.mjs

17 lines
1.1 KiB
JavaScript

import assert from "node:assert/strict";
import { CommandController, CONTROL_COMMANDS } from "./controls.mjs";
import { EMPTY_STATE, reduceWorkerState } from "./state-panel.mjs";
const calls = [];
const client = { send: async (kind, payload, options) => { calls.push({ kind, payload, options }); return { kind: "COMMAND_RESULT", payload: { status: "verified", command: kind }, simulation_tick: calls.length }; } };
const controller = new CommandController(client);
assert.equal(CONTROL_COMMANDS.mdi, "MDI_EXECUTE");
await controller.execute("mdi", { block: "G1 X2" }, { operationId: "mdi-1" });
await controller.execute("restart", {}, { operationId: "restart-1" });
assert.deepEqual(calls.map((call) => call.kind), ["MDI_EXECUTE", "PROGRAM_RESTART"]);
const error = reduceWorkerState(EMPTY_STATE, { kind: "ERROR", payload: { code: "program_interpreter", line: 7, column: 4, text: "G1 X?" } });
assert.equal(error.diagnostic.line, 7);
assert.equal(error.diagnostic.column, 4);
assert.equal(error.diagnostic.text, "G1 X?");
console.log(`editor_workflow=passed calls=${calls.length} diagnostic=${error.diagnostic.code}@${error.diagnostic.line}:${error.diagnostic.column}`);