Sha256: 963732eb20ca9e120164679981f804070bebfadc7842d64ef715142e72906b5b

Contents?: true

Size: 1.21 KB

Versions: 22

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

# extracted from https://github.com/goodwill/capybara-select2

module Capybara
  module Select2
    def select2(value, options = {})
      raise "Must pass a hash containing 'from' or 'xpath' or 'css'" unless options.is_a?(Hash) && [:from, :xpath, :css].any? { |k| options.has_key? k }

      if options.has_key? :xpath
        select2_container = find(:xpath, options[:xpath])
      elsif options.has_key? :css
        select2_container = find(:css, options[:css])
      else
        select_name = options[:from]
        select2_container = find("label", text: select_name).find(:xpath, "..").find(".select2-container")
      end

      # Open select2 field
      select2_container.find(".select2-selection").click

      if options.has_key? :search
        find(:xpath, "//body").find(".select2-search input.select2-search__field").set(value)
        page.execute_script(%|$("input.select2-search__field:visible").keyup();|)
        drop_container = ".select2-results"
      else
        drop_container = ".select2-dropdown"
      end

      [value].flatten.each do |val|
        find(:xpath, "//body").find("#{drop_container} li.select2-results__option", text: val).click
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
decidim-dev-0.6.8 lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-0.6.8 decidim-dev/lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-dev-0.6.7 lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-0.6.7 decidim-dev/lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-dev-0.6.6 lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-0.6.6 decidim-dev/lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-dev-0.6.5 lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-0.6.5 decidim-dev/lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-dev-0.6.4 lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-0.6.4 decidim-dev/lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-dev-0.6.3 lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-0.6.3 decidim-dev/lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-dev-0.6.2 lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-0.6.2 decidim-dev/lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-dev-0.6.1 lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-0.6.1 decidim-dev/lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-dev-0.6.0 lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-0.6.0 decidim-dev/lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-dev-0.5.1 lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-0.5.1 decidim-dev/lib/decidim/dev/test/rspec_support/capybara_select2.rb