Module: Capybara::TomSelect

Defined in:
lib/decidim/dev/test/rspec_support/tom_select.rb

Instance Method Summary collapse

Instance Method Details

#tom_select(select_selector, option_id:) ⇒ Object

A helper for Capybara tests that need to set values from a tom-select.js input.

This is a really hacky approach using execute_javascript, but it works. Not sure if there is a better way, we could try actually interacting with the on-screen tom-select-provided UI, but we are taking the easy way out for now.

Examples:

tom_select("#select_id", option_id: "2")
tom_select("#select_id", option_id: ["2", "10"]) # For a `multiple` select input.

Parameters:

  • select_selector (String)

    The CSS selector of the select element.

  • option_id (String, Array<String>)

    The ‘id` value of an option in the select. For selects with the `multiple` attribute, this can be an array of such IDs.



20
21
22
23
# File 'lib/decidim/dev/test/rspec_support/tom_select.rb', line 20

def tom_select(select_selector, option_id:)
  js_str = %(document.querySelector("#{select_selector}").tomselect.setValue(#{option_id.inspect}))
  execute_script(js_str)
end