Skip to content

test(fold): assert the duplicate-title fold behaviour instead of its spelling - #564

Merged
PathGao merged 1 commit into
masterfrom
test/foldkeys-behavior
Aug 10, 2026
Merged

test(fold): assert the duplicate-title fold behaviour instead of its spelling#564
PathGao merged 1 commit into
masterfrom
test/foldkeys-behavior

Conversation

@PathGao

@PathGao PathGao commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

What this is

The first slice of converting source-shape assertions into behaviour tests, following #563. Two test files change; no source file does.

  • foldKeys.test.ts — rewritten to run processMarkdownHtml instead of matching markdown.ts with regexes.
  • findRefocus.test.ts — deleted.

Mechanism

The old file asserted /h\.id = \w+\.id/ and removeAttribute("id") against markdown.ts. That is a claim about how the promotion is spelled, and it fails in both directions:

promotion deleted promotion extracted into a helper
old assertions red ✓ red ✗ — nothing broke
new assertions red ✓ green ✓

Both rows were measured, not reasoned about. The refactor in the right-hand column is four lines moved into function promoteAnchorId(h) above processMarkdownHtml; the whole suite stays green and the old assertion still goes red, because the text it was looking for moved.

The old file also could not see the part that matters. It checked that an id gets assigned, never that the ids stay unique afterwards — which is the reason the anchor gives its own up rather than sharing it.

None of this needed new infrastructure. processMarkdownHtml is exported from .ts, and renderProtocolDom.ts (the suite's DOM shim, already used by foldStatePerDocument, exportRichContent, diagramCache and three more) supplies the DOM it wants. The test document now contains the collision the feature exists for — two sections both titled Setup — and asserts that collapsing the first leaves the second open. Before the promotion, keyed by textContent, new Set(['setup']) collapsed both.

Scope

  • No source changes. The helper extraction above was an experiment to measure the false-red; it was reverted.
  • One source-shape assertion is kept on purpose, with the reason written next to it: the preview's foldableHeader.id || foldableHeader.textContent lives in a Svelte component this runner cannot import, and it is a contract between the producer and its consumers rather than an internal call site.
  • findRefocus.test.ts came in with fix(find): re-focus the preview find bar on a repeated Cmd/Ctrl+F #560 and was mine. It pinned findBar?.focusInput() — an internal call, free to rename, and green if the focus stops working. By the criterion docs: name the two kinds of test in scripts/, and ask which one a PR added #563 adds to the template it should not have been written; deleting it is cheaper than defending it.
  • The other 30 or so files that assert source shape are untouched. Most of them anchor on a genuine contract (a Tauri command name, a Tauri capability, version sync across package.json/Cargo.toml, a duplicated implementation) and should stay as they are.

Tests

The two behaviour tests are the fix check for themselves: delete the promotion block from markdown.ts and both go red; restore it and they pass. Ran both directions.

Verification

npm run check   # 674 files, 0 errors
npm test        # 942 pass, 0 fail  (944 before: 3 deleted with findRefocus, 4 added here, 1 net)

Not verified: nothing here reaches a browser, so the shim's fidelity to real classList/querySelector behaviour is taken on the same trust the five existing shim-based test files already take it on.

🤖 Generated with Claude Code

…spelling

`foldKeys.test.ts` matched markdown.ts for `/h\.id = \w+\.id/` and
`removeAttribute("id")`. Both are claims about how the promotion is
written, not that it works, and the file already shipped with the two
failure modes that come with that:

  * Extract the four lines into a `promoteAnchorId(h)` helper — same
    behaviour, every existing test still passing — and the assertion goes
    red. Measured, not argued.
  * Nothing in it looked at whether the promoted ids stay unique, which
    is the whole point of taking the id off the anchor.

`processMarkdownHtml` is an exported function in `.ts` and the suite
already has a DOM shim (`renderProtocolDom.ts`, used by
foldStatePerDocument and five others), so the behaviour can just be run.
The document under test now contains the collision the feature exists
for — two sections both titled "Setup" — and the check is that collapsing
the first leaves the second open. Keyed by text, as it was before the
promotion, `new Set(['setup'])` folds the whole document.

Deleting the promotion turns both new tests red. The helper-extraction
refactor above leaves them green.

One source-shape assertion is kept, and says why in place: the preview's
`foldableHeader.id || textContent` lives in a Svelte component this
runner cannot import, and the keying convention is a contract between
producer and consumers rather than an internal call site.

Also drops `findRefocus.test.ts` (#560, mine). It pinned
`findBar?.focusInput()` — an internal call, free to rename, and green if
the focus call stops working. By the criterion in the pull request
template it should not have been written.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant