(element: HTMLElement, options: DragOptionsType)
| 71 | * @param options Drag Options |
| 72 | */ |
| 73 | export async function drag(element: HTMLElement, options: DragOptionsType) { |
| 74 | const { to: inTo, delta, steps = 20, duration = 500 } = options; |
| 75 | let to = Object.assign({}, inTo, { x: 0, y: 0 }); |
| 76 | const from = getElementClientCenter(element); |
| 77 | |
| 78 | if (delta) { |
| 79 | to = { |
| 80 | x: from.x + delta.x, |
| 81 | y: from.y + delta.y, |
| 82 | }; |
| 83 | } |
| 84 | |
| 85 | const step = { |
| 86 | x: (to.x - from.x) / steps, |
| 87 | y: (to.y - from.y) / steps, |
| 88 | }; |
| 89 | |
| 90 | const current = { |
| 91 | clientX: from.x, |
| 92 | clientY: from.y, |
| 93 | }; |
| 94 | |
| 95 | fireEvent.mouseEnter(element, current); |
| 96 | fireEvent.mouseOver(element, current); |
| 97 | fireEvent.mouseMove(element, current); |
| 98 | fireEvent.mouseDown(element, current); |
| 99 | |
| 100 | for (let i = 0; i < steps; i++) { |
| 101 | current.clientX += step.x; |
| 102 | current.clientY += step.y; |
| 103 | await sleep(duration / steps); |
| 104 | fireEvent.mouseMove(element, current); |
| 105 | } |
| 106 | |
| 107 | fireEvent.mouseUp(element, current); |
| 108 | } |
no test coverage detected