mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add aynchronous select2 search helper
select2_search from spree times out after 1 second, so this new method just waits for a result to be returned before attempting to select it
This commit is contained in:
committed by
luisramos0
parent
70502a7a32
commit
118d26b2ff
@@ -118,6 +118,26 @@ module WebHelper
|
||||
page.execute_script "jQuery('#{selector}').select2('close');"
|
||||
end
|
||||
|
||||
def select2_search_async(value, options)
|
||||
id = find_label_by_text(options[:from])
|
||||
options[:from] = "#s2id_#{id}"
|
||||
targetted_select2_search_async(value, options)
|
||||
end
|
||||
|
||||
def targetted_select2_search_async(value, options)
|
||||
page.execute_script %Q{$('#{options[:from]}').select2('open')}
|
||||
page.execute_script "$('#{options[:dropdown_css]} input.select2-input').val('#{value}').trigger('keyup-change');"
|
||||
select_select2_result_async(value)
|
||||
end
|
||||
|
||||
def select_select2_result_async(value)
|
||||
while (page.has_selector? "div.select2-searching") do
|
||||
return if page.has_selector? "div.select2-no-results"
|
||||
sleep 0.2
|
||||
end
|
||||
page.execute_script(%Q{$("div.select2-result-label:contains('#{value}')").mouseup()})
|
||||
end
|
||||
|
||||
def perform_and_ensure(action, *args, assertion)
|
||||
# Buttons/Links/Checkboxes can be unresponsive for a while
|
||||
# so keep clicking them until assertion is satified
|
||||
|
||||
Reference in New Issue
Block a user