update datepicker_helper and add method to select date

Introduce a new method `select_date_from_datepicker` and then use it on test
This commit is contained in:
Jean-Baptiste Bellet
2021-01-27 21:18:51 +01:00
parent 3ab1d728a1
commit b72ef18ad6
2 changed files with 16 additions and 16 deletions

View File

@@ -471,7 +471,7 @@ feature '
it "displays only line items whose orders meet the date restriction criteria, when changed" do
find('#start_date_filter').click
select_date(Time.zone.today - 8.days)
select_date_from_datepicker Time.zone.today - 8.days
expect(page).to have_selector "tr#li_#{li1.id}"
expect(page).to have_selector "tr#li_#{li2.id}"
@@ -479,7 +479,7 @@ feature '
expect(page).to have_no_selector "tr#li_#{li4.id}"
find('#end_date_filter').click
select_date(Time.zone.today + 1.day)
select_date_from_datepicker Time.zone.today + 1.day
expect(page).to have_selector "tr#li_#{li1.id}"
expect(page).to have_selector "tr#li_#{li2.id}"
@@ -496,7 +496,8 @@ feature '
it "shows a dialog and ignores changes when confirm dialog is accepted" do
page.driver.accept_modal :confirm, text: "Unsaved changes exist and will be lost if you continue." do
fill_in "start_date_filter", with: (Date.current - 9).strftime('%Y-%m-%d')
find('#start_date_filter').click
select_date_from_datepicker Time.zone.today - 9.days
end
expect(page).to have_no_selector "#save-bar"
within("tr#li_#{li2.id} td.quantity") do
@@ -506,7 +507,8 @@ feature '
it "shows a dialog and keeps changes when confirm dialog is rejected" do
page.driver.dismiss_modal :confirm, text: "Unsaved changes exist and will be lost if you continue." do
fill_in "start_date_filter", with: (Date.current - 9).strftime("%F %T")
find('#start_date_filter').click
select_date_from_datepicker Time.zone.today - 9.days
end
expect(page).to have_selector "#save-bar"
within("tr#li_#{li2.id} td.quantity") do
@@ -747,13 +749,4 @@ feature '
visit spree.admin_bulk_order_management_path
expect(page).to have_no_text 'Loading orders'
end
def select_date(date)
# Wait for datepicker to open and be associated to the datepicker trigger.
expect(page).to have_selector("#ui-datepicker-div")
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

@@ -8,9 +8,14 @@ module Features
end
end
def select_date_from_datepicker(date)
navigate_datepicker_to_month date
find('.flatpickr-calendar.open .flatpickr-days .flatpickr-day', 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("%B %Y")
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
@@ -29,7 +34,9 @@ module Features
end
def datepicker_month_and_year
find(".flatpickr-calendar.open .flatpickr-current-month").text
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