Module: Capybara::ActiveAdmin::Matchers::Form

Defined in:
lib/capybara/active_admin/matchers/form.rb

Instance Method Summary collapse

Instance Method Details

#have_fields_date_range(label, options = {}) ⇒ Object

Examples:

expect(page).to have_fields_date_range('Created At', from: '2020-01-01', to: '2020-12-31')

Parameters:

  • label (String)

    label text of the date range filter.

  • options (Hash) (defaults to: {})
  • from (Hash)

    a customizable set of options

  • to (Hash)

    a customizable set of options

  • exact (Hash)

    a customizable set of options



44
45
46
47
48
49
50
51
52
53
# File 'lib/capybara/active_admin/matchers/form.rb', line 44

def have_fields_date_range(label, options = {})
  exact = options[:exact]
  satisfy do |actual|
    expect(actual).to have_selector('div.filter_date_range label', text: label)
    container = actual.find('div.filter_date_range label', text: label).ancestor('div.filter_date_range')
    base_name = container[:id].gsub(/_input\z/, '')
    expect(container).to have_field("#{base_name}_gteq_datetime", with: options[:from].to_s, exact: exact)
    expect(container).to have_field("#{base_name}_lteq_datetime", with: options[:to].to_s, exact: exact)
  end
end

#have_form_error(text, options = {}) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/capybara/active_admin/matchers/form.rb', line 7

def have_form_error(text, options = {})
  field = options.delete(:field)
  opts = Util.options_with_text(text, options)
  li_selector = input_container_selector field, **options.slice(:exact)

  have_selector("#{li_selector} #{inline_error_selector}", **opts)
end

#have_has_many_fields_for(association_name, options = {}) ⇒ Object



31
32
33
34
# File 'lib/capybara/active_admin/matchers/form.rb', line 31

def have_has_many_fields_for(association_name, options = {})
  selector = has_many_fields_selector(association_name)
  have_selector(selector, **options)
end

#have_no_form_errors(options = {}) ⇒ Object



15
16
17
18
19
20
# File 'lib/capybara/active_admin/matchers/form.rb', line 15

def have_no_form_errors(options = {})
  field = options.delete(:field)
  li_selector = input_container_selector field, **options.slice(:exact)

  have_none_of_selectors(:css, "#{li_selector} #{inline_error_selector}", **options)
end

#have_semantic_error(text, options = {}) ⇒ Object



22
23
24
25
# File 'lib/capybara/active_admin/matchers/form.rb', line 22

def have_semantic_error(text, options = {})
  opts = Util.options_with_text(text, options)
  have_selector(semantic_error_selector, **opts)
end

#have_semantic_errors(options = {}) ⇒ Object



27
28
29
# File 'lib/capybara/active_admin/matchers/form.rb', line 27

def have_semantic_errors(options = {})
  have_selector(semantic_error_selector, **options)
end

#have_submit_input(text, options = {}) ⇒ Object

Examples:

expect(page).to have_submit_input('Submit') # check that submit input is present
expect(page).to have_submit_input('Submit', selector: '.custom-class') # check custom class presence
expect(page).to have_submit_input('Submit', disabled: true) # check that submit input is disabled
expect(page).to have_submit_input('Submit', disabled: true, count: 0) # check that submit input is enabled

Parameters:

  • text (String)

    button title

  • options (Hash) (defaults to: {})
  • selector (Hash)

    a customizable set of options

  • disabled (Hash)

    a customizable set of options



65
66
67
68
69
# File 'lib/capybara/active_admin/matchers/form.rb', line 65

def have_submit_input(text, options = {})
  selector = "#{form_submit_selector(text)}#{options.delete(:selector)}"
  selector += '[disabled="disabled"].disabled' if options.delete(:disabled)
  have_selector(selector, **options)
end