Support selecting date in next months

This was causing failures when selecting tomorrow when running tests on
the last day of the month.
This commit is contained in:
Kristina Lim
2019-01-31 19:24:22 +08:00
parent bb51f7e36b
commit fdede83086
2 changed files with 26 additions and 4 deletions

View File

@@ -743,13 +743,11 @@ feature %q{
end
def select_date(date)
current_month = Time.zone.today.strftime("%B")
target_month = date.strftime("%B")
# Wait for datepicker to open and be associated to the datepicker trigger.
expect(page).to have_selector("#ui-datepicker-div")
find('#ui-datepicker-div .ui-datepicker-header .ui-datepicker-prev').click if current_month != target_month
navigate_datepicker_to_month date
find('#ui-datepicker-div .ui-datepicker-calendar .ui-state-default', text: date.strftime("%e").to_s.strip, exact_text: true).click
end
end

View File

@@ -5,5 +5,29 @@ module Features
find(".ui-datepicker-today").click
end
end
def navigate_datepicker_to_month(date, reference_date = Time.zone.today)
month_and_year = date.strftime("%B %Y")
until datepicker_month_and_year == month_and_year.upcase
if date < reference_date
navigate_datepicker_to_previous_month
elsif date > reference_date
navigate_datepicker_to_next_month
end
end
end
def navigate_datepicker_to_previous_month
find('#ui-datepicker-div .ui-datepicker-header .ui-datepicker-prev').click
end
def navigate_datepicker_to_next_month
find('#ui-datepicker-div .ui-datepicker-header .ui-datepicker-next').click
end
def datepicker_month_and_year
find("#ui-datepicker-div .ui-datepicker-title").text
end
end
end