From 329ec3455fa94b03e5ccc97c4cbea653dc7f5094 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 19 Jan 2021 16:06:14 +0100 Subject: [PATCH] update order_cycles (both list and simple) tests As we know use a new datepicker (flatpickr), we need to update our test. --- spec/features/admin/order_cycles/list_spec.rb | 10 ++- .../admin/order_cycles/simple_spec.rb | 64 +++++++++---------- 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/spec/features/admin/order_cycles/list_spec.rb b/spec/features/admin/order_cycles/list_spec.rb index a7a4890511..8e2e47c0ab 100644 --- a/spec/features/admin/order_cycles/list_spec.rb +++ b/spec/features/admin/order_cycles/list_spec.rb @@ -132,14 +132,12 @@ feature ' within("tr.order-cycle-#{oc_pt.id}") do expect(find('input.datetimepicker', match: :first).value).to start_with '2012-01-01 00:00' - find('img.ui-datepicker-trigger', match: :first).click + find('input.datetimepicker', match: :first).click end - within("#ui-datepicker-div") do - expect(page).to have_selector 'a.ui-state-active', text: '1' - - click_link '30' - find('button.ui-datepicker-close', match: :first).click + within(".flatpickr-calendar.open") do + expect(page).to have_selector '.flatpickr-day.selected', text: '1' + find('.dayContainer .flatpickr-day', text: "30").click end within("tr.order-cycle-#{oc_pt.id}") do diff --git a/spec/features/admin/order_cycles/simple_spec.rb b/spec/features/admin/order_cycles/simple_spec.rb index 1deeb40933..614401248e 100644 --- a/spec/features/admin/order_cycles/simple_spec.rb +++ b/spec/features/admin/order_cycles/simple_spec.rb @@ -12,63 +12,63 @@ feature ' scenario "updating many order cycle opening/closing times at once", js: true do # Given three order cycles - oc1 = create(:simple_order_cycle) - oc2 = create(:simple_order_cycle) + oc1 = create(:simple_order_cycle, + orders_open_at: Time.zone.local(2000, 12, 12, 12, 12, 0), + orders_close_at: Time.zone.local(2041, 12, 12, 12, 12, 1)) + oc2 = create(:simple_order_cycle, + orders_open_at: Time.zone.local(2000, 12, 12, 12, 12, 2), + orders_close_at: Time.zone.local(2041, 12, 12, 12, 12, 3)) oc3 = create(:simple_order_cycle, - orders_open_at: Time.zone.local(2040, 12, 12, 12, 12, 12), - orders_close_at: Time.zone.local(2041, 12, 12, 12, 12, 12)) + orders_open_at: Time.zone.local(2040, 12, 12, 12, 12, 4), + orders_close_at: Time.zone.local(2041, 12, 12, 12, 12, 5)) # When I go to the order cycles page login_as_admin_and_visit admin_order_cycles_path - # And I fill in some new opening/closing times and save them - within("tr.order-cycle-#{oc1.id}") do - find("input#oc#{oc1.id}_name").set "Updated Order Cycle 1" - find("input#oc#{oc1.id}_orders_open_at").set "2040-12-01 12:00:00" - find("input#oc#{oc1.id}_orders_close_at").set "2040-12-01 12:00:01" + # And I fill in a time using the datepicker + within("tr.order-cycle-#{oc2.id} .orders_open_at") do + # When I trigger the datepicker + find('input.datetimepicker', match: :first).click end + within(".flatpickr-calendar.open") do + # Then select first of month + find('.dayContainer .flatpickr-day', text: "1").click + end + within("tr.order-cycle-#{oc2.id}") do - find("input#oc#{oc2.id}_name").set "Updated Order Cycle 2" - find("input#oc#{oc2.id}_orders_open_at").set "2040-12-01 12:00:02" - find("input#oc#{oc2.id}_orders_close_at").set "2040-12-01 12:00:03" + # Then that date/time should appear on the form + expect(find("input#oc#{oc2.id}_orders_open_at").value).to eq "2000-12-01 12:12" end # And I fill in a time using the datepicker - within("tr.order-cycle-#{oc3.id}") do + within("tr.order-cycle-#{oc3.id} .orders_close_at") do # When I trigger the datepicker - find('img.ui-datepicker-trigger', match: :first).click + find('input.datetimepicker', match: :first).click end - within("#ui-datepicker-div") do - # Then it should display the correct date/time - expect(page).to have_selector 'span.ui-datepicker-month', text: 'DECEMBER' - expect(page).to have_selector 'span.ui-datepicker-year', text: '2040' - expect(page).to have_selector 'a.ui-state-active', text: '12' - - # When I fill in a new date/time - click_link '1' - click_button 'Done' + within(".flatpickr-calendar.open") do + # Then select first of month + find('.dayContainer .flatpickr-day', text: "1").click end within("tr.order-cycle-#{oc3.id}") do # Then that date/time should appear on the form - expect(find("input#oc#{oc3.id}_orders_open_at").value).to eq "2040-12-01 00:00" - - # Manually fill out time - find("input#oc#{oc3.id}_name").set "Updated Order Cycle 3" - find("input#oc#{oc3.id}_orders_open_at").set "2040-12-01 12:00:04" - find("input#oc#{oc3.id}_orders_close_at").set "2040-12-01 12:00:05" + expect(find("input#oc#{oc3.id}_orders_close_at").value).to eq "2041-12-01 12:12" end + # Manually fill out time + find("input#oc#{oc2.id}_name").set "Updated Order Cycle 2" + find("input#oc#{oc3.id}_name").set "Updated Order Cycle 3" + click_button 'Save Changes' # Then my details should have been saved expect(page).to have_selector "#save-bar", text: "Order cycles have been updated." order_cycles = OrderCycle.order("id ASC") - expect(order_cycles.map(&:name)).to eq ["Updated Order Cycle 1", "Updated Order Cycle 2", "Updated Order Cycle 3"] - expect(order_cycles.map { |oc| oc.orders_open_at.sec }).to eq [0, 2, 4] - expect(order_cycles.map { |oc| oc.orders_close_at.sec }).to eq [1, 3, 5] + expect(order_cycles.map(&:name)).to eq ["Order Cycle 1", "Updated Order Cycle 2", "Updated Order Cycle 3"] + expect(order_cycles.map { |oc| oc.orders_open_at.sec }).to eq [0, 0, 4] + expect(order_cycles.map { |oc| oc.orders_close_at.sec }).to eq [1, 3, 0] end scenario "cloning an order cycle" do