GAUD-10597 - Add drag test command - #1069
Conversation
| } | ||
|
|
||
| export async function dragElemBy(elem, offsetX = 0, offsetY = 0) { | ||
| const pixels = 10; // Mimic dragging by moving in 10px increments to the target position |
There was a problem hiding this comment.
I want to simulate a user actually dragging something, which fires events every few pixels. Just moving from one place to another programmatically doesn't fire any intermediate values.
I'm firing every 10px, but this could also just break up the values passed into 5 steps of x pixels. That's likely better for large numbers, whereas this is better for small number (eg not bothering to divide a move of 2 pixels).
| await sendMouse({ type: 'up' }); | ||
| } | ||
|
|
||
| export async function dragElemBy(elem, offsetX = 0, offsetY = 0) { |
There was a problem hiding this comment.
Name is a little odd. I'm trying to follow the pattern of the other helpers in this file, taking x and y offsets as parameters. They work a little differently though, and use "at" terminology, which doesn't make sense here.
But dragElemTo isn't correct, unless I take an x and y location rather than an offset. This is nicer for the helper, worse for the consumer - it's much easier if I can say "Drag it back 5 pixels" instead of "Drag it to spot x = 250".
| }); | ||
|
|
||
| beforeEach(() => { | ||
| pointerEvents.length = 0; |
There was a problem hiding this comment.
Also not sure I love this - was trying to follow the pattern of the file and define this stuff at the top level. But it might be better to just set it and remove it in the tests below, rather than having to clear this value every test, then clear it again after calling the fixture so I don't get any mouse moves as things reset.
There was a problem hiding this comment.
This is what that looks like instead: #1070
Not really tied to how this works at all, so figured I'd get it up and get feedback rather than trying to keep tweaking it.