Files
openfoodnetwork/spec/support/features/datepicker_helper.rb
Jean-Baptiste Bellet fbd6db89c9 avoid selecting the day in the previous month
When you select date at the end of the month (27,28,29,30,...) it is likely possible that this date is already displayed by the calender but for the previous month.
Avoid this by using css selector :not()
2021-02-08 22:09:06 +01:00

43 lines
1.4 KiB
Ruby

# frozen_string_literal: true
module Features
module DatepickerHelper
def choose_today_from_datepicker
within(".flatpickr-calendar.open") do
find('.shortcut-buttons-flatpickr-button').click
end
end
def select_date_from_datepicker(date)
navigate_datepicker_to_month date
find('.flatpickr-calendar.open .flatpickr-days .flatpickr-day:not(.prevMonthDay)', text: date.strftime("%e").to_s.strip, exact_text: true, match: :first).click
end
def navigate_datepicker_to_month(date, reference_date = Time.zone.today)
month_and_year = date.strftime("%-m %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('.flatpickr-calendar.open .flatpickr-months .flatpickr-prev-month').click
end
def navigate_datepicker_to_next_month
find('.flatpickr-calendar.open .flatpickr-months .flatpickr-next-month').click
end
def datepicker_month_and_year
month = find(".flatpickr-calendar.open .flatpickr-current-month select.flatpickr-monthDropdown-months").value.to_i + 1
year = find(".flatpickr-calendar.open .flatpickr-current-month .numInputWrapper .cur-year").value
return month.to_s + " " + year.to_s
end
end
end