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

221 lines
7.7 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?.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,getLauncherLinks,getControlPageApiMethods",
"launch API manifest methods",
);
const shellIntegrationSchema = launchApi.getShellIntegrationSchema();
const shellIntegrationManifest = launchApi.getShellIntegrationManifest();
const shellIntegrationReadiness = launchApi.getShellIntegrationReadiness();
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(
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>