Sha256: f4a1a7427854efab90cf9e66074226f949590e2edc6e87494ef6a9e9b569025f

Contents?: true

Size: 1.04 KB

Versions: 8

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

# https://github.com/orchidjs/tom-select/discussions/71#discussioncomment-641757
module Capybara
  module TomSelect
    # 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.
    #
    # @param 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.
    #
    # @example tom_select("#select_id", option_id: "2")
    # @example tom_select("#select_id", option_id: ["2", "10"]) # `multiple` input.
    def tom_select(select_selector, option_id:)
      js_str = %(document.querySelector("#{select_selector}").tomselect.setValue(#{option_id.inspect}))
      execute_script(js_str)
    end
  end
end

RSpec.configure do |config|
  config.include Capybara::TomSelect, type: :system
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
decidim-dev-0.28.5 lib/decidim/dev/test/rspec_support/tom_select.rb
decidim-dev-0.28.4 lib/decidim/dev/test/rspec_support/tom_select.rb
decidim-dev-0.28.3 lib/decidim/dev/test/rspec_support/tom_select.rb
decidim-dev-0.28.2 lib/decidim/dev/test/rspec_support/tom_select.rb
decidim-dev-0.28.1 lib/decidim/dev/test/rspec_support/tom_select.rb
decidim-dev-0.28.0 lib/decidim/dev/test/rspec_support/tom_select.rb
decidim-dev-0.28.0.rc5 lib/decidim/dev/test/rspec_support/tom_select.rb
decidim-dev-0.28.0.rc4 lib/decidim/dev/test/rspec_support/tom_select.rb