diff --git a/spec/support/features/datepicker_helper.rb b/spec/support/features/datepicker_helper.rb index 6bb8a2c6b2..4ac09f4a64 100644 --- a/spec/support/features/datepicker_helper.rb +++ b/spec/support/features/datepicker_helper.rb @@ -4,8 +4,7 @@ module Features module DatepickerHelper def choose_today_from_datepicker within(".flatpickr-calendar.open") do - # Now that we have added the Close button, find the first button to avoid any ambiguous match - find('.shortcut-buttons-flatpickr-buttons > button:nth-child(1)').click + find("button", text: "TODAY").click end end diff --git a/spec/system/admin/order_cycles/list_spec.rb b/spec/system/admin/order_cycles/list_spec.rb index 812e8db49f..2af66cd68c 100644 --- a/spec/system/admin/order_cycles/list_spec.rb +++ b/spec/system/admin/order_cycles/list_spec.rb @@ -161,7 +161,7 @@ describe ' within(".flatpickr-calendar.open") do expect(page).to have_selector '.shortcut-buttons-flatpickr-buttons' select_datetime_from_datepicker test_value - find(".shortcut-buttons-flatpickr-buttons > button:nth-last-child(1)").click + find("button", text: "CLOSE").click end # Should no more have opened flatpickr diff --git a/spec/system/flatpickr_spec.rb b/spec/system/flatpickr_spec.rb index 74a863414c..11e1165e7e 100644 --- a/spec/system/flatpickr_spec.rb +++ b/spec/system/flatpickr_spec.rb @@ -7,23 +7,25 @@ describe "Test Flatpickr", js: true do include WebHelper context "orders" do - it "opens the datepicker and closes it using the last button (the 'Close' one)" do + it "opens the datepicker and closes it using the 'CLOSE' button" do login_as_admin_and_visit 'admin/orders' open_datepicker('#q_completed_at_gteq') # Looks for the close button and click it within(".flatpickr-calendar.open") do expect(page).to have_selector '.shortcut-buttons-flatpickr-buttons' - find(".shortcut-buttons-flatpickr-buttons > button:nth-last-child(1)").click + find("button", text: "CLOSE").click end # Should no more have opened flatpickr expect(page).not_to have_selector '.flatpickr-calendar.open' end + it "opens the datepicker and sets date to today" do login_as_admin_and_visit 'admin/orders' open_datepicker('#q_completed_at_gteq') choose_today_from_datepicker check_fielddate('#q_completed_at_gteq', Date.today()) end + it "opens the datepicker and closes it by clicking outside" do login_as_admin_and_visit 'admin/orders' open_datepicker('#q_completed_at_gteq') @@ -33,13 +35,15 @@ describe "Test Flatpickr", js: true do end end -private + private + def open_datepicker(field) # Opens a datepicker find(field).click # Should have opened flatpickr expect(page).to have_selector '.flatpickr-calendar.open' end + def check_fielddate(field, date) # Check the value is correct expect(find(field, match: :first).value).to eq date.to_datetime.strftime("%Y-%m-%d")