gitlab-org--gitlab-foss/spec/support/select2_helper.rb
Dmitriy Zaporozhets 80ea344e42 Trigger change even in select2 test helper to produce production-like behaviour
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2016-10-24 13:14:00 +03:00

25 lines
627 B
Ruby

# 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
def select2(value, options = {})
raise ArgumentError, 'options must be a Hash' unless options.kind_of?(Hash)
selector = options.fetch(:from)
if options[:multiple]
execute_script("$('#{selector}').select2('val', ['#{value}']).trigger('change');")
else
execute_script("$('#{selector}').select2('val', '#{value}').trigger('change');")
end
end
end