Files
landing-builder/components/wysiwyg/Canvas.moveable.target.test.tsx
jaybe 1b1b916a30
Auto PR / open-pr (push) Successful in 18s
Auto Label PR / add-automerge-label (pull_request) Successful in 7s
CI / test (pull_request) Successful in 1m13s
WYSIWYG: Moveable 가이드라인 고도화(중심/가장자리 스냅, 8px 임계) TDD/구현 및 테스트
2025-11-16 23:21:43 +09:00

45 lines
1.4 KiB
TypeScript

import React from 'react'
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render } from '@testing-library/react'
import { Canvas } from '@/components/wysiwyg/Canvas'
import type { Frame } from '@/lib/wysiwyg/schema'
const capture = vi.fn()
vi.mock('react-moveable', () => {
const Mock = (props: Record<string, unknown>) => {
capture(props)
return <div data-testid="moveable" />
}
return { default: Mock }
})
const frame: Frame = {
id: 'f-target',
width: 300,
height: 200,
background: '#fff',
layers: [
{ id: 'l1', name: 'L1', visible: true, locked: false, objects: [
{ id: 'o1', type: 'text', x: 8, y: 8, width: 80, height: 30, rotate: 0, zIndex: 0, props: { text: 'A', fontSize: 16, color: '#000' } },
{ id: 'o2', type: 'text', x: 96, y: 8, width: 80, height: 30, rotate: 0, zIndex: 1, props: { text: 'B', fontSize: 16, color: '#000' } },
]}
]
}
describe('Canvas + Moveable target binding', () => {
beforeEach(() => {
capture.mockReset()
})
it('passes the selected object selector as Moveable target', () => {
const { getByTestId } = render(<Canvas frame={frame} />)
// 기본 선택은 첫 객체(o1)라고 가정
const el = getByTestId('obj-o1')
const last = capture.mock.calls.at(-1)?.[0] as { target?: string }
expect(last).toBeTruthy()
expect(last?.target).toBe('[data-testid="obj-o1"]')
})
})