36 lines
1.7 KiB
JavaScript
36 lines
1.7 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import test from "node:test";
|
|
import ts from "typescript";
|
|
|
|
const repoRoot = path.resolve(import.meta.dirname, "../../..");
|
|
const sourcePath = path.join(repoRoot, "web/protocol/ui-schema.ts");
|
|
const transpiled = ts.transpileModule(fs.readFileSync(sourcePath, "utf8"), {
|
|
compilerOptions: { module: ts.ModuleKind.ES2022, target: ts.ScriptTarget.ES2022 },
|
|
fileName: sourcePath,
|
|
reportDiagnostics: true,
|
|
});
|
|
assert.deepEqual(transpiled.diagnostics, []);
|
|
const moduleUrl = "data:text/javascript;base64," + Buffer.from(transpiled.outputText).toString("base64");
|
|
const { createDefaultWebWorkspaceState, reduceUICommand } = await import(moduleUrl);
|
|
|
|
test("M7-13 menu and modal overlays are mutually exclusive and Escape-closeable", () => {
|
|
let state = createDefaultWebWorkspaceState();
|
|
state = reduceUICommand(state, { type: "toggleMenu", menu: "文件" });
|
|
assert.equal(state.openMenu, "文件");
|
|
assert.equal(state.operatorSearchOpen, false);
|
|
state = reduceUICommand(state, { type: "toggleMenu", menu: "编辑" });
|
|
assert.equal(state.openMenu, "编辑");
|
|
assert.equal(state.operatorSearchOpen, false);
|
|
state = reduceUICommand(state, { type: "toggleOperatorSearch", open: true });
|
|
assert.equal(state.operatorSearchOpen, true);
|
|
assert.equal(state.openMenu, null);
|
|
state = reduceUICommand(state, { type: "toggleOperatorSearch", open: false });
|
|
assert.equal(state.operatorSearchOpen, false);
|
|
state = reduceUICommand(state, { type: "toggleMenu", menu: "窗口" });
|
|
assert.equal(state.openMenu, "窗口");
|
|
state = reduceUICommand(state, { type: "toggleMenu", menu: "窗口" });
|
|
assert.equal(state.openMenu, null);
|
|
});
|