Skip to content

test: conformance tests for JSON Canvas spec + Canvas Candy baseline#29

Open
LeslieOA wants to merge 1 commit into
developfrom
chore/conformance-tests
Open

test: conformance tests for JSON Canvas spec + Canvas Candy baseline#29
LeslieOA wants to merge 1 commit into
developfrom
chore/conformance-tests

Conversation

@LeslieOA

Copy link
Copy Markdown
Member

Summary

Test count: 38 → 168 across 5 suites. Two new files, both pure additions — no source changes.

File Tests Covers
src/core/__tests__/spec-conformance.test.ts 75 Edge side × end matrix round-trip (64 combos), preset + hex colour preservation, full deep-equal on mixed documents, FileNode subpath, GroupNode background
src/renderer/extensions/__tests__/cssclasses.test.ts 55 hasCssClasses detection, frontmatter parsing variants, full Candy class → RenderProps mapping (shapes, fills, borders, text alignment, parametric), enrichNodes batch behaviour

Why this matters

  • JSON Canvas spec compliance is now exercised against every side/end combination an edge can carry, not just the spot-checked cases in the existing serialization.test.ts. Any regression that silently mutates an edge field or fabricates a default will fail loudly.
  • Canvas Candy baseline had zero test coverage before this. The mapping in cssclasses.ts is the spec for the entire community-convention feature; pinning every class → RenderProps mapping means a future refactor (or eventual Rust port) can't drift silently.
  • The new tests are also a contract: when Workspace's canvas-ui next adds a Candy class, the same test should appear here. Easy to spot in PR review.

What's deliberately NOT in this PR

Verification

  • npm test: 168/168, 5 suites
  • npm run typecheck: clean
  • npm run lint: exit 0

Independent of #27 and #28 — no overlapping files, can merge in any order.

Refs: #16

…loses #16)

Test count goes from 38/3 suites to 168/5 suites. Two new files:

1. src/core/__tests__/spec-conformance.test.ts
   - Edge side × end matrix round-trip: 4 (fromSide) × 4 (toSide) × 2
     (fromEnd) × 2 (toEnd) = 64 combinations, each round-tripped through
     parseCanvas / serializeCanvas with deep equality on the result
   - Edge with all-optional fields omitted — verifies we don't fabricate
     default values
   - All six JSON Canvas preset colour codes ('1' through '6') preserved
     verbatim through round-trip on both nodes and edges
   - Hex colour preserved verbatim through round-trip
   - Full structural deep-equal on a representative mixed-type document
   - FileNode subpath round-trip
   - GroupNode background / backgroundStyle round-trip

2. src/renderer/extensions/__tests__/cssclasses.test.ts
   - hasCssClasses detection: text node, plain text, `cssclass` alias,
     non-text-node ignore
   - Frontmatter parsing: array form, comma-separated string, single
     string, `cssclass` (singular) alias, whitespace trimming, empty
     handling, displayText extraction
   - Class → RenderProps mapping for every baseline class:
     shapes (cc-shape-circle, parallelogram-left/right, cc-border-squared)
     fills (cc-card-fill / -transparent / -opaque / -nocolor)
     borders (cc-border-none / -dashed / -dotted / -double / -rounded /
              -dropshadow, single-side, additive multi-side)
     text alignment (cc-card-center, cc-callout-center)
     parametric: gradient {N}deg, rotate-card {N}, rotate-text {N} and
                 trailing-l variant, non-matching pattern silently ignored
   - enrichNodes batch behaviour: non-text passthrough, plain-text
     reference-equality, frontmatter-but-no-cssclasses passthrough

Verified

- npm test: 168/168 across 5 suites
- npm run typecheck: clean
- npm run lint: exit 0

Notes

- Tests live under src/core/__tests__/ and src/renderer/extensions/__tests__/
  per jest.config.js's testMatch pattern. Co-locating Candy tests with the
  extension keeps the test surface organised by module.
- Did not test the new updateXxx operation variants from #5 (PR #27) — those
  land separately and will get their own round of tests post-merge.

Refs: #16

Co-Authored-By: Claude Opus 4.7 (1M context) <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