From a11873559b7d002a2527e5bfd1663c67bdacda74 Mon Sep 17 00:00:00 2001 From: wandji20 Date: Fri, 16 Aug 2024 14:11:55 +0100 Subject: [PATCH] Make OC edit warning modal cancel button redirect user to OC list [OFN-12774] --- ..._date_time_warning_modal_content.html.haml | 3 +-- spec/system/admin/order_cycles/edit_spec.rb | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/views/admin/order_cycles/_date_time_warning_modal_content.html.haml b/app/views/admin/order_cycles/_date_time_warning_modal_content.html.haml index 28246e4e1e..525c1407b7 100644 --- a/app/views/admin/order_cycles/_date_time_warning_modal_content.html.haml +++ b/app/views/admin/order_cycles/_date_time_warning_modal_content.html.haml @@ -11,8 +11,7 @@ = t('.proceed') %button.button.secondary{ "ng-click": "submit($event, '#{main_app.admin_order_cycles_path}')", type: "button", style: "display: none;", data: { action: 'click->modal#close', 'trigger-action': 'saveAndBack' } } = t('.proceed') - %button.button.primary{ type: "button", 'data-action': 'click->modal#close' } - = t('.cancel') + = link_to t('.cancel'), admin_order_cycles_path, id: 'cancel', class: 'button primary' - if action == 'bulk_update' %button.button.secondary{ "ng-click": "saveAll($event)", type: "button", style: "display: none;", data: { action: 'click->modal#close', trigger_action: 'bulk_save' } } diff --git a/spec/system/admin/order_cycles/edit_spec.rb b/spec/system/admin/order_cycles/edit_spec.rb index bb418711ae..adb91dee0e 100644 --- a/spec/system/admin/order_cycles/edit_spec.rb +++ b/spec/system/admin/order_cycles/edit_spec.rb @@ -59,6 +59,31 @@ RSpec.describe ' expect(page).to have_field 'order_cycle_orders_close_at', with: '2024-03-30 00:00' expect(page).to have_content('Your order cycle has been updated.') end + + it "it redirects user to oc list when modal cancel is clicked" do + login_as_admin + visit edit_admin_order_cycle_path(order_cycle) + + # change date range field value + find('#order_cycle_orders_close_at').click + within(".flatpickr-calendar.open") do + expect(page).to have_selector '.shortcut-buttons-flatpickr-buttons' + select_datetime_from_datepicker Time.zone.parse("2024-03-30 00:00") + find("button", text: "Close").click + end + + # click save to open warning modal + click_button('Save') + expect(page).to have_content('You have unsaved changes') + expect(page).to have_content "Orders are linked to this order cycle." + + # Now cancel modal + within('.modal-actions') do + click_link('Cancel') + end + expect(page).not_to have_content('You have unsaved changes') + expect(page).to have_current_path admin_order_cycles_path + end end context 'with no attached order' do