推进 INI 面板 readonly status API

This commit is contained in:
2026-06-15 05:40:41 +08:00
parent deb8b7cdd3
commit 3280f3a53e
11 changed files with 302 additions and 1 deletions

View File

@@ -87,6 +87,21 @@ panelFrame.contentWindow = { linuxCncIniPanelApi: panelApi };
assert.equal(controller.getPanelApi(), panelApi);
assert.equal(controller.getControlView(), expectedView);
assert.deepEqual(controller.readStatus(), {
stateBundle: expectedStateBundle,
workflowStatus: expectedWorkflowStatus,
overview: null,
controlView: expectedView,
report: expectedStateBundle.report,
runReadiness: null,
run: null,
session: null,
status: {
lastAction: "run-gcode",
error: null,
runStatus: null,
},
});
assert.deepEqual(controller.loadSessionState(), {
phase: "ready",
panelReady: true,

View File

@@ -9,7 +9,9 @@ import {
createControlPageSessionLoadState,
createIniPanelLauncherLinkViewModel,
createIniPanelShellViewModel,
createMachineSessionReadonlyStatus,
loadMachineSessionForControlPageWorkflow,
readMachineSessionReadonlyStatus,
refreshMachineSessionControlPage,
getVisibleIniPanelEntries,
} from "../../../runtime/ui/ini-panel/ui-shell.js";
@@ -36,7 +38,9 @@ const requiredShellExports = [
"getIniPanelEntryByHref",
"getVisibleIniPanelEntries",
"createMachineSessionControlPageController",
"createMachineSessionReadonlyStatus",
"loadMachineSessionForControlPageWorkflow",
"readMachineSessionReadonlyStatus",
"refreshMachineSessionControlPage",
"renderMachineSessionControlView",
];
@@ -96,7 +100,9 @@ assert.deepEqual(createControlPageSessionLoadState({ phase: "waiting-panel" }),
error: null,
});
assert.equal(typeof createIniPanelShellViewModel().controlPage.createController, "function");
assert.equal(typeof createMachineSessionReadonlyStatus, "function");
assert.equal(createIniPanelShellViewModel().controlPage.loadSessionState, loadMachineSessionForControlPageWorkflow);
assert.equal(createIniPanelShellViewModel().controlPage.readStatus, readMachineSessionReadonlyStatus);
assert.equal(createIniPanelShellViewModel().controlPage.refresh, refreshMachineSessionControlPage);
assert.equal(typeof createIniPanelShellViewModel().controlPage.renderView, "function");

View File

@@ -0,0 +1,116 @@
import assert from "node:assert/strict";
import {
createMachineSessionReadonlyStatus,
readMachineSessionReadonlyStatus,
} from "../../../runtime/ui/ini-panel/readonly-status-api.js";
const stateBundle = {
overview: {
phase: "ran",
status: {
lastAction: "run-gcode",
error: null,
},
},
report: {
session: {
snapshotLabel: "ui-machine-session/ui-machine-session.json",
},
runReadiness: {
phase: "ready",
canRun: true,
},
run: {
status: "ok",
canonicalEventCount: 2,
},
},
};
const workflowStatus = {
overview: stateBundle.overview,
runReadiness: stateBundle.report.runReadiness,
session: stateBundle.report.session,
run: stateBundle.report.run,
lastAction: "run-gcode",
error: null,
};
const controlView = {
status: {
lastAction: "run-gcode",
runStatus: "ok",
error: null,
},
};
assert.deepEqual(
createMachineSessionReadonlyStatus({
stateBundle,
workflowStatus,
controlView,
}),
{
stateBundle,
workflowStatus,
overview: stateBundle.overview,
controlView,
report: stateBundle.report,
runReadiness: stateBundle.report.runReadiness,
run: stateBundle.report.run,
session: stateBundle.report.session,
status: {
lastAction: "run-gcode",
error: null,
runStatus: "ok",
},
},
);
assert.deepEqual(createMachineSessionReadonlyStatus(), {
stateBundle: null,
workflowStatus: null,
overview: null,
controlView: null,
report: null,
runReadiness: null,
run: null,
session: null,
status: {
lastAction: null,
error: null,
runStatus: null,
},
});
const panelApi = {
getMachineSessionStateBundle: () => stateBundle,
getMachineSessionWorkflowStatus: () => workflowStatus,
};
assert.deepEqual(
readMachineSessionReadonlyStatus({
getPanelApi: () => panelApi,
getControlView: () => controlView,
}),
createMachineSessionReadonlyStatus({
stateBundle,
workflowStatus,
controlView,
}),
);
assert.deepEqual(
readMachineSessionReadonlyStatus({
getPanelApi: () => null,
getControlView: () => null,
}),
createMachineSessionReadonlyStatus(),
);
assert.throws(
() => readMachineSessionReadonlyStatus({ getControlView: () => null }),
/panel API getter/,
);
assert.throws(
() => readMachineSessionReadonlyStatus({ getPanelApi: () => panelApi }),
/control view getter/,
);
console.log("ini_panel_readonly_status_api_node_smoke=ok");

View File

@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")/../../.." && pwd)"
node "$ROOT_DIR/tests/ui/node/verify_ini_panel_readonly_status_api.mjs"

