From a6dbd529d2f262d0a8cd7424948fea3b5184b8c2 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 11 Dec 2024 16:21:56 +1100 Subject: [PATCH] Add timepicker helper with added expectation --- spec/support/features/datepicker_helper.rb | 11 +++++++++ spec/system/admin/order_cycles/edit_spec.rb | 25 +++++---------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/spec/support/features/datepicker_helper.rb b/spec/support/features/datepicker_helper.rb index 74444316a53..e86e32a2f95 100644 --- a/spec/support/features/datepicker_helper.rb +++ b/spec/support/features/datepicker_helper.rb @@ -15,6 +15,17 @@ def select_dates_from_daterangepicker(from, to) select_date_from_datepicker(to) end + def select_datetime_from(element, datetime) + datetime = Time.zone.parse(datetime) if datetime.is_a? String + + # Wait for timepicker element to be loaded: + expect(page).to have_css "#{element}.datetimepicker" + + find(element).click + select_datetime_from_datepicker(datetime) + close_datepicker + end + def select_date_from_datepicker(date) within ".flatpickr-calendar.open" do # Unfortunately, flatpickr doesn't notice a change of year when we do diff --git a/spec/system/admin/order_cycles/edit_spec.rb b/spec/system/admin/order_cycles/edit_spec.rb index f6223edfad9..6a09d7ea22d 100644 --- a/spec/system/admin/order_cycles/edit_spec.rb +++ b/spec/system/admin/order_cycles/edit_spec.rb @@ -39,10 +39,7 @@ expect(page).to have_field 'order_cycle_name', with: "Order cycle name updated" expect(page).to have_content('Your order cycle has been updated.') - # change date range field value - find('#order_cycle_orders_close_at').click - select_datetime_from_datepicker Time.zone.parse("2024-03-30 00:00") - close_datepicker + select_datetime_from "#order_cycle_orders_close_at", "2024-03-30 00:00" expect(page).to have_content('You have unsaved changes') # click save to open warning modal @@ -61,10 +58,7 @@ login_as_admin visit edit_admin_order_cycle_path(order_cycle) - # change date range field value - find('#order_cycle_orders_close_at').click - select_datetime_from_datepicker Time.zone.parse("2024-03-30 00:00") - close_datepicker + select_datetime_from "#order_cycle_orders_open_at", "2024-03-30 00:00" # click save to open warning modal click_button('Save') @@ -94,10 +88,7 @@ expect(page).to have_field 'order_cycle_name', with: 'OC1 name updated' expect(page).to have_content('Your order cycle has been updated.') - # Now change date range field value - find('#order_cycle_orders_close_at').click - select_datetime_from_datepicker Time.zone.parse("2024-03-30 00:00") - close_datepicker + select_datetime_from "#order_cycle_orders_close_at", "2024-03-30 00:00" expect(page).to have_content('You have unsaved changes') click_button('Save') @@ -126,10 +117,7 @@ expect(page).to have_content('Your order cycle has been updated.') expect(page).to have_field 'order_cycle_name', with: "Order cycle name updated" - # change date range field value - find('#order_cycle_orders_close_at').click - select_datetime_from_datepicker Time.zone.parse("2024-03-30 00:00") - close_datepicker + select_datetime_from "#order_cycle_orders_close_at", "2024-03-30 00:00" expect(page).to have_content('You have unsaved changes') @@ -161,10 +149,7 @@ expect(page).to have_content('Your order cycle has been updated.') expect(page.find('#order_cycle_name').value).to eq 'OC1 name updated' - # Now change date range field value - find('#order_cycle_orders_close_at').click - select_datetime_from_datepicker Time.zone.parse("2024-03-30 00:00") - close_datepicker + select_datetime_from "#order_cycle_orders_close_at", "2024-03-30 00:00" expect(page).to have_content('You have unsaved changes') sleep(2)