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.
51 lines
2.8 KiB
TypeScript
51 lines
2.8 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { actionEntries, selectionRoots, setSelectedMarks, runTreeActions } from "../../../src/lib/workspace/treeActions.ts";
|
|
import { planDrop } from "../../../src/lib/workspace/treeDrop.ts";
|
|
import type { TreeEntry } from "../../../src/lib/workspace/types.ts";
|
|
|
|
const entry = (rel_path: string, kind: "file" | "folder" = "file"): TreeEntry => ({ rel_path, name: rel_path.split("/").pop()!, kind });
|
|
const entries = [entry("notes", "folder"), entry("notes/a.md"), entry("notes/sub", "folder"), entry("notes/sub/b.md"), entry("notes-old/c.md"), entry("z.md")];
|
|
const visible = entries.map(item => item.rel_path);
|
|
const find = (path: string) => entries.find(item => item.rel_path === path) ?? null;
|
|
|
|
test("context actions use all selected visible rows in display order", () => {
|
|
assert.deepEqual(actionEntries(entries[1], new Set(["z.md", "missing", "notes/a.md"]), visible, find), [entries[1], entries[5]]);
|
|
assert.deepEqual(actionEntries(entries[0], new Set(["z.md", "notes/a.md"]), visible, find), [entries[0]]);
|
|
});
|
|
|
|
test("recursive actions process each selected folder once without including similar names", () => {
|
|
assert.deepEqual(selectionRoots([...entries].reverse()), [entries[5], entries[4], entries[0]]);
|
|
assert.deepEqual(selectionRoots(entries.slice(1)), [entries[1], entries[2], entries[4], entries[5]]);
|
|
});
|
|
|
|
test("mixed marks become uniformly enabled or disabled and preserve other marks", () => {
|
|
const current = ["outside.md", "notes/a.md"];
|
|
const selection = [entries[1], entries[5]];
|
|
assert.deepEqual(setSelectedMarks(current, selection, true), ["outside.md", "notes/a.md", "z.md"]);
|
|
assert.deepEqual(setSelectedMarks(current, selection, false), ["outside.md"]);
|
|
assert.deepEqual(current, ["outside.md", "notes/a.md"]);
|
|
});
|
|
|
|
test("a failed action does not skip later items or lose successful results", async () => {
|
|
const visited: string[] = [];
|
|
const result = await runTreeActions(entries, async item => {
|
|
visited.push(item.rel_path);
|
|
if (item === entries[1]) throw new Error("Access denied");
|
|
return item.name;
|
|
});
|
|
assert.deepEqual(visited, visible);
|
|
assert.deepEqual(result.completed.map(item => item.entry), entries.filter(item => item !== entries[1]));
|
|
assert.deepEqual(result.failures, ["notes/a.md: Access denied"]);
|
|
});
|
|
|
|
test("moving beside an existing same-name file preserves both files in the destination order", () => {
|
|
const plan = planDrop("notes/a.md", entry("a.md"), "after", parent => parent === "notes" ? ["a.md"] : ["a.md", "z.md"]);
|
|
assert.equal(plan.action, "move");
|
|
if (plan.action === "move") {
|
|
assert.equal(plan.to, "a 2.md");
|
|
assert.deepEqual(plan.orderTo, ["a.md", "a 2.md", "z.md"]);
|
|
}
|
|
assert.deepEqual(planDrop("notes", entries[1], "before", () => []), { action: "noop" });
|
|
});
|