View File

@@ -5,6 +5,7 @@ import {
controlPageStatusText,
createIniPanelLauncherLinkViewModel,
createIniPanelShellViewModel,
createMachineSessionReadonlyStatus,
createControlPageRefreshState,
createControlPageSessionLoadState,
createMachineSessionControlPageController,
@@ -12,6 +13,7 @@ import {
getIniPanelEntryManifest,
getVisibleIniPanelEntries,
loadMachineSessionForControlPageWorkflow,
readMachineSessionReadonlyStatus,
refreshMachineSessionControlPage,
renderMachineSessionControlView,
} from "../../../runtime/ui/ini-panel/ui-shell.js";
@@ -38,7 +40,9 @@ assert.deepEqual(createControlPageSessionLoadState({ phase: "waiting-panel" }),
});
assert.equal(getIniPanelEntryByHref("./index.html")?.id, "edit-run");
assert.equal(typeof createMachineSessionControlPageController, "function");
assert.equal(typeof createMachineSessionReadonlyStatus, "function");
assert.equal(typeof loadMachineSessionForControlPageWorkflow, "function");
assert.equal(typeof readMachineSessionReadonlyStatus, "function");
assert.equal(typeof refreshMachineSessionControlPage, "function");
assert.equal(typeof renderMachineSessionControlView, "function");
@@ -79,6 +83,7 @@ assert.deepEqual(shellViewModel.pages, [
assert.deepEqual(shellViewModel.launcherLinks, createIniPanelLauncherLinkViewModel());
assert.equal(shellViewModel.controlPage.createController, createMachineSessionControlPageController);
assert.equal(shellViewModel.controlPage.loadSessionState, loadMachineSessionForControlPageWorkflow);
assert.equal(shellViewModel.controlPage.readStatus, readMachineSessionReadonlyStatus);
assert.equal(shellViewModel.controlPage.refresh, refreshMachineSessionControlPage);
assert.equal(shellViewModel.controlPage.renderView, renderMachineSessionControlView);
shellViewModel.pages[0].title = "changed";
@@ -96,6 +101,18 @@ const panelFrame = {
},
sections: [],
}),
getMachineSessionStateBundle: () => ({
overview: {
phase: "ran",
},
}),
getMachineSessionWorkflowStatus: () => ({
overview: {
phase: "ran",
},
lastAction: "run-gcode",
error: null,
}),
},
},
addEventListener() {},
@@ -116,6 +133,7 @@ const controller = createMachineSessionControlPageController({
assert.deepEqual(controller.render(), { rendered: true });
assert.equal(statusNode.textContent, "run-gcode | ok | -");
assert.equal(renderedView.status.runStatus, "ok");
assert.equal(controller.readStatus().overview.phase, "ran");
assert.equal(controller.loadSessionState().phase, "ready");
assert.equal(controller.refresh().phase, "rendered");

View File

@@ -12,6 +12,7 @@ ROOT_DIR="$(cd "$(dirname "$0")/../../.." && pwd)"
"$ROOT_DIR/tests/ui/node/verify_ini_panel_control_page_controller.sh"
"$ROOT_DIR/tests/ui/node/verify_ini_panel_control_page_refresh_workflow.sh"
"$ROOT_DIR/tests/ui/node/verify_ini_panel_control_page_session_workflow.sh"
"$ROOT_DIR/tests/ui/node/verify_ini_panel_readonly_status_api.sh"
"$ROOT_DIR/tests/ui/node/verify_ini_panel_entry_manifest.sh"
"$ROOT_DIR/tests/ui/node/verify_ini_panel_ui_shell.sh"
"$ROOT_DIR/tests/ui/node/verify_ini_panel_entry_docs.sh"