Module: Capybara::TomSelect

Defined in:
decidim-dev/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 Capyabara 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”]) # ‘multiple` input.

Parameters:

  • option_id

    can be the ‘id` value of an option in the select, OR for select multiple inputs, can be an array of such IDs.



17
18
19
20
# File 'decidim-dev/lib/decidim/dev/test/rspec_support/tom_select.rb', line 17

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