Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add #have_fields_date_range and #within_table_footer helpers #11

Open
senid231 opened this issue Aug 19, 2020 · 7 comments
Open

add #have_fields_date_range and #within_table_footer helpers #11

senid231 opened this issue Aug 19, 2020 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@senid231
Copy link
Member

senid231 commented Aug 19, 2020

  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).first(:xpath, './/..')
      expect(container.has_css?('.filter_date_range label')).to eq(true)
      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

  def within_table_footer
    within('tfoot > tr') { yield }
  end

  def click_table_scope(text)
    selector = "#{table_scopes_container_selector} > #{table_scope_selector}"
    page.find(selector, exact_text: text).click
  end

  def table_header_selector(text, options = {})
    column = (options[:column] || text).to_s.tr(' ', '_').downcase
    selector = "th.col.col-#{column}"
    selector += '.sortable' if options[:sortable]
    selector += ".sorted-#{options[:sort_direction].to_s.downcase}" if options[:sort_direction].present?
    "thead > tr > #{selector}"
  end

  def have_table_header(text, options = {})
    selector = table_header_selector text, options
    opts = options.except(:column, :sortable, :sort_direction).merge(exact_text: text)
    have_selector(selector, opts)
  end

  def find_table_header(text, options = {})
    selector = table_header_selector text, options
    opts = options.except(:column, :sortable, :sort_direction).merge(exact_text: text)
    page.find(selector, opts)
  end

  def click_table_header(text, options = {})
    find_table_header(text, options).find('a').click
  end
@senid231 senid231 added the enhancement New feature or request label Aug 19, 2020
@senid231 senid231 self-assigned this Aug 19, 2020
@senid231
Copy link
Member Author

def within_sidebar(title)
    sidebar = page.find('#sidebar > .sidebar_section > h3', text: title).ancestor('.sidebar_section')
    within(sidebar) { yield }
  end

@senid231
Copy link
Member Author

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

@senid231
Copy link
Member Author

senid231 commented Nov 1, 2020

# 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

@senid231
Copy link
Member Author

def within_attribute_row(label)
    selector = attributes_row_selector(label)
    within(selector) { yield }
  end

@senid231
Copy link
Member Author

senid231 commented Dec 7, 2021

  def have_status_tag(text, type:, **options)
    selector = ".status_tag.#{type}"
    opts = options.merge exact_text: text
    have_selector(selector, opts)
  end

@senid231
Copy link
Member Author

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

@senid231
Copy link
Member Author

senid231 commented Jun 28, 2023

# @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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant