17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/bootstrap_datepicker_spec.rb', line 17
def select_date(value_string)
value = Date.parse(value_string)
@node.click
page = @node.send(:session)
picker = page.find('.datepicker')
picker_years = picker.find('.datepicker-years', visible: false)
picker_months = picker.find('.datepicker-months', visible: false)
picker_days = picker.find('.datepicker-days', visible: false)
picker_current_decade = picker_years.find('th.datepicker-switch', visible: false)
picker_current_year = picker_months.find('th.datepicker-switch', visible: false)
picker_current_month = picker_days.find('th.datepicker-switch', visible: false)
picker_current_month.trigger("click") if picker_days.visible?
picker_current_year.trigger("click") if picker_months.visible?
decade_start, decade_end = picker_current_decade.text.split('-').map(&:to_i)
if value.year < decade_start.to_i
gap = decade_start / 10 - value.year / 10
gap.times { picker_years.find('th.prev').trigger("click") }
elsif value.year > decade_end
gap = value.year / 10 - decade_end / 10
gap.times { picker_years.find('th.next').trigger("click") }
end
picker_years.find('.year', text: value.year).trigger("click")
picker_months.find('.month', text: value.strftime('%b')).trigger("click")
day_xpath = " .//*[contains(concat(' ', @class, ' '), ' day ')\n and not(contains(concat(' ', @class, ' '), ' old '))\n and not(contains(concat(' ', @class, ' '), ' new '))\n and normalize-space(text())='\#{value.day}']\n eos\n picker_days.find(:xpath, day_xpath).trigger :click\n\n # fail unless page.has_no_css? '.datepicker'\nend\n"
|