class Capybara::ReactDatetime::Picker

The Picker class interacts with the datepicker

Public Class Methods

new() click to toggle source

Initializes the picker

# File lib/capybara-react-datetime.rb, line 60
def initialize
  @element = find_picker
end

Public Instance Methods

find_day(value) click to toggle source

Get the day we want to click on @param value [Fixnum] the day of the desired date @return the DOM element to click on

# File lib/capybara-react-datetime.rb, line 95
      def find_day(value)
        day_xpath = <<-eos
            .//*[contains(concat(' ', @class, ' '), ' rdtDay ')
            and not(contains(concat(' ', @class, ' '), ' rdtOld '))
            and not(contains(concat(' ', @class, ' '), ' rdtNew '))
            and normalize-space(text())='#{value}']
        eos
        days.find :xpath, day_xpath
      end
find_month(value) click to toggle source

Get the month we want to click on @param value [Fixnum] the month of the desired date @return the DOM element to click on

# File lib/capybara-react-datetime.rb, line 88
def find_month(value)
  months.find ".rdtMonth[data-value='#{value - 1}']"
end
find_year(value) click to toggle source

Get the year we want to click on @param value [Fixnum] the year of the desired date @return the DOM element to click on

# File lib/capybara-react-datetime.rb, line 81
def find_year(value)
  years.find '.rdtYear', text: value
end
goto_decade_panel() click to toggle source

Reveals the decade panel

# File lib/capybara-react-datetime.rb, line 65
def goto_decade_panel
  current_month.click if days.visible?
  current_year.click if months.visible?
end
navigate_through_decades(value) click to toggle source

Navigates through the decade panels until the correct one @param value [Fixnum] the year of the desired date

Private Instance Methods

click_next_decade() click to toggle source

Click and display next decade

# File lib/capybara-react-datetime.rb, line 181
def click_next_decade
  years.find('th.rdtNext').click
end
click_prev_decade() click to toggle source

Click and display previous decade

# File lib/capybara-react-datetime.rb, line 176
def click_prev_decade
  years.find('th.rdtPrev').click
end
current_decade() click to toggle source

Get the current decade panel @param (see find_switch) @return (see find_switch)

# File lib/capybara-react-datetime.rb, line 151
def current_decade
  find_switch :years
end
current_decade_minmax() click to toggle source

Get the current decade period @return [Array<Fixnum, Fixnum>] the min and max years of the decade

# File lib/capybara-react-datetime.rb, line 171
def current_decade_minmax
  current_decade.text.split('-').map(&:to_i)
end
current_month() click to toggle source

Get the current month panel @param (see find_switch) @return (see find_switch)

# File lib/capybara-react-datetime.rb, line 165
def current_month
  find_switch :days
end
current_year() click to toggle source

Get the current year panel @param (see find_switch) @return (see find_switch)

# File lib/capybara-react-datetime.rb, line 158
def current_year
  find_switch :months
end
days() click to toggle source

Get the days panel @param (see find_period) @return (see find_period)

# File lib/capybara-react-datetime.rb, line 144
def days
  find_period :days
end
find_period(period) click to toggle source

Get the datepicker panel @param period [:years, :months, :days] the panel's period @return the DOM element of the panel

# File lib/capybara-react-datetime.rb, line 116
def find_period(period)
  @element.find(".rdt#{period.to_s.titleize}", visible: false)
end
find_picker() click to toggle source

Get the datepicker @return the DOM element of the datepicker

# File lib/capybara-react-datetime.rb, line 109
def find_picker
  Capybara.find(:xpath, '//body').find('.rdtPicker')
end
find_switch(period) click to toggle source

Get the up level panel @param (see find_period) @return the DOM element of the switch panel button

# File lib/capybara-react-datetime.rb, line 123
def find_switch(period)
  send(period).find('th.rdtSwitch', visible: false)
end
gap(min, max) click to toggle source

Calculates the distance in decades between min and max @return [Fixnum] the distance in decades between min and max

# File lib/capybara-react-datetime.rb, line 187
def gap(min, max)
  return 0 if min >= max
  (max - min) / 10
end
goto_next_decade(decade_end, value) click to toggle source

Go forward to the wanted decade @param decade_end [Fixnum] the last year of a decade @param value [Fixnum] the year of the desired date

# File lib/capybara-react-datetime.rb, line 202
def goto_next_decade(decade_end, value)
  gap(decade_end, value).times { click_next_decade }
end
goto_prev_decade(value, decade_start) click to toggle source

Go backward to the wanted decade @param value [Fixnum] the year of the desired date @param decade_start [Fixnum] the first year of a decade

# File lib/capybara-react-datetime.rb, line 195
def goto_prev_decade(value, decade_start)
  gap(value, decade_start).times { click_prev_decade }
end
months() click to toggle source

Get the months panel @param (see find_period) @return (see find_period)

# File lib/capybara-react-datetime.rb, line 137
def months
  find_period :months
end
years() click to toggle source

Get the years panel @param (see find_period) @return (see find_period)

# File lib/capybara-react-datetime.rb, line 130
def years
  find_period :years
end