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:
- Being able to drag to an item that is not visible until after the drag has started (see this conversation)
- Being able to cancel the drag
- 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)
# 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