class Capybara::ReactDatetime::Picker
The Picker
class interacts with the datepicker
Public Class Methods
Initializes the picker
# File lib/capybara-react-datetime.rb, line 60 def initialize @element = find_picker end
Public Instance Methods
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
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
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
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
Private Instance Methods
Click and display next decade
# File lib/capybara-react-datetime.rb, line 181 def click_next_decade years.find('th.rdtNext').click end
Click and display previous decade
# File lib/capybara-react-datetime.rb, line 176 def click_prev_decade years.find('th.rdtPrev').click end
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
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
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
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
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
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
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
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
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
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
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
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
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