nanobot-voice-interface/scripts/check_card_runtime_fixture.mjs
kacper 4dfb7ca3cc
Some checks failed
CI / Backend Checks (push) Failing after 36s
CI / Frontend Checks (push) Failing after 40s
feat: unify card runtime and event-driven web ui
2026-04-06 15:42:53 -04:00

57 lines
1.3 KiB
JavaScript

import assert from "node:assert/strict";
import { mount } from "./card_runtime_fixture_card.mjs";
function createFakeRoot() {
return {
dataset: {},
innerHTML: "",
};
}
async function main() {
const root = createFakeRoot();
const liveContentCalls = [];
const refreshHandlers = [];
const host = {
setLiveContent(value) {
liveContentCalls.push(value);
},
setRefreshHandler(handler) {
refreshHandlers.push(handler);
},
};
const mounted = mount({
root,
state: { title: "alpha" },
host,
});
assert.equal(typeof mounted?.update, "function");
assert.equal(typeof mounted?.destroy, "function");
assert.match(root.innerHTML, /alpha/);
assert.deepEqual(liveContentCalls.at(-1), { phase: "mount", title: "alpha" });
assert.equal(typeof refreshHandlers.at(-1), "function");
refreshHandlers.at(-1)?.();
assert.equal(root.dataset.refreshed, "1");
mounted.update({
root,
state: { title: "beta" },
host,
});
assert.match(root.innerHTML, /beta/);
assert.deepEqual(liveContentCalls.at(-1), { phase: "update", title: "beta" });
mounted.destroy();
assert.equal(root.innerHTML, "");
assert.equal(root.dataset.destroyed, "1");
assert.equal(refreshHandlers.at(-1), null);
console.log("card runtime fixture ok");
}
await main();