|
| 1 | +import { DragManager } from '@src/components/InfiniteTable/components/draggable/DragManager'; |
| 2 | +import { test, expect } from '@playwright/test'; |
| 3 | +import { Rectangle } from '@infinite-table/infinite-react/src/utils/pageGeometry/Rectangle'; |
| 4 | +import { PointCoords } from '@infinite-table/infinite-react/src/utils/pageGeometry/Point'; |
| 5 | +import { DragInteractionTarget } from '@infinite-table/infinite-react/src/components/InfiniteTable/components/draggable/DragInteractionTarget'; |
| 6 | + |
| 7 | +export default test.describe.parallel('DND', () => { |
| 8 | + test('should work for simple vertical list, no other interaction', () => { |
| 9 | + /** |
| 10 | + * list1 |
| 11 | + * |
| 12 | + * +--- top: 0, left: 0 ----------+ |
| 13 | + * | item1 | |
| 14 | + * +----bottom: 100, right: 50 ---+ |
| 15 | + * |
| 16 | + * +--- top: 120, left: 0 --------+ |
| 17 | + * | item2 | |
| 18 | + * +----bottom: 220, right: 50 ---+ |
| 19 | + * |
| 20 | + * +--- top: 240, left: 0 --------+ |
| 21 | + * | item3 | |
| 22 | + * +----bottom: 340, right: 50 ---+ |
| 23 | + */ |
| 24 | + |
| 25 | + const draggableItems = [ |
| 26 | + { |
| 27 | + id: 'item1', |
| 28 | + rect: Rectangle.from({ |
| 29 | + top: 0, |
| 30 | + left: 0, |
| 31 | + height: 100, |
| 32 | + width: 50, |
| 33 | + }).toDOMRect(), |
| 34 | + }, |
| 35 | + { |
| 36 | + id: 'item2', |
| 37 | + rect: Rectangle.from({ |
| 38 | + top: 120, |
| 39 | + left: 0, |
| 40 | + height: 100, |
| 41 | + width: 50, |
| 42 | + }).toDOMRect(), |
| 43 | + }, |
| 44 | + { |
| 45 | + id: 'item3', |
| 46 | + rect: Rectangle.from({ |
| 47 | + top: 240, |
| 48 | + left: 0, |
| 49 | + height: 100, |
| 50 | + width: 50, |
| 51 | + }).toDOMRect(), |
| 52 | + }, |
| 53 | + ]; |
| 54 | + |
| 55 | + const list1 = new DragInteractionTarget({ |
| 56 | + orientation: 'vertical', |
| 57 | + listId: 'list1', |
| 58 | + initial: true, |
| 59 | + listRectangle: Rectangle.from({ |
| 60 | + top: 0, |
| 61 | + left: 0, |
| 62 | + height: 360, |
| 63 | + width: 50, |
| 64 | + }), |
| 65 | + draggableItems, |
| 66 | + }); |
| 67 | + |
| 68 | + DragManager.registerDragInteractionTarget(list1); |
| 69 | + const dragOperation = DragManager.startDrag( |
| 70 | + { |
| 71 | + listId: 'list1', |
| 72 | + dragIndex: 0, |
| 73 | + dragItem: draggableItems[0], |
| 74 | + }, |
| 75 | + { |
| 76 | + top: 10, |
| 77 | + left: 10, |
| 78 | + }, |
| 79 | + ); |
| 80 | + |
| 81 | + let theOffsets: PointCoords[][] = []; |
| 82 | + list1.on('move', ({ offsetsForItems }) => { |
| 83 | + theOffsets.push(offsetsForItems); |
| 84 | + }); |
| 85 | + |
| 86 | + dragOperation.move({ |
| 87 | + top: 30, |
| 88 | + left: 10, |
| 89 | + }); |
| 90 | + |
| 91 | + expect(theOffsets).toEqual([ |
| 92 | + [ |
| 93 | + { left: 0, top: 20 }, |
| 94 | + { left: 0, top: 0 }, |
| 95 | + { left: 0, top: 0 }, |
| 96 | + ], |
| 97 | + ]); |
| 98 | + |
| 99 | + dragOperation.move({ |
| 100 | + top: 100, |
| 101 | + left: 10, |
| 102 | + }); |
| 103 | + |
| 104 | + expect(theOffsets.length).toEqual(2); |
| 105 | + |
| 106 | + expect(theOffsets[1]).toEqual([ |
| 107 | + { left: 0, top: 90 }, |
| 108 | + { left: 0, top: -100 }, |
| 109 | + { left: 0, top: 0 }, |
| 110 | + ]); |
| 111 | + |
| 112 | + dragOperation.move({ |
| 113 | + top: 101, |
| 114 | + left: 10, |
| 115 | + }); |
| 116 | + dragOperation.move({ |
| 117 | + top: 102, |
| 118 | + left: 10, |
| 119 | + }); |
| 120 | + |
| 121 | + expect(theOffsets[theOffsets.length - 1]).toEqual([ |
| 122 | + { left: 0, top: 92 }, |
| 123 | + { left: 0, top: -100 }, |
| 124 | + { left: 0, top: 0 }, |
| 125 | + ]); |
| 126 | + }); |
| 127 | +}); |
0 commit comments