capybara icon indicating copy to clipboard operation
capybara copied to clipboard

Add `dragenter` event and test to `drag_to`

Open matt17r opened this issue 2 years ago • 1 comments

Fire a dragenter event before the two dragover events.

The spec requires a dragenter event to be fired first:

To accept a drop, the drop target has to listen to at least three events. First, the dragenter event, which is used to determine whether or not the drop target is to accept the drop.

Addresses #2576

This is my first code contribution and I'm much more comfortable in Ruby than JavaScript so please let me know if I've done this badly or misunderstood the JavaScript side of things!

matt17r avatar Oct 19 '22 02:10 matt17r

Perhaps also add a test that verifies that the dragenter is dispatched before the dragover?

boris-petrov avatar Oct 21 '22 06:10 boris-petrov

How about checking for both at the same time, @boris-petrov? Looks a bit ugly to me but since I need to check their order anyway, this finds the element in question then checks the dragover occurs next using preceding-sibling

matt17r avatar Oct 21 '22 12:10 matt17r

Isn't it possible to do something like expect(page).to have_text(/DragEnter.*DragOver/)?

boris-petrov avatar Oct 21 '22 12:10 boris-petrov

That's much simpler! Events are listed in reverse chronological order...

image

It's not obvious reading the test and I couldn't think of a way to make it explicit in code so I added a comment. There's a similar comment on what's currently line 562

matt17r avatar Oct 21 '22 14:10 matt17r

Whoops, now the test isn't passing. Bear with me 🙃

matt17r avatar Oct 21 '22 14:10 matt17r

~Ugh, I'm trying to rebase against master, squash it all into a single commit and then force push to my branch but I clearly don't know what I'm doing~

Edit: Rebased and squashed to keep the history clean

matt17r avatar Oct 21 '22 14:10 matt17r