Skip to content

AI-native design editor. Open-source Figma alternative.

Improve E2E test quality: stronger assertions, fix bold button test, improve snap guide comparison

Anton A Sd7dc55264be0
diff --git a/tests/e2e/auto-layout.spec.ts b/tests/e2e/auto-layout.spec.ts
index c463a6232..a1b1a96b8 100644
--- a/tests/e2e/auto-layout.spec.ts
+++ b/tests/e2e/auto-layout.spec.ts
@@ -68,7 +68,7 @@ test('gap ScrubInput sets itemSpacing', async () => {
await canvas.dragScrubInput(page.locator('[data-test-id="layout-gap-input"]'), 40)
const after = await getNodeById(page, frameId)
- expect(after!.itemSpacing).toBeGreaterThan(initialSpacing)
+ expect(after!.itemSpacing).toBeGreaterThan(initialSpacing + 5)
canvas.assertNoErrors()
})
diff --git a/tests/e2e/snap-guides.spec.ts b/tests/e2e/snap-guides.spec.ts
index 980b9214a..6120502c9 100644
--- a/tests/e2e/snap-guides.spec.ts
+++ b/tests/e2e/snap-guides.spec.ts
@@ -30,7 +30,11 @@ async function createRects() {
await canvas.waitForRender()
}
-test('edge snap guide visual appears during drag', async () => {
+// Snap guide visual tests compare the canvas at a snap position vs a non-snap position
+// during the same drag. The snap position produces a guide line overlay; non-snap does not.
+// Skipped on Linux CI due to X11 Alt+drag interference and rendering differences.
+
+test('edge snap guide: canvas differs at snap vs non-snap position', async () => {
test.skip(process.platform === 'linux', 'Snap guide visual tests skipped on Linux CI')
await createRects()
@@ -38,22 +42,27 @@ test('edge snap guide visual appears during drag', async () => {
const box = await page.locator('canvas').boundingBox()
if (!box) throw new Error('No canvas')
- const baseline = await canvas.screenshotCanvas()
-
+ // drag to a non-snap position first, capture screenshot
await page.mouse.move(box.x + 340, box.y + 140)
await page.mouse.down()
- await page.mouse.move(box.x + 182, box.y + 140, { steps: 30 })
+ await page.mouse.move(box.x + 250, box.y + 140, { steps: 15 })
+ const nonSnapShot = await canvas.screenshotCanvas()
- const midDrag = await canvas.screenshotCanvas()
+ // continue drag to edge-snap position (right edge of rect B aligns with left edge of rect A at x=180)
+ await page.mouse.move(box.x + 182, box.y + 140, { steps: 15 })
+ const snapShot = await canvas.screenshotCanvas()
await page.mouse.up()
- const changed = Buffer.compare(baseline, midDrag) !== 0
- expect.soft(changed, 'Snap guide did not appear — guide may not have rendered').toBeTruthy()
+ // At snap position the guide line overlay should make the canvas visually different
+ expect(
+ Buffer.compare(nonSnapShot, snapShot),
+ 'Canvas should differ at snap position due to guide line overlay'
+ ).not.toBe(0)
canvas.assertNoErrors()
})
-test('center snap guide visual appears during drag', async () => {
+test('center snap guide: canvas differs at snap vs non-snap position', async () => {
test.skip(process.platform === 'linux', 'Snap guide visual tests skipped on Linux CI')
await createRects()
@@ -61,17 +70,21 @@ test('center snap guide visual appears during drag', async () => {
const box = await page.locator('canvas').boundingBox()
if (!box) throw new Error('No canvas')
- const baseline = await canvas.screenshotCanvas()
-
+ // drag to a non-snap position first
await page.mouse.move(box.x + 340, box.y + 140)
await page.mouse.down()
- await page.mouse.move(box.x + 220, box.y + 140, { steps: 30 })
+ await page.mouse.move(box.x + 260, box.y + 140, { steps: 15 })
+ const nonSnapShot = await canvas.screenshotCanvas()
- const midDrag = await canvas.screenshotCanvas()
+ // continue drag to center-snap position (center of rect B aligns with center of rect A)
+ await page.mouse.move(box.x + 220, box.y + 140, { steps: 15 })
+ const snapShot = await canvas.screenshotCanvas()
await page.mouse.up()
- const changed = Buffer.compare(baseline, midDrag) !== 0
- expect.soft(changed, 'Snap guide did not appear — guide may not have rendered').toBeTruthy()
+ expect(
+ Buffer.compare(nonSnapShot, snapShot),
+ 'Canvas should differ at snap position due to center guide line overlay'
+ ).not.toBe(0)
canvas.assertNoErrors()
})
diff --git a/tests/e2e/text-formatting.spec.ts b/tests/e2e/text-formatting.spec.ts
index 099cff36a..f9545c820 100644
--- a/tests/e2e/text-formatting.spec.ts
+++ b/tests/e2e/text-formatting.spec.ts
@@ -42,33 +42,38 @@ test('double-click enters text edit mode', async () => {
canvas.assertNoErrors()
})
-test('Cmd+B in text edit mode toggles fontWeight without selection', async () => {
+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 before = await getSelectedNode(page)
- expect(before).not.toBeNull()
- const nodeId = before!.id
- const initialWeight = before!.fontWeight
+ const nodeId = (await getSelectedNode(page))!.id
- // enter edit mode, press Escape immediately to clear cursor (no selection range)
- // then press Meta+b — toggleBold falls through to node-level fontWeight change
- await canvas.dblclick(275, 215)
- await expect.poll(() => getEditingTextId(page), { timeout: 5000 }).toBeTruthy()
+ // 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()
- // Move to end to place cursor but ensure no text range selection
- await page.keyboard.press('End')
- await page.keyboard.press('Meta+b')
- await page.waitForTimeout(200)
- await canvas.pressKey('Escape')
+ 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 after = await getNodeById(page, nodeId)
- // Bold applied to styleRuns (range from cursor) or fontWeight — either way weight changed
- const effectiveWeight = after!.styleRuns?.length
- ? after!.styleRuns[0].fontWeight ?? after!.fontWeight
- : after!.fontWeight
- expect(effectiveWeight).not.toBe(initialWeight)
+ 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()
})
@@ -119,20 +124,4 @@ test('Alt+ArrowRight word navigation stays in text edit mode', async () => {
canvas.assertNoErrors()
})
-test('Bold button in panel toggles fontWeight', async () => {
- await canvas.pressKey('Escape')
- await canvas.waitForRender()
-
- await canvas.click(275, 215)
- await canvas.waitForRender()
-
- const before = await getSelectedNode(page)
- const initialWeight = before!.fontWeight
-
- await page.locator('[data-test-id="typography-bold-button"]').click()
- await canvas.waitForRender()
- const after = await getSelectedNode(page)
- expect(after!.fontWeight).not.toBe(initialWeight)
- canvas.assertNoErrors()
-})