Module: Capybara::ActiveAdmin::Matchers::Layout

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

Overview

Matchers for common Active Admin components.

Instance Method Summary collapse

Instance Method Details

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



8
9
10
11
# File 'lib/capybara/active_admin/matchers/layout.rb', line 8

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

Examples:

expect(page).to have_action_item_link('New User')
expect(page).to have_action_item_link('New User', href: new_admin_user_path)

Parameters:

  • title (String)

    action item link text.

  • exact (Boolean) (defaults to: true)

    whether to match the title exactly (default true).

  • href (String, nil) (defaults to: nil)

    expected href attribute of the link.

  • options (Hash)

    additional options passed to have_selector.



56
57
58
59
60
61
62
# File 'lib/capybara/active_admin/matchers/layout.rb', line 56

def have_action_item_link(title, exact: true, href: nil, **options)
  opts = exact ? { exact_text: title } : { text: title }
  opts.merge!(options)
  selector = "#{action_item_selector} > a"
  selector += "[href=\"#{href}\"]" if href.present?
  have_selector(selector, **opts)
end

#have_batch_action(title, exact: true) ⇒ Object



42
43
44
45
46
# File 'lib/capybara/active_admin/matchers/layout.rb', line 42

def have_batch_action(title, exact: true)
  selector = "#{dropdown_list_selector} #{batch_action_selector}"
  opts = Util.options_with_text(title, exact: exact)
  have_selector(selector, **opts)
end

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



18
19
20
21
22
23
# File 'lib/capybara/active_admin/matchers/layout.rb', line 18

def have_flash_message(text, options = {})
  type = options.delete(:type)
  opts = Util.options_with_text(text, options)
  selector = flash_message_selector(type)
  have_selector(selector, **opts)
end


25
26
27
28
# File 'lib/capybara/active_admin/matchers/layout.rb', line 25

def have_footer(options = {})
  selector = footer_selector
  have_selector(selector, **options)
end

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



13
14
15
16
# File 'lib/capybara/active_admin/matchers/layout.rb', line 13

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

#have_panel(title, options = {}) ⇒ Object



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

def have_panel(title, options = {})
  title_selector = "#{panel_selector} > #{panel_title_selector}"
  opts = Util.options_with_text(title, options)
  have_selector(title_selector, **opts)
end

#have_sidebar(title, options = {}) ⇒ Object



36
37
38
39
40
# File 'lib/capybara/active_admin/matchers/layout.rb', line 36

def have_sidebar(title, options = {})
  title_selector = "#{sidebar_selector} #{panel_selector} > #{panel_title_selector}"
  opts = Util.options_with_text(title, options)
  have_selector(title_selector, **opts)
end

#have_status_tag(type, **options) ⇒ Object

Examples:

expect(page).to have_status_tag(:yes)
expect(page).to have_status_tag(:error, exact_text: 'DOWN')

Parameters:

  • type (String, Symbol)

    status tag type (e.g. :yes, :no, :warning).

  • options (Hash)

    additional options passed to have_selector (e.g. exact_text:).



70
71
72
# File 'lib/capybara/active_admin/matchers/layout.rb', line 70

def have_status_tag(type, **options)
  have_selector("span.status_tag.#{type}", **options)
end