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.
77 lines
3.3 KiB
TypeScript
77 lines
3.3 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { planRename, planTitleRename, planMarkdownTitleRename, planDocumentTitleRename } from "../../../src/lib/workspace/renamePath.ts";
|
|
|
|
test("rename in a folder keeps the parent", () => {
|
|
assert.deepEqual(planRename("notes/a.md", "b.md"), {
|
|
action: "rename",
|
|
to: "notes/b.md",
|
|
});
|
|
});
|
|
|
|
test("same name is a no-op", () => {
|
|
assert.deepEqual(planRename("notes/a.md", "a.md"), { action: "noop" });
|
|
});
|
|
|
|
test("path separators are rejected", () => {
|
|
assert.deepEqual(planRename("notes/a.md", "foo/bar"), {
|
|
action: "error",
|
|
message: "Name cannot contain a path separator",
|
|
});
|
|
assert.deepEqual(planRename("notes/a.md", "foo\\bar"), {
|
|
action: "error",
|
|
message: "Name cannot contain a path separator",
|
|
});
|
|
});
|
|
|
|
test("empty name is rejected", () => {
|
|
assert.deepEqual(planRename("notes/a.md", " "), {
|
|
action: "error",
|
|
message: "Name is empty",
|
|
});
|
|
});
|
|
|
|
test("root file rename stays at the root", () => {
|
|
assert.deepEqual(planRename("inbox.md", "todo.md"), {
|
|
action: "rename",
|
|
to: "todo.md",
|
|
});
|
|
});
|
|
|
|
test("title rename keeps the existing extension", () => {
|
|
assert.deepEqual(planTitleRename("notes/inbox.md", "hello"), {
|
|
action: "rename",
|
|
to: "notes/hello.md",
|
|
});
|
|
assert.deepEqual(planTitleRename("notes/inbox.md", "inbox"), { action: "noop" });
|
|
});
|
|
|
|
test("title rename keeps a typed extension", () => {
|
|
assert.deepEqual(planTitleRename("notes/inbox.md", "hello.txt"), {
|
|
action: "rename",
|
|
to: "notes/hello.txt",
|
|
});
|
|
});
|
|
|
|
test("writing titles preserve Markdown extensions and allow dots in names", () => {
|
|
assert.deepEqual(planMarkdownTitleRename("notes/inbox.md", "Release 1.2"), { action: "rename", to: "notes/Release 1.2.md" });
|
|
assert.deepEqual(planMarkdownTitleRename("notes/inbox.MD", " Renamed.md "), { action: "rename", to: "notes/Renamed.MD" });
|
|
assert.deepEqual(planMarkdownTitleRename("inbox.markdown", "Renamed"), { action: "rename", to: "Renamed.markdown" });
|
|
assert.deepEqual(planMarkdownTitleRename("inbox.mdown", "Renamed"), { action: "rename", to: "Renamed.mdown" });
|
|
assert.deepEqual(planMarkdownTitleRename("notes/inbox.md", "inbox"), { action: "noop" });
|
|
assert.deepEqual(planMarkdownTitleRename("notes/inbox.md.md", "inbox.md"), { action: "noop" });
|
|
for (const name of ["", " ", ".md", "../escape", "folder/note", "folder\\note"]) {
|
|
assert.equal(planMarkdownTitleRename("notes/inbox.md", name).action, "error", name);
|
|
}
|
|
});
|
|
|
|
test("document names retain their format and cannot hide or move the file", () => {
|
|
assert.deepEqual(planDocumentTitleRename("Projects/Board.md", "Renamed"), { action: "rename", to: "Projects/Renamed.md" });
|
|
assert.deepEqual(planDocumentTitleRename("Projects/Board.md", "Release 1.2"), { action: "rename", to: "Projects/Release 1.2.md" });
|
|
assert.deepEqual(planDocumentTitleRename("Projects/Board.MD", "Renamed.md"), { action: "rename", to: "Projects/Renamed.MD" });
|
|
assert.deepEqual(planDocumentTitleRename("Report.pdf", "Next.pdf"), { action: "rename", to: "Next.pdf" });
|
|
assert.deepEqual(planDocumentTitleRename("Board.md", "Board"), { action: "noop" });
|
|
for (const name of ["", " ", ".md", ".hidden", "../escape", "folder/name", "folder\\name", "a:b", "a?b"])
|
|
assert.equal(planDocumentTitleRename("Board.md", name).action, "error", name);
|
|
});
|