Skip to content

Commit

Permalink
Add timepicker helper with added expectation
Browse files Browse the repository at this point in the history
  • Loading branch information
mkllnk committed Dec 12, 2024
1 parent 58c3916 commit a6dbd52
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
11 changes: 11 additions & 0 deletions spec/support/features/datepicker_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 5 additions & 20 deletions spec/system/admin/order_cycles/edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit a6dbd52

Please sign in to comment.