38 lines
2.2 KiB
JavaScript
38 lines
2.2 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 "../../node_modules/typescript/lib/typescript.js";
|
|
|
|
const root = path.resolve(import.meta.dirname, "../../..");
|
|
const sourcePath = path.join(root, "web/protocol/input-modal.ts");
|
|
const output = ts.transpileModule(fs.readFileSync(sourcePath, "utf8"), { compilerOptions: { module: ts.ModuleKind.ES2022, target: ts.ScriptTarget.ES2022 }, fileName: sourcePath, reportDiagnostics: true });
|
|
assert.deepEqual(output.diagnostics, []);
|
|
const modal = await import(`data:text/javascript;base64,${Buffer.from(output.outputText).toString("base64")}`);
|
|
|
|
test("M14-04F cancels touch modal without commit and starts one two-finger navigation revision", () => {
|
|
let state = modal.createInputModalState();
|
|
state = modal.beginTouch(state, 4);
|
|
state = modal.beginTouch(state, 2);
|
|
assert.deepEqual([state.kind, state.activePointerIds, state.navigationRevision, state.mainCommitCount], ["TOUCH_NAVIGATION", [2, 4], 1, 0]);
|
|
state = modal.cancelInputModal(state);
|
|
assert.deepEqual([state.kind, state.activePointerIds, state.cancelled, state.mainCommitCount], ["NONE", [], true, 0]);
|
|
});
|
|
|
|
test("M14-04F commits pen stroke once and ignores late up/cancel", () => {
|
|
let state = modal.beginPenStroke(modal.createInputModalState(), 9);
|
|
state = modal.commitPenStroke(state, 9);
|
|
state = modal.commitPenStroke(state, 9);
|
|
assert.deepEqual([state.kind, state.mainCommitCount, state.activePointerIds], ["NONE", 1, []]);
|
|
});
|
|
|
|
test("M14-04F reduces production pointer events and rejects invalid IDs", () => {
|
|
let state = modal.createInputModalState();
|
|
state = modal.reduceInputModal(state, { type: "pointerdown", pointerType: "touch", pointerId: 2 });
|
|
state = modal.reduceInputModal(state, { type: "pointerdown", pointerType: "touch", pointerId: 4 });
|
|
assert.equal(state.navigationRevision, 1);
|
|
state = modal.reduceInputModal(state, { type: "pointercancel", pointerType: "touch", pointerId: 2 });
|
|
assert.deepEqual([state.kind, state.activePointerIds, state.cancelled], ["NONE", [], true]);
|
|
assert.throws(() => modal.reduceInputModal(state, { type: "pointerdown", pointerType: "pen", pointerId: -1 }), /POINTER_ID_INVALID/);
|
|
});
|