2019-07-25 01:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-06 11:52:18 -05:00
|
|
|
module DragTo
|
2020-10-05 05:08:17 -04:00
|
|
|
# rubocop:disable Metrics/ParameterLists
|
|
|
|
def drag_to(list_from_index: 0, from_index: 0, to_index: 0, list_to_index: 0, selector: '', scrollable: 'body', duration: 1000, perform_drop: true, extra_height: 0)
|
2019-08-23 07:40:56 -04:00
|
|
|
js = <<~JS
|
|
|
|
simulateDrag({
|
|
|
|
scrollable: document.querySelector('#{scrollable}'),
|
|
|
|
duration: #{duration},
|
|
|
|
from: {
|
|
|
|
el: document.querySelectorAll('#{selector}')[#{list_from_index}],
|
|
|
|
index: #{from_index}
|
|
|
|
},
|
|
|
|
to: {
|
|
|
|
el: document.querySelectorAll('#{selector}')[#{list_to_index}],
|
|
|
|
index: #{to_index}
|
|
|
|
},
|
2020-10-05 05:08:17 -04:00
|
|
|
performDrop: #{perform_drop},
|
|
|
|
extraHeight: #{extra_height}
|
2019-08-23 07:40:56 -04:00
|
|
|
});
|
|
|
|
JS
|
|
|
|
evaluate_script(js)
|
2017-01-06 11:52:18 -05:00
|
|
|
|
|
|
|
Timeout.timeout(Capybara.default_max_wait_time) do
|
2017-04-04 13:47:12 -04:00
|
|
|
loop while drag_active?
|
2017-01-06 11:52:18 -05:00
|
|
|
end
|
|
|
|
end
|
2020-10-05 05:08:17 -04:00
|
|
|
# rubocop:enable Metrics/ParameterLists
|
2017-01-06 11:52:18 -05:00
|
|
|
|
|
|
|
def drag_active?
|
2017-04-04 13:47:12 -04:00
|
|
|
page.evaluate_script('window.SIMULATE_DRAG_ACTIVE').nonzero?
|
2017-01-06 11:52:18 -05:00
|
|
|
end
|
|
|
|
end
|