| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import { describe, expect, it, vi } from 'vitest'
- import {
- completeLineEdit,
- hasLineDragStarted,
- normalizeLineGeometry
- } from '@/components/mt-edit/utils/line-interaction'
- describe('自由连线拖动', () => {
- it('鼠标轻微抖动时不开始拖动', () => {
- expect(hasLineDragStarted(1, 1)).toBe(false)
- expect(hasLineDragStarted(2, 2)).toBe(false)
- expect(hasLineDragStarted(3, 0)).toBe(true)
- })
- it('只在真实拖动结束并写回最终数据后记录历史', () => {
- const calls: string[] = []
- const update = vi.fn(() => calls.push('update'))
- const complete = vi.fn(() => calls.push('history'))
- completeLineEdit({ id: 'line-1' }, false, update, complete)
- expect(calls).toEqual([])
- completeLineEdit({ id: 'line-1' }, true, update, complete)
- expect(calls).toEqual(['update', 'history'])
- })
- it('将 DOM 和缩放计算产生的坐标统一保留两位小数', () => {
- expect(
- normalizeLineGeometry(
- {
- left: 1480.034912109375,
- top: Number('669.9048461914062'),
- width: 100.00000000003,
- height: Number('50.99999999997')
- },
- [
- { x: 0.00000000003, y: 0 },
- { x: 99.99999999997, y: 50.123456 }
- ]
- )
- ).toEqual({
- binfo: { left: 1480.03, top: 669.9, width: 100, height: 51 },
- points: [
- { x: 0, y: 0 },
- { x: 100, y: 50.12 }
- ]
- })
- })
- })
|