gitlab-org--gitlab-foss/spec/support/helpers/select2_helper.rb
Paul Slaughter ecc2527032
Add close_select2 method to select2_helper
**Why?**
This is needed to create a feature test for:
https://gitlab.com/gitlab-org/gitlab-ee/issues/11194
2019-05-01 23:14:36 -05:00

45 lines
1.1 KiB
Ruby

require_relative 'wait_for_requests'
# 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 = {})
raise ArgumentError, 'options must be a Hash' unless options.is_a?(Hash)
wait_for_requests unless options[:async]
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
def open_select2(selector)
execute_script("$('#{selector}').select2('open');")
end
def close_select2(selector)
execute_script("$('#{selector}').select2('close');")
end
def scroll_select2_to_bottom(selector)
evaluate_script "$('#{selector}').scrollTop($('#{selector}')[0].scrollHeight); $('#{selector}');"
end
end