gitlab-org--gitlab-foss/spec/support/helpers/select2_helper.rb

42 lines
1,014 B
Ruby
Raw Normal View History

require_relative 'wait_for_requests'
2013-07-29 06:46:00 -04:00
# Select2 ajax programmatic helper
# It allows you to select value from select2
#
# Params
# value - real value of selected item
# opts - options containing css selector
#
# Usage:
#
# select2(2, from: '#user_ids')
#
module Select2Helper
include WaitForRequests
def select2(value, options = {})
2017-02-22 12:25:50 -05:00
raise ArgumentError, 'options must be a Hash' unless options.is_a?(Hash)
wait_for_requests unless options[:async]
2015-06-22 14:52:41 -04:00
selector = options.fetch(:from)
first(selector, visible: false)
if options[:multiple]
execute_script("$('#{selector}').select2('val', ['#{value}']).trigger('change');")
else
execute_script("$('#{selector}').select2('val', '#{value}').trigger('change');")
end
end
2017-03-30 08:14:32 -04:00
def open_select2(selector)
execute_script("$('#{selector}').select2('open');")
end
def scroll_select2_to_bottom(selector)
evaluate_script "$('#{selector}').scrollTop($('#{selector}')[0].scrollHeight); $('#{selector}');"
end
end