mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-25 01:23:23 +00:00
Selecting the tom select option in the dropdown often happened quicker than the search finished. In that case we selected the option from the list of all options and then the search would present the found option again and leave the dropdown open. This didn't cause any trouble in the past because any other action would close the dropdown again. But the new cuprite version didn't trigger the next click on the target element. It would just close the dropdown on the next click without further action. That would then break the next assertion looking for the next open dropdown, which didn't open with the click. Selecting the "active" option means that we wait for the search to finish and present an option as active. Clicking that option closes the dropdown without opening it again.
42 lines
1.6 KiB
Ruby
42 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module TomSelectHelper
|
|
def tomselect_multiselect(value, options)
|
|
tomselect_wrapper = page.find_field(options[:from]).sibling(".ts-wrapper")
|
|
tomselect_wrapper.find(".ts-control").click
|
|
tomselect_wrapper.find(:css, '.ts-dropdown.multi .ts-dropdown-content .option',
|
|
text: value).click
|
|
# Close the dropdown
|
|
page.find("body").click
|
|
end
|
|
|
|
def tomselect_search_and_select(value, options)
|
|
tomselect_wrapper = page.find_field(options[:from]).sibling(".ts-wrapper")
|
|
tomselect_wrapper.find(".ts-control").click
|
|
# Use send_keys as setting the value directly doesn't trigger the search
|
|
tomselect_wrapper.find(:css, '.ts-dropdown input.dropdown-input').send_keys(value)
|
|
tomselect_wrapper.find(:css, '.ts-dropdown .ts-dropdown-content .option.active', text: value).click
|
|
end
|
|
|
|
def tomselect_select(value, options)
|
|
tomselect_wrapper = page.find_field(options[:from]).sibling(".ts-wrapper")
|
|
tomselect_wrapper.find(".ts-control").click
|
|
|
|
tomselect_wrapper.find(:css, '.ts-dropdown .ts-dropdown-content .option', text: value).click
|
|
end
|
|
|
|
def open_tomselect_to_validate!(page, field_name)
|
|
tomselect_wrapper = page.find_field(field_name).sibling(".ts-wrapper")
|
|
tomselect_wrapper.find(".ts-control").click # open the dropdown
|
|
|
|
raise 'Please pass the block for expectations' unless block_given?
|
|
|
|
# execute block containing expectations
|
|
yield
|
|
|
|
tomselect_wrapper.find(
|
|
'.ts-dropdown .ts-dropdown-content .option.active',
|
|
).click # close the dropdown by selecting the already selected value
|
|
end
|
|
end
|