Open senid231 opened 4 years ago
def within_sidebar(title)
sidebar = page.find('#sidebar > .sidebar_section > h3', text: title).ancestor('.sidebar_section')
within(sidebar) { yield }
end
def find_action_item(title, exact: true)
opts = exact ? { exact_text: title } : { text: title }
page.find(action_item_selector, opts)
end
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
def within_action_item_dropdown
within("#{action_item_selector} .dropdown_menu_list_wrapper") { yield }
end
# override Capybara::ActiveAdmin::Selectors::Form#has_many_fields_selector
# @param association_name [String]
# @return [String] selector.
def has_many_fields_selector(association_name)
".has_many_container.#{association_name} > fieldset.inputs.has_many_fields"
end
def within_attribute_row(label)
selector = attributes_row_selector(label)
within(selector) { yield }
end
def have_status_tag(text, type:, **options)
selector = ".status_tag.#{type}"
opts = options.merge exact_text: text
have_selector(selector, opts)
end
def have_table_scope(title, selected: false)
selector = table_scope_selector(selected)
have_selector(selector, exact_text: title.to_s)
end
def table_scope_selector(selected)
if selected
'div.scopes li.scope.selected'
else
'div.scopes li.scope'
end
end
# @example usage
# expect(page).to have_status_tag(:error, exact_text: 'DOWN')
def have_status_tag(type, **options)
have_selector("span.status_tag.#{type}", **options)
end