test(configurator): cover previewResolver.svelte.ts and save-error state (SL-023, PR7) - #481
Conversation
…s save-error state SL-023 continuation, the last item in the remediation plan's PR7. Two real gaps remained after PR4/PR5/PR6 merged and the earlier batch's persistence.ts/SliderRow/TokenRow coverage: - previewResolver.svelte.ts had zero test coverage. Added tests/previewResolver.test.js covering registerPreviewDoc/getActiveTheme, resolveColor/resolveColorForTheme's per-expression and per-theme caching, resolveRgb/resolveBackground's no-preview-doc fallbacks, and — closing the loop on PR6's SL-020 rAF-coalescing — that bumpPreviewVersion() reliably invalidates the cache and is safe to call repeatedly (a pure counter, no reactive loop). Uses a real <iframe>'s contentDocument rather than a detached document, since jsdom's getComputedStyle only resolves colors on documents with a defaultView — matching how PreviewPanel.svelte registers a real iframe in production. - StudioHeader's 'error' saveState (added by SL-018 in an earlier batch) had no test coverage of its own. Added a save-state describe block to tests-components/header.test.js covering all four states (idle/saving/saved/error), specifically that a failed save surfaces a distinct title/label from a fresh save and stays clickable to retry, while an in-progress retry is still correctly disabled. Corrected the file's baseProps fixture, which was missing hasPendingChanges/saveState/onSave (present since SL-018 but never added to this test file). Verified: npm run test:unit (89/89), npm run test:components (23/23), npm run test (112/112 combined), npx tsc --noEmit, npx svelte-check (0 errors/warnings), npm run build, and a real-browser e2e smoke pass against a built preview server (5/6 — the 1 failure is the same pre-existing /favicon.ico 404 noted in PR5/PR6, unrelated).
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoTests: add coverage for previewResolver cache/invalidation and StudioHeader save-error
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
Context used✅ Compliance rules (platform):
6 rules 1.
|
…est from environment
Qodo review on PR7 flagged two real issues in tests/previewResolver.test.js:
1. makePreviewDoc() appended a new <iframe> to document.body on every
call with no teardown — registerPreviewDoc() only cleans up the
resolver's internal probe elements, not the test-created iframes
themselves, so they accumulated across the file's 16+ calls. Added
an afterEach that removes every iframe makePreviewDoc() created and
unregisters the preview doc.
2. The canvas-degrades-to-null test asserted resolveRgb('red') returns
null based on this sandbox's jsdom lacking the optional `canvas` npm
package, rather than the documented contract — if canvas support
ever became available the test would start failing for an unrelated
reason. Replaced with an explicit getContext('2d') stub, plus a new
companion test asserting the positive path (a real 2D context
available) returns an [r,g,b] triple.
Fixing this surfaced a real subtlety Qodo's own suggested fix would
have missed: each iframe is a separate jsdom realm with its own
HTMLCanvasElement constructor, so a canvas created via
activeDoc.createElement('canvas') is an instance of
doc.defaultView.HTMLCanvasElement, not the top-level test file's
global HTMLCanvasElement — spying on the wrong one is a silent no-op
(verified: the positive-path test failed until the spy target was
corrected to the iframe's own realm).
Verified: npm run test:unit (90/90, up from 89 with the new positive-
path test), npx tsc --noEmit, npx svelte-check (0 errors/warnings), and
a standalone check confirming zero leftover <iframe> elements in
document.body after the full previewResolver suite runs.
|
Both good catches — fixed in 156e421.
One subtlety the literal suggested fix would have missed: each Verified: 90/90 unit tests (up from 89 with the new positive-path test), Generated by Claude Code |
2dcc34f
into
claude/pr-469-audit-rebase-ggp0e4
Summary
Seventh and final themed PR from the SLASHED technical-debt audit (PR #469): the configurator test-coverage buildout (SL-023 continuation). Lands last per the remediation plan's explicit ordering, now that PR4/PR5/PR6 are merged.
Priority 1 (
persistence.tsload/save, both standalone and WP-embedded branches, including the malformed-localStorage case) and most of Priority 3 (SliderRow/TokenRowbind → override-set → reset) were already covered by earlier batches. Two real gaps remained:previewResolver.svelte.tshad zero test coverage. Addedtests/previewResolver.test.js(16 tests) coveringregisterPreviewDoc/getActiveTheme,resolveColor/resolveColorForTheme's per-expression and per-theme caching,resolveRgb/resolveBackground's no-preview-doc fallbacks, and — closing the loop on PR6's SL-020 rAF-coalescing — thatbumpPreviewVersion()reliably invalidates the cache and is safe to call repeatedly (a pure counter, no reactive loop).<iframe>'scontentDocumentrather than a detacheddocument.implementation.createHTMLDocument(), since jsdom'sgetComputedStyleonly resolves colors on documents that have adefaultView(a detached document lacks one) — this matches howPreviewPanel.svelteregisters a real iframe in production.resolveRgb's canvas-context test documents and locks in the graceful-degradation path: this sandbox has nocanvasnpm package, so jsdom'sgetContext('2d')is unimplemented, andresolveRgbcorrectly degrades tonullrather than throwing.StudioHeader's'error'saveState(added by SL-018 in an earlier batch) had no dedicated test coverage. Added asave statedescribe block totests-components/header.test.js(6 new tests) covering all four states (idle/saving/saved/error) — specifically that a failed save surfaces a distinct title/label from a fresh save and stays clickable to retry, while an in-progress retry is correctly disabled. Also corrected the file'sbasePropsfixture, which was missinghasPendingChanges/saveState/onSave(present in the component's props since SL-018, never added to this test file).Test plan
npm run test:unit— 89/89 passednpm run test:components— 23/23 passednpm run test(combined vitest suite) — 112/112 passednpx tsc --noEmit— cleannpx svelte-check --tsconfig ./tsconfig.json— 0 errors, 0 warningsnpm run build— succeedstests-e2e/shell.spec.js) against a built preview server — 5/6 passing; the 1 failure is the same pre-existing/favicon.ico404 noted in PR5/PR6, unrelated to this PR (test-only changes, no runtime source touched)Generated by Claude Code