|
| 1 | +import type { Graph } from '@/src'; |
| 2 | +import { CommonEvent } from '@/src'; |
| 3 | +import { bugDragRotatedCanvas } from '@@/demos'; |
| 4 | +import { createDemoGraph, dispatchCanvasEvent } from '@@/utils'; |
| 5 | + |
| 6 | +describe('behavior drag rotated canvas', () => { |
| 7 | + let graph: Graph; |
| 8 | + |
| 9 | + beforeAll(async () => { |
| 10 | + graph = await createDemoGraph(bugDragRotatedCanvas, { animation: false }); |
| 11 | + }); |
| 12 | + |
| 13 | + afterAll(() => { |
| 14 | + graph.destroy(); |
| 15 | + }); |
| 16 | + |
| 17 | + it('drag 30 rotated canvas', async () => { |
| 18 | + await graph.rotateTo(30); |
| 19 | + const [x, y] = graph.getPosition(); |
| 20 | + |
| 21 | + dispatchCanvasEvent(graph, CommonEvent.DRAG_START, { targetType: 'canvas' }); |
| 22 | + dispatchCanvasEvent(graph, CommonEvent.DRAG, { movement: { x: 10, y: 10 }, targetType: 'canvas' }); |
| 23 | + dispatchCanvasEvent(graph, CommonEvent.DRAG_END); |
| 24 | + |
| 25 | + expect(graph.getRotation()).toBe(30); |
| 26 | + expect(graph.getPosition()).toBeCloseTo([x + 3.66, y + 13.66]); |
| 27 | + }); |
| 28 | + |
| 29 | + it('drag 90 rotated canvas', async () => { |
| 30 | + await graph.rotateTo(90); |
| 31 | + const [x, y] = graph.getPosition(); |
| 32 | + |
| 33 | + dispatchCanvasEvent(graph, CommonEvent.DRAG_START, { targetType: 'canvas' }); |
| 34 | + dispatchCanvasEvent(graph, CommonEvent.DRAG, { movement: { x: 10, y: 20 }, targetType: 'canvas' }); |
| 35 | + dispatchCanvasEvent(graph, CommonEvent.DRAG_END); |
| 36 | + |
| 37 | + expect(graph.getRotation()).toBe(90); |
| 38 | + expect(graph.getPosition()).toBeCloseTo([x - 20, y + 10]); |
| 39 | + }); |
| 40 | + |
| 41 | + it('drag 180 rotated canvas', async () => { |
| 42 | + await graph.rotateTo(180); |
| 43 | + const [x, y] = graph.getPosition(); |
| 44 | + |
| 45 | + dispatchCanvasEvent(graph, CommonEvent.DRAG_START, { targetType: 'canvas' }); |
| 46 | + dispatchCanvasEvent(graph, CommonEvent.DRAG, { movement: { x: 10, y: 20 }, targetType: 'canvas' }); |
| 47 | + dispatchCanvasEvent(graph, CommonEvent.DRAG_END); |
| 48 | + |
| 49 | + expect(graph.getRotation()).toBe(180); |
| 50 | + expect(graph.getPosition()).toBeCloseTo([x - 10, y - 20]); |
| 51 | + }); |
| 52 | + |
| 53 | + it('drag 270 rotated canvas', async () => { |
| 54 | + await graph.rotateTo(270); |
| 55 | + const [x, y] = graph.getPosition(); |
| 56 | + |
| 57 | + dispatchCanvasEvent(graph, CommonEvent.DRAG_START, { targetType: 'canvas' }); |
| 58 | + dispatchCanvasEvent(graph, CommonEvent.DRAG, { movement: { x: 10, y: 20 }, targetType: 'canvas' }); |
| 59 | + dispatchCanvasEvent(graph, CommonEvent.DRAG_END); |
| 60 | + |
| 61 | + expect(graph.getRotation()).toBe(270); |
| 62 | + expect(graph.getPosition()).toBeCloseTo([x + 20, y - 10]); |
| 63 | + }); |
| 64 | +}); |
0 commit comments