Treat not seeing the mousedown event the same as it being default prevented
This commit is contained in:
parent
a7ef932643
commit
de62b4ff9b
|
@ -89,6 +89,7 @@ class Capybara::Selenium::Node
|
|||
JS
|
||||
|
||||
MOUSEDOWN_TRACKER = <<~JS
|
||||
window.capybara_mousedown_prevented = null;
|
||||
document.addEventListener('mousedown', ev => {
|
||||
window.capybara_mousedown_prevented = ev.defaultPrevented;
|
||||
}, { once: true, passive: true })
|
||||
|
@ -96,7 +97,10 @@ class Capybara::Selenium::Node
|
|||
|
||||
LEGACY_DRAG_CHECK = <<~JS
|
||||
(function(el){
|
||||
if (window.capybara_mousedown_prevented) return true;
|
||||
if ([true, null].indexOf(window.capybara_mousedown_prevented) >= 0){
|
||||
return true;
|
||||
}
|
||||
|
||||
do {
|
||||
if (el.draggable) return false;
|
||||
} while (el = el.parentElement );
|
||||
|
|
|
@ -444,6 +444,20 @@ Capybara::SpecHelper.spec 'node' do
|
|||
end
|
||||
end
|
||||
|
||||
it 'should work with jsTree' do
|
||||
@session.visit('/with_jstree')
|
||||
@session.within(:css, '#container') do
|
||||
@session.assert_text(/A.*B.*C/m)
|
||||
source = @session.find(:css, '#j1_1_anchor')
|
||||
target = @session.find(:css, '#j1_2_anchor')
|
||||
|
||||
source.drag_to(target)
|
||||
|
||||
@session.assert_no_text(/A.*B.*C/m)
|
||||
@session.assert_text(/B.*C/m)
|
||||
end
|
||||
end
|
||||
|
||||
context 'HTML5', requires: %i[js html5_drag] do
|
||||
it 'should HTML5 drag and drop an object' do
|
||||
@session.visit('/with_js')
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
|
||||
<title>with_jstree</title>
|
||||
</head>
|
||||
<body id="with_jstree">
|
||||
<div id="container">
|
||||
<ul>
|
||||
<li>Child node A</li>
|
||||
<li>Child node B</li>
|
||||
<li>Child node C</li>
|
||||
</ul>
|
||||
</div>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.8/jstree.min.js"></script>
|
||||
<script>
|
||||
$(function () {
|
||||
$('#container').jstree({
|
||||
"core" : { "check_callback" : true }, // so that operations work
|
||||
"plugins" : ["dnd"]
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue