AI-native design editor. Open-source Figma alternative.
Merge PR #70: E2E test coverage + mutation unit tests
Danila Poyarkov01c8753f6eb2
diff --cc CHANGELOG.mdindex 8789a1c4f,c18309720..0a5fed4be--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -41,6 -39,9 +41,8 @@@- Mobile UI cleanup: extract shared `colorToCSS` util to core, `initials` to `src/utils/text`, `toolIcons` to `src/utils/tools`; replace hand-rolled dropdowns with reka-ui Popover/DropdownMenu; narrow `mobileDrawerSnap` type to string union; move magic numbers to constants; disable PWA service worker in dev mode- 83 new E2E tests (57 → 140): design panel, code panel, components, copy/paste, multi-page, text editing, keyboard shortcuts, context menu- 150 new unit tests (588 → 738): color, undo, snap, vector, style-runs, text-editor-- 48 new E2E tests across 9 spec files: canvas manipulation (marquee, alt-drag, resize, rotation, hover), toolbar (pen tool, flyouts), properties panel (scrub inputs, corner radius, fills, alignment, flip, clip), text formatting (bold, italic, word navigation), auto-layout (gap, padding, alignment grid), panels (resize, persistence, hide/show), variables dialog (search, rename, color picker), export (add/remove rows, format selector, preview). Add `tests/helpers/store.ts` for typed store access via `window.__OPEN_PENCIL_STORE__`-- 26 new mutation unit tests in `tests/engine/mutation.test.ts`: `toggleBoldInRange` partial/idempotency/immutability, `applyStyleToRange` split/merge, `removeStyleFromRange` edge cases, `vectorNetworkBlob` negative coords/precision/determinism, `SceneGraph + UndoManager` integration (LIFO order, redo stack clearing, batch, multi-field restore). Discovered and documented `handleMirroring` not persisted in blob format-- Add `data-test-id` attributes to `AppearanceSection` (corner radius, independent corners), `LayoutSection` (clip content, gap, uniform padding), `TypographySection` (bold button), `VariablesDialog` (search input, variable rows), `EditorView` (left splitter handle)++- 48 new E2E tests (9 spec files) + 26 mutation unit tests + store/canvas test helpers++- Add `data-test-id` attributes to AppearanceSection, LayoutSection, TypographySection, VariablesDialog, EditorView## 0.7.0 — 2026-03-05diff --cc openspec/specs/testing/spec.mdindex f957b7f80,b0a131811..b9426d0ce--- a/openspec/specs/testing/spec.md+++ b/openspec/specs/testing/spec.md@@@ -136,178 -135,73 +135,250 @@@ The test suite SHALL include tests for- **WHEN** sceneNodeToJsx is called on a rectangle with blue fill- **THEN** the output includes Rectangle component with bg prop+++### Requirement: FigmaAPI unit tests++The project SHALL provide comprehensive unit tests for the Figma Plugin API in `tests/engine/figma-api.test.ts`.++#### Scenario: Node creation tests+- **WHEN** `bun test tests/engine/figma-api.test.ts` runs+- **THEN** tests verify `createFrame()`, `createRectangle()`, `createText()`, and other creation methods++#### Scenario: Property access tests+- **WHEN** tests read node properties (x, y, width, height, name, fills, strokes)+- **THEN** all getters return correct values from SceneNode++#### Scenario: Property setting tests+- **WHEN** tests set node properties (`node.name = "Test"`, `node.x = 100`)+- **THEN** SceneGraph is updated correctly++#### Scenario: Text property tests+- **WHEN** tests access `textNode.characters`, `fontSize`, `fontName`+- **THEN** text-specific properties work correctly++#### Scenario: Auto-layout tests+- **WHEN** tests set `layoutMode = "VERTICAL"`, `itemSpacing`, `paddingLeft`+- **THEN** auto-layout properties are applied++#### Scenario: Tree operation tests+- **WHEN** tests call `appendChild()`, `insertChild()`, `remove()`+- **THEN** scene graph tree is modified correctly++#### Scenario: Traversal tests+- **WHEN** tests call `findAll()`, `findOne()`, `findAllWithCriteria()`+- **THEN** correct nodes are returned++#### Scenario: Component tests+- **WHEN** tests create components and instances+- **THEN** component-instance relationships work++#### Scenario: Serialization tests+- **WHEN** tests call `figma.toJSON(node)`+- **THEN** JSON output includes all required properties++#### Scenario: Frozen array tests+- **WHEN** tests access `fills`, `strokes`, `children` and try to mutate+- **THEN** arrays are frozen and throw errors on mutation attempts++#### Scenario: 924 LOC of tests+- **WHEN** FigmaAPI test file is counted+- **THEN** it contains 924 lines covering 60+ test cases++### Requirement: Eval CLI integration tests++The project SHALL provide integration tests for eval command in `tests/engine/eval-cli.test.ts`.++#### Scenario: Inline code execution test+- **WHEN** test runs eval with `--code 'return figma.currentPage.id'`+- **THEN** output matches expected page ID++#### Scenario: Node creation test+- **WHEN** test runs eval creating a frame+- **THEN** document is modified and frame exists++#### Scenario: Write flag test+- **WHEN** test runs eval with `--write`+- **THEN** file is modified in-place++#### Scenario: Output file test+- **WHEN** test runs eval with `-o output.fig`+- **THEN** new file is created with modifications++#### Scenario: JSON output test+- **WHEN** test runs eval with `--json`+- **THEN** result is formatted as JSON++#### Scenario: Error handling test+- **WHEN** eval code throws error+- **THEN** stderr contains error message++#### Scenario: 202 LOC of integration tests+- **WHEN** eval CLI test file is counted+- **THEN** it contains 202 lines covering 17 integration scenarios++### Requirement: Tool schema unit tests++The project SHALL provide unit tests for unified tool definitions in `tests/engine/tools.test.ts`.++#### Scenario: Schema structure tests+- **WHEN** tests validate tool schemas+- **THEN** each tool has name, description, parameters, and handler++#### Scenario: Tool handler tests+- **WHEN** tests invoke tool handlers with valid params+- **THEN** handlers return expected results++#### Scenario: Parameter validation tests+- **WHEN** tests call handlers with invalid params+- **THEN** errors are raised or handled gracefully++#### Scenario: 390 LOC of tool tests+- **WHEN** tools test file is counted+- **THEN** it contains 390 lines++### Requirement: Tool adapter tests++The project SHALL provide adapter tests in `tests/engine/tools-ai-adapter.test.ts` (190 LOC) and `tests/engine/tools-cli.test.ts` (219 LOC).++#### Scenario: AI adapter format test+- **WHEN** AI adapter converts schema to LLM format+- **THEN** output matches expected structure++#### Scenario: CLI adapter test+- **WHEN** CLI commands use tool schema+- **THEN** parameters map correctly++### Requirement: App menu integration tests++The project SHALL provide integration tests for app menu in `tests/e2e/app-menu.spec.ts`.++#### Scenario: File menu test+- **WHEN** test clicks File menu items+- **THEN** actions (Open, Save, Export) are triggered++#### Scenario: Edit menu test+- **WHEN** test uses Edit menu (Undo, Redo, Copy, Paste)+- **THEN** operations execute correctly++#### Scenario: View menu test+- **WHEN** test uses View → Zoom in/out+- **THEN** viewport zoom changes++#### Scenario: Object menu test+- **WHEN** test uses Object → Group/Ungroup+- **THEN** nodes are grouped/ungrouped++#### Scenario: Text menu test+- **WHEN** test uses Text → Bold/Italic+- **THEN** text styles are applied++#### Scenario: Arrange menu test+- **WHEN** test uses Arrange → Bring to front+- **THEN** z-order changes++#### Scenario: 131 LOC of app menu tests+- **WHEN** app menu test file is counted+- **THEN** it contains 131 lines++### Requirement: Autosave integration tests++The project SHALL provide integration tests for autosave in `tests/e2e/autosave.spec.ts`.++#### Scenario: Autosave trigger test+- **WHEN** test modifies scene graph+- **THEN** autosave timer starts++#### Scenario: Debounce test+- **WHEN** test makes rapid changes+- **THEN** only one save occurs after 3 seconds++#### Scenario: Write test+- **WHEN** autosave timer expires+- **THEN** file is written++#### Scenario: Skip unchanged test+- **WHEN** sceneVersion matches savedVersion+- **THEN** write is skipped++#### Scenario: 113 LOC of autosave tests+- **WHEN** autosave test file is counted+- **THEN** it contains 113 lines++### Requirement: Test coverage expansion++The test suite SHALL expand from original coverage to include 2571 LOC of new tests across 7 files (figma-api.test.ts, eval-cli.test.ts, tools.test.ts, tools-ai-adapter.test.ts, tools-cli.test.ts, app-menu.spec.ts, autosave.spec.ts).++#### Scenario: Total new test lines+- **WHEN** new test files are counted+- **THEN** 2571 lines of tests are added+++ ### Requirement: Canvas manipulation E2E tests+ The E2E suite SHALL include tests for `tests/e2e/canvas-manipulation.spec.ts` covering: marquee selection, resize handle drag, rotation handle drag, Alt+drag duplicate, Shift+Arrow nudge (10px), and hover highlight (visual screenshot comparison).++ #### Scenario: Canvas manipulation tests pass+ - **WHEN** `bun run test` executes `canvas-manipulation.spec.ts`+ - **THEN** all 6+ tests pass verifying selection, resize, rotation, duplicate, nudge, and hover++ ### Requirement: Toolbar E2E tests+ The E2E suite SHALL include tests for `tests/e2e/toolbar.spec.ts` covering: shapes flyout chevron, Polygon tool, Star tool, Pen tool (corner, close path, Escape), and Frame flyout.++ #### Scenario: Toolbar tests pass+ - **WHEN** `bun run test` executes `toolbar.spec.ts`+ - **THEN** all 7+ tests pass verifying flyout menus and shape creation++ ### Requirement: Properties panel E2E tests+ The E2E suite SHALL include tests for `tests/e2e/properties-panel.spec.ts` covering: ScrubInput drag, corner radius (uniform + independent), fill gradient switch, variable bind badge, alignment buttons, flip horizontal, and clip content checkbox.++ #### Scenario: Properties panel tests pass+ - **WHEN** `bun run test` executes `properties-panel.spec.ts`+ - **THEN** all 8+ tests pass verifying property changes via store assertions++ ### Requirement: Text formatting E2E tests+ The E2E suite SHALL include tests for `tests/e2e/text-formatting.spec.ts` covering: cursor positioning, double-click word select, ⌘B bold, ⌘I italic, Alt+ArrowRight word navigation, and Bold button in typography section.++ #### Scenario: Text formatting tests pass+ - **WHEN** `bun run test` executes `text-formatting.spec.ts`+ - **THEN** all 6+ tests pass verifying text edit interactions++ ### Requirement: Auto-layout E2E tests+ The E2E suite SHALL include tests for `tests/e2e/auto-layout.spec.ts` covering: Shift+A on selection, direction toggle, gap ScrubInput, uniform padding, alignment grid, and remove auto-layout.++ #### Scenario: Auto-layout tests pass+ - **WHEN** `bun run test` executes `auto-layout.spec.ts`+ - **THEN** all 6+ tests pass verifying auto-layout frame state via store++ ### Requirement: Snap guides E2E tests+ The E2E suite SHALL include tests for `tests/e2e/snap-guides.spec.ts` covering: edge snap guide and center snap guide, both verified via screenshot comparison.++ #### Scenario: Snap guide tests pass+ - **WHEN** `bun run test` executes `snap-guides.spec.ts`+ - **THEN** 2 screenshot comparison tests pass confirming guide line visibility++ ### Requirement: Panel resize E2E tests+ The E2E suite SHALL include tests for `tests/e2e/panels.spec.ts` covering: left panel drag resize, width persistence after reload, and ⌘\\ UI toggle (hide + show).++ #### Scenario: Panel tests pass+ - **WHEN** `bun run test` executes `panels.spec.ts`+ - **THEN** all 4+ tests pass verifying panel DOM dimensions and visibility++ ### Requirement: Variables dialog E2E tests+ The E2E suite SHALL include tests for `tests/e2e/variables-dialog.spec.ts` covering: dialog open, search filter, cell edit, and color swatch picker.++ #### Scenario: Variables dialog tests pass+ - **WHEN** `bun run test` executes `variables-dialog.spec.ts`+ - **THEN** all 4+ tests pass verifying dialog interactions++ ### Requirement: Export E2E tests+ The E2E suite SHALL include tests for `tests/e2e/export.spec.ts` covering: format selector, add/remove rows, preview toggle, and SVG hiding scale input.++ #### Scenario: Export tests pass+ - **WHEN** `bun run test` executes `export.spec.ts`+ - **THEN** all 5+ tests pass verifying export section UI state++ ### Requirement: CanvasHelper extended helpers+ The `CanvasHelper` class SHALL provide `marquee()`, `hover()`, `dragScrubInput()`, and `shiftDrag()` helper methods usable across all spec files.++ #### Scenario: Helpers available in all specs+ - **WHEN** a spec file imports `CanvasHelper`+ - **THEN** `canvas.marquee()`, `canvas.hover()`, `canvas.dragScrubInput()`, and `canvas.shiftDrag()` are callable without TypeScript errors+diff --cc tests/e2e/text-formatting.spec.tsindex 000000000,f9545c820..0c03a6d98mode 000000,100644..100644--- a/tests/e2e/text-formatting.spec.ts+++ b/tests/e2e/text-formatting.spec.ts@@@ -1,0 -1,127 +1,125 @@@+ import { test, expect, type Page } from '@playwright/test'++ import { CanvasHelper } from '../helpers/canvas'+ import { getSelectedNode, getEditingTextId, getNodeById } from '../helpers/store'++ let page: Page+ let canvas: CanvasHelper++ test.describe.configure({ mode: 'serial' })++ test.beforeAll(async ({ browser }) => {+ page = await browser.newPage()+ await page.goto('/')+ canvas = new CanvasHelper(page)+ await canvas.waitForInit()+ await canvas.clearCanvas()++ await page.evaluate(() => {+ const store = window.__OPEN_PENCIL_STORE__!+ store.state.zoom = 1+ store.state.panX = 0+ store.state.panY = 0+ const id = store.createShape('TEXT', 200, 200, 150, 30)+ store.graph.updateNode(id, { text: 'Hello World', fontSize: 18 })+ store.select([id])+ })+ await canvas.waitForRender()+ await canvas.pressKey('Escape')+ await canvas.waitForRender()+ })++ test.afterAll(async () => {+ await page.close()+ })++ test('double-click enters text edit mode', async () => {+ await canvas.dblclick(275, 215)+ await page.waitForTimeout(200)++ const editingId = await getEditingTextId(page)+ expect(editingId).not.toBeNull()+ canvas.assertNoErrors()+ })++ test('bold button toggles fontWeight to 700 then back to 400', async () => {+ await canvas.pressKey('Escape')+ await canvas.waitForRender()+ await canvas.click(275, 215)+ await canvas.waitForRender()++ const nodeId = (await getSelectedNode(page))!.id++ // ensure starting weight is 400 via undo-safe store method+ await page.evaluate(async (id: string) => {+ const store = window.__OPEN_PENCIL_STORE__!+ store.updateNodeWithUndo(id, { fontWeight: 400 }, 'reset')+ store.state.sceneVersion+++ await new Promise(requestAnimationFrame)+ }, nodeId)+ await canvas.waitForRender()++ const boldBtn = page.locator('[data-test-id="typography-bold-button"]')+ await expect(boldBtn).toBeVisible({ timeout: 3000 })+ await boldBtn.click()+ await page.waitForTimeout(500)+ await canvas.waitForRender()++ const bold = await getNodeById(page, nodeId)+ expect(bold!.fontWeight).toBe(700)++ await page.locator('[data-test-id="typography-bold-button"]').click()+ await page.waitForTimeout(500)+ await canvas.waitForRender()++ const normal = await getNodeById(page, nodeId)+ expect(normal!.fontWeight).toBe(400)+ canvas.assertNoErrors()+ })++ test('Cmd+I toggles italic', async () => {+ await canvas.click(275, 215)+ await canvas.waitForRender()+ const nodeId = (await getSelectedNode(page))!.id++ await canvas.dblclick(275, 215)+ await expect.poll(() => getEditingTextId(page), { timeout: 5000 }).toBeTruthy()++ await page.keyboard.press('End')+ await page.keyboard.press('Meta+i')+ await canvas.pressKey('Escape')+ await canvas.waitForRender()++ const node = await getNodeById(page, nodeId)+ expect(node!.italic).toBe(true)+ canvas.assertNoErrors()+ })++ test('double-click word select changes canvas screenshot', async () => {+ await canvas.pressKey('Escape')+ await canvas.waitForRender()++ const baseline = await canvas.screenshotCanvas()++ await canvas.dblclick(275, 215)+ await page.waitForTimeout(200)++ const selected = await canvas.screenshotCanvas()++ expect(Buffer.compare(baseline, selected)).not.toBe(0)+ await canvas.pressKey('Escape')+ await canvas.waitForRender()+ canvas.assertNoErrors()+ })++ test('Alt+ArrowRight word navigation stays in text edit mode', async () => {+ await canvas.dblclick(275, 215)+ await page.waitForTimeout(200)++ await page.keyboard.press('Alt+ArrowRight')+ await canvas.waitForRender()++ const editingId = await getEditingTextId(page)+ expect(editingId).not.toBeNull()+ canvas.assertNoErrors()+ })--diff --cc tests/e2e/toolbar.spec.tsindex 000000000,8b97ef15c..2499ea987mode 000000,100644..100644--- a/tests/e2e/toolbar.spec.ts+++ b/tests/e2e/toolbar.spec.ts@@@ -1,0 -1,112 +1,112 @@@+ import { test, expect, type Page } from '@playwright/test'++ import { CanvasHelper } from '../helpers/canvas'+ import { getPageChildren } from '../helpers/store'++ let page: Page+ let canvas: CanvasHelper++ test.describe.configure({ mode: 'serial' })++ test.beforeAll(async ({ browser }) => {+ page = await browser.newPage()+ await page.goto('/')+ canvas = new CanvasHelper(page)+ await canvas.waitForInit()+ })++ test.afterAll(async () => {+ await page.close()+ })++ test('shapes flyout opens', async () => {+ await page.locator('[data-test-id="toolbar-flyout-rectangle"]').click()+ await expect(page.locator('[data-test-id="toolbar-flyout-item-polygon"]')).toBeVisible()+ canvas.assertNoErrors()+ })++ test('Polygon tool creates POLYGON node', async () => {+ await page.locator('[data-test-id="toolbar-flyout-item-polygon"]').click()+ await canvas.drag(300, 200, 400, 300)+ await canvas.waitForRender()++ const children = await getPageChildren(page)- expect(children.some((n: any) => n.type === 'POLYGON')).toBe(true)++ expect(children.some(n => n.type === 'POLYGON')).toBe(true)+ canvas.assertNoErrors()+ })++ test('Star tool creates STAR node', async () => {+ await page.locator('[data-test-id="toolbar-flyout-rectangle"]').click()+ await page.locator('[data-test-id="toolbar-flyout-item-star"]').click()+ await canvas.drag(150, 150, 250, 250)+ await canvas.waitForRender()++ const children = await getPageChildren(page)- expect(children.some((n: any) => n.type === 'STAR')).toBe(true)++ expect(children.some(n => n.type === 'STAR')).toBe(true)+ canvas.assertNoErrors()+ })++ test('Pen creates VECTOR node with 3 vertices on Enter', async () => {+ await canvas.pressKey('Escape')+ await canvas.pressKey('p')+ await canvas.click(100, 400)+ await canvas.waitForRender()+ await canvas.click(200, 400)+ await canvas.waitForRender()+ await canvas.click(200, 480)+ await canvas.waitForRender()+ await canvas.pressKey('Enter')+ await canvas.waitForRender()++ const children = await getPageChildren(page)- const vectors = children.filter((n: any) => n.type === 'VECTOR')++ const vectors = children.filter(n => n.type === 'VECTOR')+ expect(vectors.length).toBeGreaterThan(0)+ const last = vectors[vectors.length - 1]+ expect(last.vectorNetwork.vertices.length).toBe(3)+ canvas.assertNoErrors()+ })++ test('Pen Escape with 2 vertices cancels path without creating node', async () => {- const before = (await getPageChildren(page)).filter((n: any) => n.type === 'VECTOR').length++ const before = (await getPageChildren(page)).filter(n => n.type === 'VECTOR').length++ await canvas.pressKey('p')+ await canvas.click(350, 400)+ await canvas.waitForRender()+ await canvas.click(440, 400)+ await canvas.waitForRender()+ await canvas.pressKey('Escape')+ await canvas.waitForRender()+- const after = (await getPageChildren(page)).filter((n: any) => n.type === 'VECTOR').length++ const after = (await getPageChildren(page)).filter(n => n.type === 'VECTOR').length+ expect(after).toBe(before)+ canvas.assertNoErrors()+ })++ test('Pen close path creates VECTOR with closed region', async () => {- const before = (await getPageChildren(page)).filter((n: any) => n.type === 'VECTOR').length++ const before = (await getPageChildren(page)).filter(n => n.type === 'VECTOR').length++ await canvas.pressKey('p')+ await canvas.click(500, 200)+ await canvas.waitForRender()+ await canvas.click(580, 200)+ await canvas.waitForRender()+ await canvas.click(540, 270)+ await canvas.waitForRender()+ await canvas.click(500, 200)+ await canvas.waitForRender()+- const after = (await getPageChildren(page)).filter((n: any) => n.type === 'VECTOR').length++ const after = (await getPageChildren(page)).filter(n => n.type === 'VECTOR').length+ expect(after).toBeGreaterThan(before)+- const vectors = (await getPageChildren(page)).filter((n: any) => n.type === 'VECTOR')++ const vectors = (await getPageChildren(page)).filter(n => n.type === 'VECTOR')+ const last = vectors[vectors.length - 1]+ expect(last.vectorNetwork.regions?.length).toBeGreaterThan(0)+ canvas.assertNoErrors()+ })++ test('Frame flyout shows Frame and Section items', async () => {+ await page.locator('[data-test-id="toolbar-flyout-frame"]').click()+ await expect(page.locator('[data-test-id="toolbar-flyout-item-frame"]')).toBeVisible()+ await expect(page.locator('[data-test-id="toolbar-flyout-item-section"]')).toBeVisible()+ canvas.assertNoErrors()+ })diff --cc tests/helpers/canvas.tsindex db4c74aba,5c0c329be..450a0694f--- a/tests/helpers/canvas.ts+++ b/tests/helpers/canvas.ts@@@ -41,7 -42,7 +42,9 @@@ export class CanvasHelper}private async canvasBounds() {-- return this.canvas.boundingBox().then((b) => b!)++ const b = await this.canvas.boundingBox()++ if (!b) throw new Error('Canvas has no bounding box — is it visible?')++ return b}async click(canvasX: number, canvasY: number) {