module Alchemy::TestSupport::CapybaraHelpers

Public Instance Methods

click_button_with_tooltip(content) click to toggle source
# File lib/alchemy/test_support/capybara_helpers.rb, line 52
def click_button_with_tooltip(content)
  find(%([content="#{content}"] button)).click
end
click_icon(name) click to toggle source
# File lib/alchemy/test_support/capybara_helpers.rb, line 60
def click_icon(name)
  find(%(alchemy-icon[name="#{name}"])).click
end
select2(value, options) click to toggle source

Select2 capybara helper

# File lib/alchemy/test_support/capybara_helpers.rb, line 7
def select2(value, options)
  label = find_label_by_text(options[:from])

  select2_anchor_selector = ".select2-container a"

  if label.has_css?(select2_anchor_selector)
    label.find(select2_anchor_selector).click
  else
    within label.find(:xpath, "..") do
      find(select2_anchor_selector).click
    end
  end

  within_entire_page do
    page.find(
      "div.select2-result-label",
      text: /#{Regexp.escape(value)}/i, match: :prefer_exact
    ).click
  end
end

Private Instance Methods

find_label_by_text(text) click to toggle source
# File lib/alchemy/test_support/capybara_helpers.rb, line 70
def find_label_by_text(text)
  find "label:not(.select2-offscreen)",
    text: /#{Regexp.escape(text)}/i,
    match: :one
rescue Capybara::ElementNotFound
  find %([content="#{text}"]), match: :one
end
within_entire_page(&) click to toggle source
# File lib/alchemy/test_support/capybara_helpers.rb, line 66
def within_entire_page(&)
  within(:xpath, "//body", &)
end