From b72ef18ad647d8414fece3102241bddb654f705f Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Wed, 27 Jan 2021 21:18:51 +0100 Subject: [PATCH] update datepicker_helper and add method to select date Introduce a new method `select_date_from_datepicker` and then use it on test --- .../admin/bulk_order_management_spec.rb | 19 ++++++------------- spec/support/features/datepicker_helper.rb | 13 ++++++++++--- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/spec/features/admin/bulk_order_management_spec.rb b/spec/features/admin/bulk_order_management_spec.rb index 9c6f8fbf13..5a1aae73de 100644 --- a/spec/features/admin/bulk_order_management_spec.rb +++ b/spec/features/admin/bulk_order_management_spec.rb @@ -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 diff --git a/spec/support/features/datepicker_helper.rb b/spec/support/features/datepicker_helper.rb index 8aff099ccb..b54e46bd2c 100644 --- a/spec/support/features/datepicker_helper.rb +++ b/spec/support/features/datepicker_helper.rb @@ -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