接入 INI 面板浏览器状态 report getter
This commit is contained in:
@@ -11,6 +11,10 @@ objects produced by the run/session/machine-file helpers and the visible badge
|
||||
state so browser tests or future UI consumers can compare panel state without
|
||||
reading ad hoc DOM text.
|
||||
|
||||
Upper-level UI/API consumers should read `createMachineSessionStateReport(...)`
|
||||
or `window.getMachineSessionStateReport()` rather than scraping DOM nodes or
|
||||
depending on `window.linuxCncIniPanelMachineSessionState` directly.
|
||||
|
||||
## `createIniPanelStateSummary(input)`
|
||||
|
||||
`input` may contain:
|
||||
|
||||
@@ -47,6 +47,7 @@ import {
|
||||
} from "./session-workflow.js";
|
||||
import {
|
||||
createMachineSessionStateSnapshot,
|
||||
createMachineSessionStateReport,
|
||||
} from "./panel-state-summary.js";
|
||||
|
||||
const SAMPLE_PATH =
|
||||
@@ -151,6 +152,10 @@ let canonicalEventText = "";
|
||||
let runPlaybackTimer = null;
|
||||
let panelMachineSessionState = createMachineSessionStateSnapshot();
|
||||
|
||||
function getMachineSessionStateReport() {
|
||||
return createMachineSessionStateReport(window.linuxCncIniPanelMachineSessionState);
|
||||
}
|
||||
|
||||
function updatePanelMachineSessionState(patch = {}) {
|
||||
panelMachineSessionState = createMachineSessionStateSnapshot({
|
||||
...panelMachineSessionState,
|
||||
@@ -164,6 +169,9 @@ function updatePanelMachineSessionState(patch = {}) {
|
||||
return panelMachineSessionState;
|
||||
}
|
||||
|
||||
window.getMachineSessionStateReport = getMachineSessionStateReport;
|
||||
window.linuxCncIniPanelMachineSessionState = panelMachineSessionState;
|
||||
|
||||
function setBadge(node, text, className = "badge") {
|
||||
node.className = className;
|
||||
node.textContent = text;
|
||||
|
||||
@@ -493,6 +493,22 @@ TOOL_TABLE = browser-tool.tbl
|
||||
) {
|
||||
throw new Error(`UI saved snapshot log missing metadata summary: ${savedSnapshotLog}`);
|
||||
}
|
||||
const savedMachineSessionStateReport = uiDocument.defaultView.getMachineSessionStateReport();
|
||||
assertEqual(
|
||||
savedMachineSessionStateReport.session.snapshotLabel,
|
||||
"ui-machine-session/ui-machine-session.json",
|
||||
"UI saved machine session state report snapshot label",
|
||||
);
|
||||
assertEqual(
|
||||
savedMachineSessionStateReport.session.gcode,
|
||||
"linuxcnc/gcode/ui-session.ngc",
|
||||
"UI saved machine session state report G-code path",
|
||||
);
|
||||
assertEqual(
|
||||
savedMachineSessionStateReport.status.lastAction,
|
||||
"save-session-snapshot",
|
||||
"UI saved machine session state report last action",
|
||||
);
|
||||
const savedUiSnapshot = await loadMachineSessionSnapshot(
|
||||
"ui-machine-session",
|
||||
"xyzab-tdr",
|
||||
@@ -572,6 +588,27 @@ TOOL_TABLE = browser-tool.tbl
|
||||
) {
|
||||
throw new Error(`UI restore/load session log missing OPFS default file mapping: ${uiLog}`);
|
||||
}
|
||||
const restoredLoadedMachineSessionStateReport = uiDocument.defaultView.getMachineSessionStateReport();
|
||||
assertEqual(
|
||||
restoredLoadedMachineSessionStateReport.session.snapshotLabel,
|
||||
"ui-machine-session/ui-machine-session.json",
|
||||
"UI restored loaded machine session state report snapshot label",
|
||||
);
|
||||
assertEqual(
|
||||
restoredLoadedMachineSessionStateReport.loaded.iniWasmPath,
|
||||
"/work/session-machine.ini",
|
||||
"UI restored loaded machine session state report loaded INI WASM path",
|
||||
);
|
||||
assertEqual(
|
||||
restoredLoadedMachineSessionStateReport.loaded.parameterWasmPath,
|
||||
"/work/session-linuxcnc.var",
|
||||
"UI restored loaded machine session state report loaded parameter WASM path",
|
||||
);
|
||||
assertEqual(
|
||||
restoredLoadedMachineSessionStateReport.status.lastAction,
|
||||
"restore-load-session",
|
||||
"UI restored loaded machine session state report last action",
|
||||
);
|
||||
uiDocument.getElementById("run-gcode").click();
|
||||
await waitFor(
|
||||
() => uiDocument.getElementById("log")?.textContent.includes("Ran G-code"),
|
||||
@@ -660,36 +697,51 @@ TOOL_TABLE = browser-tool.tbl
|
||||
2,
|
||||
"UI snapshot run summary motion snapshot count",
|
||||
);
|
||||
const machineSessionState = uiDocument.defaultView.linuxCncIniPanelMachineSessionState;
|
||||
const machineSessionStateReport = uiDocument.defaultView.getMachineSessionStateReport();
|
||||
assertEqual(
|
||||
machineSessionState.lastAction,
|
||||
machineSessionStateReport.status.lastAction,
|
||||
"run-gcode",
|
||||
"UI machine session state last action",
|
||||
"UI machine session state report last action",
|
||||
);
|
||||
assertEqual(
|
||||
machineSessionState.selectedProgram.opfsPath,
|
||||
machineSessionStateReport.program.opfsPath,
|
||||
"linuxcnc/gcode/ui-session.ngc",
|
||||
"UI machine session state selected program OPFS path",
|
||||
"UI machine session state report selected program OPFS path",
|
||||
);
|
||||
assertEqual(
|
||||
machineSessionState.sessionLoad.iniWasmPath,
|
||||
machineSessionStateReport.loaded.iniWasmPath,
|
||||
"/work/session-machine.ini",
|
||||
"UI machine session state loaded INI WASM path",
|
||||
"UI machine session state report loaded INI WASM path",
|
||||
);
|
||||
assertEqual(
|
||||
machineSessionState.run.programSource,
|
||||
machineSessionStateReport.program.source,
|
||||
"snapshot",
|
||||
"UI machine session state run source",
|
||||
"UI machine session state report run source",
|
||||
);
|
||||
assertEqual(
|
||||
machineSessionState.fields.runWorkflow,
|
||||
machineSessionStateReport.session.workflow,
|
||||
"save-session-snapshot",
|
||||
"UI machine session state run workflow field",
|
||||
"UI machine session state report workflow",
|
||||
);
|
||||
assertEqual(
|
||||
machineSessionState.error,
|
||||
machineSessionStateReport.status.error,
|
||||
null,
|
||||
"UI machine session state error",
|
||||
"UI machine session state report error",
|
||||
);
|
||||
assertEqual(
|
||||
machineSessionStateReport.run.status,
|
||||
"ok",
|
||||
"UI machine session state report run status",
|
||||
);
|
||||
assertEqual(
|
||||
machineSessionStateReport.run.canonicalEventCount,
|
||||
2,
|
||||
"UI machine session state report canonical event count",
|
||||
);
|
||||
assertEqual(
|
||||
machineSessionStateReport.run.motionSnapshotCount,
|
||||
2,
|
||||
"UI machine session state report motion snapshot count",
|
||||
);
|
||||
if (
|
||||
!runLog.includes("canon_event=STRAIGHT_TRAVERSE") ||
|
||||
|
||||
Reference in New Issue
Block a user