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

36 lines
903 B
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
# 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
2016-09-13 17:45:13 +05:30
def select2(value, options = {})
2017-08-17 22:00:37 +05:30
raise ArgumentError, 'options must be a Hash' unless options.is_a?(Hash)
2014-09-02 18:07:02 +05:30
2015-09-11 14:41:01 +05:30
selector = options.fetch(:from)
2014-09-02 18:07:02 +05:30
2018-03-17 18:26:18 +05:30
first(selector, visible: false)
2014-09-02 18:07:02 +05:30
if options[:multiple]
2017-08-17 22:00:37 +05:30
execute_script("$('#{selector}').select2('val', ['#{value}']).trigger('change');")
2014-09-02 18:07:02 +05:30
else
2017-08-17 22:00:37 +05:30
execute_script("$('#{selector}').select2('val', '#{value}').trigger('change');")
2014-09-02 18:07:02 +05:30
end
end
2017-08-17 22:00:37 +05:30
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
2014-09-02 18:07:02 +05:30
end