Files
landing-builder/components/wysiwyg/Canvas.drag.test.tsx
T
jaybe 1737ae172e feat(wysiwyg): 캔버스 키보드 nudge/마우스 드래그 + 8px 스냅 (M1 1차)
- Frame/Layer/Object 스키마(zod) 및 테스트
- 키보드 화살표 nudge 시 8px 스냅 적용
- 마우스 드래그 이동 시 8px 스냅 적용
- Canvas 컴포넌트 초기 버전 및 테스트 추가
2025-11-16 21:23:51 +09:00

42 lines
1.2 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { render, fireEvent } from '@testing-library/react'
import { Canvas } from '@/components/wysiwyg/Canvas'
import type { Frame } from '@/lib/wysiwyg/schema'
function makeFrame(): Frame {
return {
id: 'f1',
width: 400,
height: 300,
background: '#ffffff',
layers: [
{
id: 'l1',
name: 'L1',
visible: true,
locked: false,
objects: [
{ id: 'o1', type: 'image', x: 101, y: 100, width: 50, height: 40, rotate: 0, zIndex: 0, props: { src: 'x', alt: '' } },
],
},
],
}
}
describe('WYSIWYG Canvas mouse drag with 8px snap', () => {
it('dragging object snaps to nearest 8px', () => {
const frame = makeFrame()
const { getByTestId } = render(<Canvas frame={frame} />)
const canvas = getByTestId('wysiwyg-canvas')
const obj = getByTestId('obj-o1')
// start drag
fireEvent.mouseDown(obj, { clientX: 200, clientY: 150 })
// move by +5,+5 (should snap from 101->104, 100->104)
fireEvent.mouseMove(canvas, { clientX: 205, clientY: 155 })
fireEvent.mouseUp(canvas)
expect(obj).toHaveStyle({ left: '104px', top: '104px' })
})
})