module Capybara::ReactDatetime
Adds datepicker interaction facilities to {Capybara}
Constants
- VERSION
the current version of the gem
Public Instance Methods
Selects a date by simulating human interaction with the datepicker @param (see select_simple_date
)
# File lib/capybara-react-datetime.rb, line 40 def select_bootstrap_date(date_input, value) date_input.click picker = Picker.new picker.goto_decade_panel picker.navigate_through_decades value.year picker.find_year(value.year).click picker.find_month(value.month).click picker.find_day(value.day).click fail if Date.parse(date_input.value) != value end
Selects a date by simulating human interaction with the datepicker or filling the input field @param value [#to_date, String] any object that responds to `#to_date` or a parsable date string @param datepicker [:bootstrap, :simple] the datepicker to use (are supported: bootstrap or input field) @param format [String, nil] a valid date format used to format value @param from [String, nil] the path to input field (required if `xpath` is nil) @param xpath [String, nil] the xpath to input field (required if `from` is nil) @param args [Hash] extra args to find the input field
# File lib/capybara-react-datetime.rb, line 13 def select_date(value, datepicker: false, format: nil, from: nil, xpath: nil, **args) fail "Must pass a hash containing 'from' or 'xpath'" if from.nil? && xpath.nil? value = value.respond_to?(:to_date) ? value.to_date : Date.parse(value) date_input = xpath ? find(:xpath, xpath, **args) : find_field(from, **args) if datepicker select_bootstrap_date date_input, value else select_simple_date date_input, value, format end first(:xpath, '//body').click end
Selects a date by filling the input field @param date_input the input field @param value [Date] the date to set @param format [String, nil] a valid date format used to format value
# File lib/capybara-react-datetime.rb, line 32 def select_simple_date(date_input, value, format = nil) value = value.strftime format unless format.nil? date_input.set "#{value}\e" end