Skip to content

add #have_fields_date_range and #within_table_footer helpers #11

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions