From 64e565f00ff9a5b7b5e34543a6f6746750517833 Mon Sep 17 00:00:00 2001 From: Richard Osborne Date: Wed, 18 Feb 2026 17:14:52 +0100 Subject: [PATCH] test(styles): STYLE-005 StyleAnalyzer unit tests (17 cases) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Covers: hex/rgb color detection, spacing detection, variant candidate threshold logic, toSuggestions ordering, stable IDs, edge cases. Infra note: tests in tests/models/ — use 'npm run test:editor' not 'npx jest' directly (webpack build required by test-editor.ts script). 'npx jest' alone hangs on webpack. Move tests to tests/models/ not tests/services/ — transform config only covers models/ path. --- .../PROGRESS-richard.md | 84 +++-- .../tests/models/StyleAnalyzer.test.ts | 294 ++++++++++++++++++ 2 files changed, 353 insertions(+), 25 deletions(-) create mode 100644 packages/noodl-editor/tests/models/StyleAnalyzer.test.ts diff --git a/dev-docs/tasks/phase-9-styles-overhaul/PROGRESS-richard.md b/dev-docs/tasks/phase-9-styles-overhaul/PROGRESS-richard.md index 0e7b98b..54c975b 100644 --- a/dev-docs/tasks/phase-9-styles-overhaul/PROGRESS-richard.md +++ b/dev-docs/tasks/phase-9-styles-overhaul/PROGRESS-richard.md @@ -1,38 +1,72 @@ -# Phase 9 Progress — Richard +# Phase 9: Styles Overhaul — Richard's Progress -**Branch:** cline-dev-richard -**Last Updated:** 2026-02-18 +_Branch: `cline-dev-richard`_ -## Completed This Sprint +--- -| Task | Name | Completed | Notes | -| ----------------- | ---------------------------- | ---------- | ----------------------------------------------------------------------------------------------- | -| STYLE-001 Phase 3 | TokenPicker Component | 2026-02-18 | noodl-core-ui — searchable grouped dropdown with colour swatches, clear button, category filter | -| STYLE-001 Phase 4 | Preview CSS Injection | 2026-02-18 | PreviewTokenInjector singleton + CanvasView dom-ready hook + ProjectDesignTokenContext wiring | -| CLEANUP-000H | Migration Wizard SCSS Polish | 2026-02-18 | All 8 SCSS files replaced with design token versions (removed 2112 lines of hardcoded CSS) | +## Sprint 1 — 18 Feb 2026 -## In Progress +### STYLE-005: Smart Style Suggestion Engine ✅ (committed 05379c9) -| Task | Name | Started | Blocker | -| -------------- | ------------------------------ | ------- | ------------------------------ | -| STYLE-005 | Smart Style Suggestions V1 | - | Needs fresh context window | -| ~~WIZARD-001~~ | ~~Project Creation Wizard V1~~ | ~~-~~ | ~~Needs fresh context window~~ | +**Files created:** -## Decisions & Learnings +- `packages/noodl-editor/src/editor/src/services/StyleAnalyzer/types.ts` — TypeScript interfaces: `ElementReference`, `RepeatedValue`, `VariantCandidate`, `StyleAnalysisResult`, `StyleSuggestion`, `StyleAnalysisOptions`, `TokenModelLike`, `SUGGESTION_THRESHOLDS` +- `packages/noodl-editor/src/editor/src/services/StyleAnalyzer/StyleAnalyzer.ts` — Static analyzer class: + - `analyzeProject(options?)` — scans all visual nodes for repeated raw colors/spacing (threshold: 3) and variant candidates (threshold: 3 overrides) + - `analyzeNode(nodeId)` — per-node analysis for property panel integration + - `toSuggestions(result)` — converts analysis to ordered `StyleSuggestion[]` + - `TokenModelLike` injected via options to avoid static singleton coupling +- `packages/noodl-editor/src/editor/src/services/StyleAnalyzer/SuggestionActionHandler.ts` — `executeSuggestionAction()`: + - repeated-color/spacing → calls `tokenModel.setToken()` + replaces all occurrences with `var(--token-name)` + - variant-candidate → sets `_variant` param on node +- `packages/noodl-editor/src/editor/src/services/StyleAnalyzer/index.ts` — barrel export +- `packages/noodl-core-ui/src/components/StyleSuggestions/SuggestionBanner.tsx` — Compact banner UI (accept / ignore / never-show) +- `packages/noodl-core-ui/src/components/StyleSuggestions/SuggestionBanner.module.scss` — Styled with CSS tokens only +- `packages/noodl-core-ui/src/components/StyleSuggestions/index.ts` — barrel export +- `packages/noodl-editor/src/editor/src/hooks/useStyleSuggestions.ts` — Hook: runs analyzer on mount, exposes `activeSuggestion`, `pendingCount`, `dismissSession`, `dismissPermanent`, `refresh` -- **[2026-02-18] Sprint 1 started on cline-dev-richard.** +**Pending (next session):** -- **[2026-02-18] STYLE-001 Phase 4 injection architecture:** +- Unit tests for `StyleAnalyzer` (value detection, threshold logic, `toSuggestions` ordering) +- Wire `SuggestionBanner` into `ElementStyleSection` / property panel +- Consider debounced auto-refresh on `componentAdded`/`nodeParametersChanged` events - - `PreviewTokenInjector.attachModel(model)` → subscribes to `tokensChanged` - - `PreviewTokenInjector.notifyDomReady(webview)` → called from `CanvasView` on `dom-ready` - - Injects `