Files
RuneStone/tests/unit/links/headingLinks.spec.ts
T
Knotty Wyvern f32f60b540 Add a workspace session for marks, renames, the index, and events
Phase 4d. session.svelte.ts holds the workspace state of each window:
the marks, the note index, renames, and typed change events. It
replaces refreshToken.

- One rename path: session.rename serves the tree, the note title, the
  rename command, the link menu, plugins, and the template manager.
  Open documents, plugin views, the index, and the marks follow it.
  A title rename, the rename command, and a plugin rename now also
  move pins and bookmarks.
- marksStore.svelte.ts is the only writer of .runestone/marks.json.
  Changes run in order from the latest marks. A change from another
  window reloads the marks.
- The note index updates only the paths that change, does not rescan
  on window focus, reads in batches of 64, and keeps links, not text.
- Plugins also hear about .runestone/ changes from other windows.
- The outline uses the heading parser of heading links and Read, so
  lines in code blocks are no longer headings.
- New note is above New file in the tree menu (card a6032af5).
- New workspace/session smoke test and new unit tests for the index
  and the outline.

pnpm check, pnpm test (347 of 347), and the full smoke suite pass,
except workspace/manageTemplates, which failed one time under load and
passed on retry and 4 of 4 times alone.
2026-10-28 11:28:54 -07:00

29 lines
1.5 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { documentHeadings, headingLinkLine, linkFragment } from "../../../src/lib/workspace/headingLinks.ts";
test("section links decode fragments without changing the file path", () => {
assert.equal(linkFragment("notes/a%23b.md#Caf%C3%A9%20setup"), "Café setup");
assert.equal(linkFragment("#literal%"), "literal%");
assert.equal(linkFragment("a.md"), null);
assert.equal(headingLinkLine("# Title", ""), 1);
});
test("headings use rendered text, Unicode, and unique slugs", () => {
const source = "# **Windows** setup!\n\n## Café `setup`\n\n## Windows setup!\n\n## Windows setup-1\n\n## Windows setup!\n";
assert.deepEqual(documentHeadings(source).map(({ slug }) => slug),
["windows-setup", "café-setup", "windows-setup-1", "windows-setup-1-1", "windows-setup-2"]);
assert.equal(headingLinkLine(source, "windows-setup-2"), 9);
assert.equal(headingLinkLine(source, "Café setup"), 3);
assert.equal(headingLinkLine(source, "missing"), null);
});
test("section lines exclude properties and code, and include Setext headings", () => {
const source = "---\r\ntitle: Test\r\n---\r\n\r\n```md\r\n# Fake\r\n```\r\n\r\nInstall\r\n=======\r\n\r\n## Real ###\r\n";
assert.deepEqual(documentHeadings(source), [
{ level: 1, text: "Install", slug: "install", line: 9 },
{ level: 2, text: "Real", slug: "real", line: 12 },
]);
assert.equal(headingLinkLine(source, "fake"), null);
});