Files
RuneStone/tests/unit/layout/tabActions.spec.ts
T
Knotty Wyvern e433bed28e Move the tests from scripts/ to tests/ by feature
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.
2026-10-27 19:47:39 -07:00

47 lines
2.0 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { tabsToClose } from "../../../src/lib/workspace/tabActions.ts";
import { Documents } from "../../../src/lib/workspace/documents.ts";
function setup() {
return new Documents({
read: async () => "original", write: async () => {}, image: async () => "data:image/png;base64,",
kind: () => "text", chrome: () => "Writing",
}, () => {});
}
const entry = (path: string) => ({ rel_path: path, name: path, kind: "file" as const });
test("group closes follow tab order and preserve pins without changing the active tab", async () => {
const docs = setup();
for (const name of ["a.md", "b.md", "c.md", "d.md"]) await docs.open(entry(name));
docs.togglePin("b.md");
docs.move("d.md", 1);
const paths = (scope: "one" | "others" | "after" | "all") => tabsToClose(docs.buffers, "d.md", scope).map(tab => tab.relPath);
assert.deepEqual(paths("one"), ["d.md"]);
assert.deepEqual(paths("others"), ["a.md", "c.md"]);
assert.deepEqual(paths("after"), ["c.md"]);
assert.deepEqual(paths("all"), ["a.md", "d.md", "c.md"]);
assert.equal(docs.activePath, "d.md");
assert.deepEqual(tabsToClose(docs.buffers, "missing.md", "all"), []);
assert.equal(tabsToClose(docs.buffers, "b.md", "one")[0].pinned, true);
});
test("pinning protects current and empty tabs from replacement, and survives rename", async () => {
const docs = setup();
await docs.open(entry("a.md"));
docs.togglePin("a.md");
await docs.open(entry("b.md"), "current");
assert.deepEqual(docs.buffers.map(tab => tab.relPath), ["a.md", "b.md"]);
docs.rename("a.md", "renamed.md");
assert.equal(docs.buffers[0].pinned, true);
docs.newTab();
const blank = docs.active!;
docs.togglePin(blank.relPath);
await docs.open(entry("c.md"));
assert.ok(docs.buffers.includes(blank));
docs.select("renamed.md");
docs.togglePin("renamed.md");
await docs.open(entry("d.md"), "current");
assert.ok(!docs.buffers.some(tab => tab.relPath === "renamed.md"));
});