Improved drag-and-drop interface

24 views
Skip to first unread message

Andrew “Percy” Hanna

unread,
Mar 31, 2023, 11:29:09 AMMar 31
to Capybara
Hello all,

I've been using Capybara for many years, and in the last few years we've been adding more and more drag-and-drop specs to cover a lot of our more advanced use cases in our application.

With these additional tests, we've wanted to have better integration level tests for complex drag operations, such as:
  1. Being able to drag to an item that is not visible until after the drag has started (see this conversation)
  2. Being able to cancel the drag
  3. Being able to hover over one or more other targets before completing the drop
This is just an example of some of the more advanced use cases for drag-and-drop that we have wanted for our test coverage.

To this end, I have created a custom HTML5 drag helper that we have started using internally quite successfully. Here are some examples of the advanced use cases it supports:

begin_drag(element) do |dragger|
  # example 1: very simple drop example, but this allows target to be found after the drag starts
  dragger.drop(target)

  # example 2: drag over multiple targets
  dragger.drag_over(target1)
  dragger.drag_over(target2)
  dragger.drop(target3)

  # example 3: cancel drag
  dragger.drag_over(target)
  dragger.cancel
end

If this conversation is better suited as a GH issue, I'm happy to open one there. I'm also happy to contribute to a PR for this change, but I wanted to get at least some idea if it would be worth writing up as a PR before proceeding. If this type of change doesn't make as much sense in Capybara, then I might explore creating this as a gem instead.

Thanks for the great tool!
-Percy

Thomas Walpole

unread,
Apr 2, 2023, 7:06:06 PMApr 2
to Capybara
Hi Percy, 
  Assuming it's mostly implemented in JS I probably wouldn't incorporate it into Capybara right now, and would recommend you releasing as a separate Gem.  The current HTML5 drag implementation is already more JS than I like, and therefore moving further and further away from accurately representing what  an app would experience from the browser.

-- Thomas

Reply all
Reply to author
Forward
0 new messages