Unit tests go to tests/unit/<area>/, browser smoke tests to tests/smoke/<area>/, and tests against a running desktop app to tests/native/. Files named after dates, work passes, or Kanban cards get feature names, for example editorOctober12 -> editor/footnotes. scripts/ keeps the build, release, and package tools. Plugin repositories import scripts/packagePlugin.mjs, and the Terminal smoke test imports scripts/pluginMocks.mjs, which now re-exports the harness copy. The unit tests get their own type check (tests/tsconfig.json) with Node types. pnpm check runs it after the app check. Add @types/node and fix the three test mocks that it reported.
58 lines
3.0 KiB
TypeScript
58 lines
3.0 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { initialDocumentPanes, syncDocumentPanes, splitDocumentPane, closeDocumentPane, selectPane, readDocumentPane } from "../../../src/lib/workspace/documentPanes.ts";
|
|
import { paneBounds } from "../../../src/lib/workspace/splitLayout.ts";
|
|
import { registerSelection, selectedEditorText } from "../../../src/lib/editor/selection.ts";
|
|
|
|
test("opening a link to the right keeps its source and focuses an existing pane for duplicate targets", () => {
|
|
let state = syncDocumentPanes(initialDocumentPanes(), ["a", "b", "c"], "a");
|
|
const primary = state.active;
|
|
state = readDocumentPane(state, primary, true);
|
|
state = splitDocumentPane(state, primary, "b", "right");
|
|
assert.deepEqual(state.panes.map(pane => pane.documentId), ["a", "b"]);
|
|
assert.equal(state.active, "right");
|
|
assert.deepEqual(paneBounds(state.layout).right, { left: 50, top: 0, width: 50, height: 100 });
|
|
state = splitDocumentPane(state, "right", "a", "unused");
|
|
assert.equal(state.active, primary);
|
|
assert.equal(state.panes.length, 2);
|
|
assert.equal(state.panes[0].reading, true);
|
|
state = splitDocumentPane(state, "right", "c", "third");
|
|
assert.equal(paneBounds(state.layout).third.left, 75);
|
|
});
|
|
|
|
test("closing a split preserves the remaining pane and a later tab selection can restore its hidden document", () => {
|
|
let state = syncDocumentPanes(initialDocumentPanes(), ["a", "b"], "a");
|
|
state = splitDocumentPane(state, state.active, "b", "right");
|
|
state = closeDocumentPane(state, "right");
|
|
assert.equal(state.panes[0].documentId, "a");
|
|
assert.equal(state.layout, state.active);
|
|
state = syncDocumentPanes(state, ["a", "b"], "b");
|
|
assert.equal(state.panes[0].documentId, "b");
|
|
});
|
|
|
|
test("tab replacement stays in its focused pane, and closing another tab collapses only its empty pane", () => {
|
|
let state = syncDocumentPanes(initialDocumentPanes(), ["a", "b"], "a");
|
|
state = splitDocumentPane(state, state.active, "b", "right");
|
|
state = syncDocumentPanes(state, ["a", "c"], "c");
|
|
assert.deepEqual(state.panes.map(pane => pane.documentId), ["a", "c"]);
|
|
assert.equal(state.active, "right");
|
|
const unchanged = syncDocumentPanes(state, ["a", "c"], "c");
|
|
assert.equal(unchanged, state);
|
|
state = syncDocumentPanes(state, ["c"], "c");
|
|
assert.equal(state.panes.length, 1);
|
|
assert.equal(state.layout, "right");
|
|
assert.equal(selectPane(state, "missing"), state);
|
|
});
|
|
|
|
test("selection readers remain available in both panes and disposal cannot clear a replacement reader", () => {
|
|
const first = registerSelection("a", () => "first selection");
|
|
const second = registerSelection("b", () => "second selection");
|
|
assert.equal(selectedEditorText("a"), "first selection");
|
|
assert.equal(selectedEditorText("b"), "second selection");
|
|
const replacement = registerSelection("a", () => "new selection");
|
|
first(); second();
|
|
assert.equal(selectedEditorText("a"), "new selection");
|
|
assert.equal(selectedEditorText("b"), "");
|
|
replacement();
|
|
});
|