Sha256: bc24afb493c0b4d1c3ac2e153769d32956efe3f585d197ae800dbfe3d1f0b3e6

Contents?: true

Size: 1.05 KB

Versions: 5

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

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

module Capybara
  module Select2
    def select2(value, xpath:, search:)
      expect(page).to have_xpath(xpath)
      select2_container = find(:xpath, xpath)

      expect(select2_container).to have_selector(".select2-selection")
      select2_container.find(".select2-selection").click

      if search
        body = find(:xpath, "//body")
        expect(body).to have_selector(".select2-search input.select2-search__field")
        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

      expect(page).to have_no_content("Searching...")

      body = find(:xpath, "//body")
      expect(body).to have_selector("#{drop_container} li.select2-results__option", text: value)
      body.find("#{drop_container} li.select2-results__option", text: value).click
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
decidim-dev-0.7.4 lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-dev-0.7.3 lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-dev-0.7.2 lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-dev-0.7.1 lib/decidim/dev/test/rspec_support/capybara_select2.rb
decidim-dev-0.7.0 lib/decidim/dev/test/rspec_support/capybara_select2.rb