debian-mirror-gitlab/spec/support/helpers/drag_to_helper.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

34 lines
998 B
Ruby
Raw Permalink Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module DragTo
2021-01-03 14:25:43 +05:30
# 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-12-04 20:38:33 +05:30
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}
},
2021-01-03 14:25:43 +05:30
performDrop: #{perform_drop},
extraHeight: #{extra_height}
2019-12-04 20:38:33 +05:30
});
JS
evaluate_script(js)
2017-08-17 22:00:37 +05:30
Timeout.timeout(Capybara.default_max_wait_time) do
loop while drag_active?
end
end
2021-01-03 14:25:43 +05:30
# rubocop:enable Metrics/ParameterLists
2017-08-17 22:00:37 +05:30
def drag_active?
page.evaluate_script('window.SIMULATE_DRAG_ACTIVE').nonzero?
end
end