Files
cnc_wams/wasm-port/tests/browser/ini_panel_launch_smoke.html

463 lines
17 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>LinuxCNC INI Launch Smoke</title>
</head>
<body>
<pre id="status">running</pre>
<script type="module">
import {
createControlPageBrowserApiMethods,
createIniPanelLaunchApiManifest,
createIniPanelLauncherLinkViewModel,
createIniPanelShellIntegrationManifest,
createIniPanelShellViewModel,
getIniPanelEntryByHref,
getVisibleIniPanelEntries,
} from "../../runtime/ui/ini-panel/ui-shell.js";
function assertEqual(actual, expected, label) {
if (actual !== expected) {
throw new Error(`${label}: expected ${expected}, got ${actual}`);
}
}
async function loadLaunchFrame() {
const frame = document.createElement("iframe");
frame.src = "../../runtime/ui/ini-panel/launch.html";
document.body.appendChild(frame);
await new Promise((resolve, reject) => {
frame.addEventListener("load", resolve, { once: true });
frame.addEventListener("error", reject, { once: true });
});
return frame.contentDocument;
}
try {
const visibleEntries = getVisibleIniPanelEntries();
assertEqual(visibleEntries.length, 2, "launch visible entry length");
const launcherLinks = createIniPanelLauncherLinkViewModel();
assertEqual(launcherLinks.length, 2, "launcher link model length");
assertEqual(launcherLinks[0].entryId, "edit-run", "launcher link entry id");
assertEqual(launcherLinks[0].label, "Open edit and run panel", "launcher link label");
assertEqual(launcherLinks[0].href, "./index.html", "launcher link href");
assertEqual(getIniPanelEntryByHref("./index.html").id, "edit-run", "launch manifest edit entry");
assertEqual(
getIniPanelEntryByHref("./control-page.html").title,
"Open read-only control view",
"launch manifest control entry",
);
assertEqual(
createIniPanelShellViewModel().controlPage.browserApiMethods.join(","),
createControlPageBrowserApiMethods().join(","),
"launch shell control-page browser API methods",
);
assertEqual(
createIniPanelShellViewModel().launchApiManifest.apiName,
"ini-panel-launch",
"launch shell API manifest name",
);
assertEqual(
createIniPanelShellViewModel().launchApiManifest.methods.join(","),
createIniPanelLaunchApiManifest().methods.join(","),
"launch shell API manifest methods",
);
const launchDoc = await loadLaunchFrame();
const launchApi = launchDoc.defaultView.linuxCncIniPanelLaunchApi;
if (
!launchApi?.isSupportedLaunchApiManifest ||
!launchApi?.getLaunchApiSchema ||
!launchApi?.getLaunchApiManifest ||
!launchApi?.getShellIntegrationSchema ||
!launchApi?.getShellIntegrationManifest ||
!launchApi?.getShellIntegrationReadiness ||
!launchApi?.getShellSessionHandoffSummarySchema ||
!launchApi?.getShellSessionHandoffSummary ||
!launchApi?.isSupportedShellSessionHandoffSummary ||
!launchApi?.getShellSessionHandoffCompatibilityReport ||
!launchApi?.getShellSessionHandoffDisplayViewModel ||
!launchApi?.getShellSessionHandoffSnapshot ||
!launchApi?.getShellSessionHandoffRenderState ||
!launchApi?.getShellSessionHandoffActionPlan ||
!launchApi?.getShellSessionHandoffChecklist ||
!launchApi?.getShellSessionHandoffPackageSchema ||
!launchApi?.getShellSessionHandoffPackage ||
!launchApi?.isSupportedShellSessionHandoffPackage ||
!launchApi?.getLauncherLinks ||
!launchApi?.getControlPageApiMethods
) {
throw new Error("launch API namespace did not expose shell helpers");
}
const launchApiSchema = launchApi.getLaunchApiSchema();
assertEqual(
launchApiSchema.manifestVersion,
1,
"launch API schema manifest version",
);
assertEqual(
launchApiSchema.fields.includes("persistenceCapabilities"),
true,
"launch API schema persistence field",
);
const launchApiManifest = launchApi.getLaunchApiManifest();
assertEqual(
launchApi.isSupportedLaunchApiManifest(launchApiManifest),
true,
"launch API supports manifest",
);
assertEqual(
launchApi.isSupportedLaunchApiManifest({ ...launchApiManifest, manifestVersion: 2 }),
false,
"launch API rejects unsupported manifest version",
);
assertEqual(
launchApiManifest.apiName,
"ini-panel-launch",
"launch API manifest name",
);
assertEqual(
launchApiManifest.manifestVersion,
1,
"launch API manifest version",
);
assertEqual(
launchApiManifest.methods.join(","),
"isSupportedLaunchApiManifest,getLaunchApiSchema,getLaunchApiManifest,getShellIntegrationSchema,getShellIntegrationManifest,getShellIntegrationReadiness,getShellSessionHandoffSummarySchema,getShellSessionHandoffSummary,isSupportedShellSessionHandoffSummary,getShellSessionHandoffCompatibilityReport,getShellSessionHandoffDisplayViewModel,getShellSessionHandoffSnapshot,getShellSessionHandoffRenderState,getShellSessionHandoffActionPlan,getShellSessionHandoffChecklist,getShellSessionHandoffPackageSchema,getShellSessionHandoffPackage,isSupportedShellSessionHandoffPackage,getLauncherLinks,getControlPageApiMethods",
"launch API manifest methods",
);
const shellIntegrationSchema = launchApi.getShellIntegrationSchema();
const shellIntegrationManifest = launchApi.getShellIntegrationManifest();
const shellIntegrationReadiness = launchApi.getShellIntegrationReadiness();
const shellSessionHandoffSummarySchema = launchApi.getShellSessionHandoffSummarySchema();
const shellSessionHandoffSummary = launchApi.getShellSessionHandoffSummary();
const shellSessionHandoffCompatibilityReport = launchApi.getShellSessionHandoffCompatibilityReport();
const shellSessionHandoffDisplayViewModel = launchApi.getShellSessionHandoffDisplayViewModel();
const shellSessionHandoffSnapshot = launchApi.getShellSessionHandoffSnapshot();
const shellSessionHandoffRenderState = launchApi.getShellSessionHandoffRenderState();
const shellSessionHandoffActionPlan = launchApi.getShellSessionHandoffActionPlan();
const shellSessionHandoffChecklist = launchApi.getShellSessionHandoffChecklist();
const shellSessionHandoffPackageSchema = launchApi.getShellSessionHandoffPackageSchema();
const shellSessionHandoffPackage = launchApi.getShellSessionHandoffPackage();
assertEqual(
shellIntegrationSchema.manifestVersion,
1,
"shell integration schema manifest version",
);
assertEqual(
shellIntegrationManifest.apiName,
"ini-panel-shell-integration",
"shell integration manifest API name",
);
assertEqual(
shellIntegrationManifest.compatibility.launchApiManifest,
true,
"shell integration launch compatibility",
);
assertEqual(
shellIntegrationManifest.compatibility.controlPageApiManifest,
true,
"shell integration control-page compatibility",
);
assertEqual(
shellIntegrationManifest.controlPageApiManifest.apiName,
"ini-panel-control-page",
"shell integration control-page manifest name",
);
assertEqual(
shellIntegrationReadiness.ready,
true,
"shell integration readiness",
);
assertEqual(
shellIntegrationReadiness.counts.persistenceCapabilities,
3,
"shell integration readiness capability count",
);
assertEqual(
shellIntegrationReadiness.missing.join(","),
"",
"shell integration readiness missing checks",
);
assertEqual(
shellSessionHandoffSummary.ready,
true,
"shell session handoff summary readiness",
);
assertEqual(
shellSessionHandoffSummarySchema.summaryVersion,
1,
"shell session handoff summary schema version",
);
assertEqual(
launchApi.isSupportedShellSessionHandoffSummary(shellSessionHandoffSummary),
true,
"shell session handoff summary supported",
);
assertEqual(
launchApi.isSupportedShellSessionHandoffSummary({ ...shellSessionHandoffSummary, summaryVersion: 2 }),
false,
"shell session handoff summary rejects version",
);
assertEqual(
shellSessionHandoffCompatibilityReport.compatible,
true,
"shell session handoff compatibility report",
);
assertEqual(
shellSessionHandoffCompatibilityReport.summarySupported,
true,
"shell session handoff summary support report",
);
assertEqual(
shellSessionHandoffCompatibilityReport.missingFields.join(","),
"",
"shell session handoff compatibility missing fields",
);
assertEqual(
shellSessionHandoffDisplayViewModel.statusText,
"Ready",
"shell session handoff display status",
);
assertEqual(
shellSessionHandoffDisplayViewModel.rows.length,
5,
"shell session handoff display rows",
);
assertEqual(
shellSessionHandoffSnapshot.snapshotVersion,
1,
"shell session handoff snapshot version",
);
assertEqual(
shellSessionHandoffSnapshot.ready,
true,
"shell session handoff snapshot readiness",
);
assertEqual(
shellSessionHandoffRenderState.renderStateVersion,
1,
"shell session handoff render-state version",
);
assertEqual(
shellSessionHandoffRenderState.ready,
true,
"shell session handoff render-state readiness",
);
assertEqual(
shellSessionHandoffRenderState.statusLine,
"Ready: No blocking reasons",
"shell session handoff render-state status",
);
assertEqual(
shellSessionHandoffActionPlan.planVersion,
1,
"shell session handoff action-plan version",
);
assertEqual(
shellSessionHandoffActionPlan.ready,
true,
"shell session handoff action-plan readiness",
);
assertEqual(
shellSessionHandoffActionPlan.nextSteps.map(({ id }) => id).join(","),
"open-control-page,read-readonly-status",
"shell session handoff action-plan next steps",
);
assertEqual(
shellSessionHandoffActionPlan.requiredMethods.readStatus,
"readControlPageStatus",
"shell session handoff action-plan read method",
);
assertEqual(
shellSessionHandoffChecklist.checklistVersion,
1,
"shell session handoff checklist version",
);
assertEqual(
shellSessionHandoffChecklist.ready,
true,
"shell session handoff checklist readiness",
);
assertEqual(
shellSessionHandoffChecklist.checks.map(({ status }) => status).join(","),
"pass,pass,pass,pass,pass",
"shell session handoff checklist checks",
);
assertEqual(
shellSessionHandoffChecklist.nextStepIds.join(","),
"open-control-page,read-readonly-status",
"shell session handoff checklist next step ids",
);
assertEqual(
shellSessionHandoffPackage.packageVersion,
1,
"shell session handoff package version",
);
assertEqual(
shellSessionHandoffPackageSchema.packageVersion,
1,
"shell session handoff package schema version",
);
assertEqual(
launchApi.isSupportedShellSessionHandoffPackage(shellSessionHandoffPackage),
true,
"shell session handoff package supported",
);
assertEqual(
launchApi.isSupportedShellSessionHandoffPackage({ ...shellSessionHandoffPackage, packageVersion: 2 }),
false,
"shell session handoff package rejects version",
);
assertEqual(
shellSessionHandoffPackage.ready,
true,
"shell session handoff package readiness",
);
assertEqual(
shellSessionHandoffPackage.manifests.launchMethods.includes("getShellSessionHandoffPackage"),
true,
"shell session handoff package launch methods",
);
assertEqual(
shellSessionHandoffPackage.manifests.controlPageMethods.includes("readControlPageStatus"),
true,
"shell session handoff package control methods",
);
assertEqual(
JSON.stringify(shellSessionHandoffSnapshot.readiness),
JSON.stringify(shellIntegrationReadiness),
"shell session handoff snapshot readiness object",
);
assertEqual(
JSON.stringify(shellSessionHandoffSnapshot.summary),
JSON.stringify(shellSessionHandoffSummary),
"shell session handoff snapshot summary object",
);
assertEqual(
JSON.stringify(shellSessionHandoffSnapshot.displayViewModel),
JSON.stringify(shellSessionHandoffDisplayViewModel),
"shell session handoff snapshot display object",
);
assertEqual(
JSON.stringify(shellSessionHandoffRenderState.rows),
JSON.stringify(shellSessionHandoffDisplayViewModel.rows),
"shell session handoff render-state rows",
);
assertEqual(
JSON.stringify(shellSessionHandoffActionPlan.displayRows),
JSON.stringify(shellSessionHandoffRenderState.rows),
"shell session handoff action-plan rows",
);
assertEqual(
JSON.stringify(shellSessionHandoffChecklist.displayRows),
JSON.stringify(shellSessionHandoffRenderState.rows),
"shell session handoff checklist rows",
);
assertEqual(
JSON.stringify(shellSessionHandoffPackage.checklist),
JSON.stringify(shellSessionHandoffChecklist),
"shell session handoff package checklist",
);
assertEqual(
launchDoc.querySelector("[data-handoff-status]").textContent,
"Ready: No blocking reasons",
"shell session handoff DOM status",
);
assertEqual(
launchDoc.querySelector("[data-handoff-shell]").dataset.handoffPhase,
"ready",
"shell session handoff DOM phase",
);
assertEqual(
launchDoc.querySelector("[data-handoff-shell]").dataset.handoffReady,
"true",
"shell session handoff DOM ready",
);
assertEqual(
launchDoc.querySelector('[data-handoff-value="missing-fields"]').textContent,
"none",
"shell session handoff DOM missing fields",
);
assertEqual(
launchDoc.querySelector('[data-handoff-value="blocking-reasons"]').textContent,
"none",
"shell session handoff DOM blocking reasons",
);
assertEqual(
shellSessionHandoffSummary.targetPage.href,
"./control-page.html",
"shell session handoff summary target",
);
assertEqual(
shellSessionHandoffSummary.readonlyStatusFields.includes("session"),
true,
"shell session handoff summary readonly fields",
);
assertEqual(
shellSessionHandoffSummary.persistenceCapabilities.length,
3,
"shell session handoff summary persistence capabilities",
);
assertEqual(
JSON.stringify(shellIntegrationManifest),
JSON.stringify(createIniPanelShellIntegrationManifest()),
"shell integration manifest",
);
assertEqual(
launchApiManifest.visibleEntries.length,
2,
"launch API manifest visible entry count",
);
assertEqual(
launchApiManifest.targetPages[1].href,
"./control-page.html",
"launch API manifest control target",
);
assertEqual(
launchApiManifest.persistenceCapabilities.length,
3,
"launch API manifest persistence capability count",
);
assertEqual(
launchApiManifest.persistenceCapabilities.map((capability) => capability.id).join(","),
"machine-files,session-snapshot,readonly-status",
"launch API manifest persistence capability ids",
);
assertEqual(
launchApiManifest.persistenceCapabilities[2].scope,
"control-page",
"launch API manifest readonly status scope",
);
assertEqual(
launchDoc.querySelector('a[href="./index.html"]').textContent,
"Open edit and run panel",
"launch panel edit link",
);
assertEqual(
launchDoc.querySelector('a[href="./control-page.html"]').textContent,
"Open read-only control view",
"launch panel control link",
);
assertEqual(
launchApi.getLauncherLinks().length,
2,
"launch API launcher link count",
);
assertEqual(
launchApi.getControlPageApiMethods().join(","),
createControlPageBrowserApiMethods().join(","),
"launch API control-page browser methods",
);
status.textContent = "browser_ini_launch_smoke=ok";
console.log("browser_ini_launch_smoke=ok");
} catch (error) {
status.textContent = `browser_ini_launch_smoke=failed: ${error.message}`;
console.error(error);
throw error;
}
</script>
</body>
</html>