openpencil/tests/e2e/editor/duplicate-undo.spec.ts
Danila Poyarkov 69dbc36a7e
fix: match Figma when dragging, drawing, duplicating, and pasting (#894)
* fix: match Figma when dragging, drawing, duplicating, and pasting

Checked against Figma desktop 126 with real pointer input. A dragged layer
lands in the topmost unlocked frame, section, component, or instance under
the cursor, following rotation and clipping, and leaves its frame as soon as
the cursor does; groups, boolean operations, component sets, and locked
frames never take a drop, and a layer stays in its group unless it lands on
another frame. Space keeps parents, Shift locks an axis, and Control drops
into auto layout as an absolute-positioned layer. Locked layers stay put.

New shapes go into the frame under the start point, frames and sections take
in the unlocked siblings they fully cover, duplicates land in place (top-level
frames to the right), and paste keeps the copied position, centering an axis
that does not fit the selected frame.

* fix: match Figma for drag edge cases with components, groups, and auto layout

A second round of checks against Figma desktop 126, replaying the same
pointer input in both editors. A component set takes back only its own
variants, and components never go into other components. Groups and
booleans refit their children after a move or nudge, and a group whose
last layer leaves is removed. Pressing inside a selected frame, group, or
component set drags it instead of the layer under the cursor.

Auto layout children dragged out land where they are dropped, drawing
inside auto layout adds to the end of the flow, and wrapped frames insert
on the line under the cursor. Duplicates keep their names, and a main
component duplicates as an instance with Cmd+D or Alt-drag; a multi-layer
duplicate stays in place, and a lone frame in a section counts as
top-level.

* fix(core): refuse new shapes in the locked part of an instance

createShape redirected a refused parent through acceptingParent while keeping coordinates in the original parent's space, and still inserted the layer when the slot claim failed. It now takes the given parent, claims a slot when needed, and throws when the parent refuses children; drawing skips such parents before creating anything.
2026-10-05 12:39:03 +00:00

64 lines
2.3 KiB
TypeScript

import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'
const editor = useEditorSetupWithClear('/?test')
async function rectangleCount() {
return editor.page.evaluate(() => {
const store = window.openPencil?.getStore?.()
if (!store) throw new Error('OpenPencil store not initialized')
return [...store.graph.nodes.values()].filter((node) => node.type === 'RECTANGLE').length
})
}
async function layerItems() {
return editor.page.getByTestId('layers-item').allTextContents()
}
async function historyState() {
return editor.page.evaluate(() => {
const store = window.openPencil?.getStore?.()
if (!store) throw new Error('OpenPencil store not initialized')
return {
canUndo: store.undo.canUndo,
canRedo: store.undo.canRedo,
undoLabel: store.undo.undoLabel,
redoLabel: store.undo.redoLabel
}
})
}
test('undo after option-drag duplicate removes the copy', async () => {
await editor.canvas.drawRect(120, 120, 120, 90)
await expect.poll(rectangleCount).toBe(1)
await editor.canvas.altDrag(180, 165, 340, 165)
await expect.poll(rectangleCount).toBe(2)
await expect.poll(layerItems).toEqual(['Rectangle', 'Rectangle'])
await editor.canvas.undo()
await expect.poll(rectangleCount).toBe(1)
await expect.poll(layerItems).toEqual(['Rectangle'])
await expect.poll(historyState).toMatchObject({ canRedo: true, redoLabel: 'Duplicate' })
await editor.page.waitForTimeout(1500)
await expect.poll(rectangleCount).toBe(1)
await expect.poll(layerItems).toEqual(['Rectangle'])
await expect.poll(historyState).toMatchObject({ canRedo: true, redoLabel: 'Duplicate' })
await editor.page.keyboard.down('Meta')
await editor.page.keyboard.down('Shift')
await editor.page.keyboard.press('KeyZ')
await editor.page.keyboard.up('Shift')
await editor.page.keyboard.up('Meta')
await editor.canvas.waitForRender()
await expect.poll(rectangleCount).toBe(2)
await expect.poll(layerItems).toEqual(['Rectangle', 'Rectangle'])
await expect.poll(historyState).toMatchObject({ canUndo: true, undoLabel: 'Duplicate' })
await editor.page.waitForTimeout(1500)
await expect.poll(rectangleCount).toBe(2)
await expect.poll(layerItems).toEqual(['Rectangle', 'Rectangle'])
await expect.poll(historyState).toMatchObject({ canUndo: true, undoLabel: 'Duplicate' })
editor.canvas.assertNoErrors()
})