From db0922a7cf95536915a474b2803c8bf6af6a4add Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Mon, 12 May 2025 01:14:51 +0500 Subject: [PATCH 1/7] 13180: increase filter time to 1 year --- .../controllers/line_items_controller.js.coffee | 2 +- spec/system/admin/bulk_order_management_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/admin/line_items/controllers/line_items_controller.js.coffee b/app/assets/javascripts/admin/line_items/controllers/line_items_controller.js.coffee index d10de21f26..d27787f764 100644 --- a/app/assets/javascripts/admin/line_items/controllers/line_items_controller.js.coffee +++ b/app/assets/javascripts/admin/line_items/controllers/line_items_controller.js.coffee @@ -97,7 +97,7 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $timeout, $scope.loadAssociatedData = -> RequestMonitor.load $scope.distributors = Enterprises.index(action: "visible", ams_prefix: "basic", "q[sells_in][]": ["own", "any"]) - RequestMonitor.load $scope.orderCycles = OrderCycles.index(ams_prefix: "basic", as: "distributor", "q[orders_close_at_gt]": "#{moment().subtract(90,'days').format()}") + RequestMonitor.load $scope.orderCycles = OrderCycles.index(ams_prefix: "basic", as: "distributor", "q[orders_close_at_gt]": "#{moment().subtract(1,'year').format()}") RequestMonitor.load $scope.suppliers = Enterprises.index(action: "visible", ams_prefix: "basic", "q[is_primary_producer_eq]": "true") $scope.dereferenceLoadedData = -> diff --git a/spec/system/admin/bulk_order_management_spec.rb b/spec/system/admin/bulk_order_management_spec.rb index 95af4bac5b..020355e76d 100644 --- a/spec/system/admin/bulk_order_management_spec.rb +++ b/spec/system/admin/bulk_order_management_spec.rb @@ -681,6 +681,14 @@ RSpec.describe ' let!(:oc1) { create(:simple_order_cycle, distributors: [distributor]) } let!(:oc2) { create(:simple_order_cycle, distributors: [distributor]) } let!(:oc3) { create(:simple_order_cycle, distributors: [distributor]) } + let!(:oc4) do + create( + :simple_order_cycle, + orders_close_at: 364.days.ago, + orders_open_at: 400.days.ago, + distributors: [distributor] + ) + end let!(:o1) { create(:order_with_distributor, state: 'complete', shipment_state: 'ready', completed_at: Time.zone.now, @@ -701,6 +709,11 @@ RSpec.describe ' completed_at: 2.weeks.from_now, order_cycle: oc3 ) } + let!(:o5) { + create(:order_with_distributor, state: 'complete', shipment_state: 'ready', + completed_at: 100.days.ago, + order_cycle: oc4 ) + } let!(:li1) { create(:line_item_with_shipment, order: o1 ) } let!(:li2) { create(:line_item_with_shipment, order: o2 ) } let!(:li3) { create(:line_item_with_shipment, order: o3 ) } From 6daf94875a4e01f2d4f1f9fcb25569547d0f916a Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 13 May 2025 14:23:51 +1000 Subject: [PATCH 2/7] Rename varianbles based on OC number It was a bit confusing that they don't line up. --- spec/system/admin/bulk_order_management_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/system/admin/bulk_order_management_spec.rb b/spec/system/admin/bulk_order_management_spec.rb index 020355e76d..869bbd66f3 100644 --- a/spec/system/admin/bulk_order_management_spec.rb +++ b/spec/system/admin/bulk_order_management_spec.rb @@ -704,12 +704,12 @@ RSpec.describe ' completed_at: 1.week.from_now, order_cycle: oc3 ) } - let!(:o4) { + let!(:o3a) { create(:order_with_distributor, state: 'complete', shipment_state: 'ready', completed_at: 2.weeks.from_now, order_cycle: oc3 ) } - let!(:o5) { + let!(:o4) { create(:order_with_distributor, state: 'complete', shipment_state: 'ready', completed_at: 100.days.ago, order_cycle: oc4 ) @@ -717,7 +717,7 @@ RSpec.describe ' let!(:li1) { create(:line_item_with_shipment, order: o1 ) } let!(:li2) { create(:line_item_with_shipment, order: o2 ) } let!(:li3) { create(:line_item_with_shipment, order: o3 ) } - let!(:li4) { create(:line_item_with_shipment, order: o4 ) } + let!(:li3a) { create(:line_item_with_shipment, order: o3a ) } before do oc3.update!(orders_close_at: 2.weeks.from_now) From cf30b792f98db0796912de3a7d1fa96689a36f08 Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 13 May 2025 14:32:11 +1000 Subject: [PATCH 3/7] Refactor: move shared code to context --- spec/system/admin/bulk_order_management_spec.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/spec/system/admin/bulk_order_management_spec.rb b/spec/system/admin/bulk_order_management_spec.rb index 869bbd66f3..d2ee525705 100644 --- a/spec/system/admin/bulk_order_management_spec.rb +++ b/spec/system/admin/bulk_order_management_spec.rb @@ -676,7 +676,7 @@ RSpec.describe ' end end - context "order_cycle filter" do + context "order_cycle filter selected" do let!(:distributor) { create(:distributor_enterprise) } let!(:oc1) { create(:simple_order_cycle, distributors: [distributor]) } let!(:oc2) { create(:simple_order_cycle, distributors: [distributor]) } @@ -723,26 +723,22 @@ RSpec.describe ' oc3.update!(orders_close_at: 2.weeks.from_now) oc3.update!(orders_open_at: 1.week.from_now) visit_bulk_order_management + + displays_default_orders + select2_select oc1.name, from: "order_cycle_filter" + page.find('.filter-actions .button.icon-search').click end it "displays a select box for order cycles, which filters line items " \ "by the selected order cycle", retry: 3 do - displays_default_orders expect(page).to have_select2 'order_cycle_filter', with_options: OrderCycle.pluck(:name).unshift("All") - select2_select oc1.name, from: "order_cycle_filter" - page.find('.filter-actions .button.icon-search').click expect(page).not_to have_selector "#loading i" expect(page).to have_selector "tr#li_#{li1.id}" expect(page).not_to have_selector "tr#li_#{li2.id}" end it "displays all line items when 'All' is selected from order_cycle filter", retry: 3 do - displays_default_orders - select2_select oc1.name, from: "order_cycle_filter" - page.find('.filter-actions .button.icon-search').click - expect(page).to have_selector "tr#li_#{li1.id}" - expect(page).not_to have_selector "tr#li_#{li2.id}" select2_select "All", from: "order_cycle_filter" page.find('.filter-actions .button.icon-search').click displays_default_orders From 3b1f267465b1aea7970551e3d66a6f52a120f5b9 Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 13 May 2025 14:36:44 +1000 Subject: [PATCH 4/7] Declare which line items are being expected. --- spec/system/admin/bulk_order_management_spec.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spec/system/admin/bulk_order_management_spec.rb b/spec/system/admin/bulk_order_management_spec.rb index d2ee525705..43638a53cd 100644 --- a/spec/system/admin/bulk_order_management_spec.rb +++ b/spec/system/admin/bulk_order_management_spec.rb @@ -724,7 +724,7 @@ RSpec.describe ' oc3.update!(orders_open_at: 1.week.from_now) visit_bulk_order_management - displays_default_orders + expect_line_items(li1, li2) select2_select oc1.name, from: "order_cycle_filter" page.find('.filter-actions .button.icon-search').click end @@ -741,7 +741,7 @@ RSpec.describe ' it "displays all line items when 'All' is selected from order_cycle filter", retry: 3 do select2_select "All", from: "order_cycle_filter" page.find('.filter-actions .button.icon-search').click - displays_default_orders + expect_line_items(li1, li2) end end @@ -1306,9 +1306,10 @@ RSpec.describe ' expect(page).not_to have_text 'Loading orders' end - def displays_default_orders - expect(page).to have_selector "tr#li_#{li1.id}" - expect(page).to have_selector "tr#li_#{li2.id}" + def expect_line_items(*line_items) + line_items.each do |line_item| + expect(page).to have_selector "tr#li_#{line_item.id}" + end end def expect_line_items_results(line_items, excluded_line_items) From fa9ed1a66b161865a4119311944e3d06a05d4a2e Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 13 May 2025 14:29:17 +1000 Subject: [PATCH 5/7] Add expectation for other line items --- spec/system/admin/bulk_order_management_spec.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/system/admin/bulk_order_management_spec.rb b/spec/system/admin/bulk_order_management_spec.rb index 43638a53cd..002910a99d 100644 --- a/spec/system/admin/bulk_order_management_spec.rb +++ b/spec/system/admin/bulk_order_management_spec.rb @@ -718,13 +718,14 @@ RSpec.describe ' let!(:li2) { create(:line_item_with_shipment, order: o2 ) } let!(:li3) { create(:line_item_with_shipment, order: o3 ) } let!(:li3a) { create(:line_item_with_shipment, order: o3a ) } + let!(:li4) { create(:line_item_with_shipment, order: o4 ) } before do oc3.update!(orders_close_at: 2.weeks.from_now) oc3.update!(orders_open_at: 1.week.from_now) visit_bulk_order_management - expect_line_items(li1, li2) + expect_line_items(li1, li2, li3, li3a, li4) select2_select oc1.name, from: "order_cycle_filter" page.find('.filter-actions .button.icon-search').click end @@ -736,12 +737,14 @@ RSpec.describe ' expect(page).not_to have_selector "#loading i" expect(page).to have_selector "tr#li_#{li1.id}" expect(page).not_to have_selector "tr#li_#{li2.id}" + expect(page).not_to have_selector "tr#li_#{li3.id}" + expect(page).not_to have_selector "tr#li_#{li4.id}" end it "displays all line items when 'All' is selected from order_cycle filter", retry: 3 do select2_select "All", from: "order_cycle_filter" page.find('.filter-actions .button.icon-search').click - expect_line_items(li1, li2) + expect_line_items(li1, li2, li3, li3a, li4) end end From d62740da109568a2db33aea643e08e31addcee59 Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 13 May 2025 14:46:11 +1000 Subject: [PATCH 6/7] Update helper to exclude line items MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _scrolls down_ Oh... JB already did that 😆 Nice to see we were thinking along the same lines. --- spec/system/admin/bulk_order_management_spec.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spec/system/admin/bulk_order_management_spec.rb b/spec/system/admin/bulk_order_management_spec.rb index 002910a99d..152ea1873e 100644 --- a/spec/system/admin/bulk_order_management_spec.rb +++ b/spec/system/admin/bulk_order_management_spec.rb @@ -735,10 +735,8 @@ RSpec.describe ' expect(page).to have_select2 'order_cycle_filter', with_options: OrderCycle.pluck(:name).unshift("All") expect(page).not_to have_selector "#loading i" - expect(page).to have_selector "tr#li_#{li1.id}" - expect(page).not_to have_selector "tr#li_#{li2.id}" - expect(page).not_to have_selector "tr#li_#{li3.id}" - expect(page).not_to have_selector "tr#li_#{li4.id}" + + expect_line_items(li1, excluding: [li2, li3, li3a, li4]) end it "displays all line items when 'All' is selected from order_cycle filter", retry: 3 do @@ -1309,10 +1307,13 @@ RSpec.describe ' expect(page).not_to have_text 'Loading orders' end - def expect_line_items(*line_items) + def expect_line_items(*line_items, excluding: []) line_items.each do |line_item| expect(page).to have_selector "tr#li_#{line_item.id}" end + excluding.each do |line_item| + expect(page).not_to have_selector "tr#li_#{line_item.id}" + end end def expect_line_items_results(line_items, excluded_line_items) From ffea1cca81d29d460c7128eda5e8ecf54ca5cb86 Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 13 May 2025 14:51:39 +1000 Subject: [PATCH 7/7] Replace JB's method with mine Obviously I'm biased, but I like mine better. --- .../admin/bulk_order_management_spec.rb | 41 ++++++++----------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/spec/system/admin/bulk_order_management_spec.rb b/spec/system/admin/bulk_order_management_spec.rb index 152ea1873e..f51bcb8aa7 100644 --- a/spec/system/admin/bulk_order_management_spec.rb +++ b/spec/system/admin/bulk_order_management_spec.rb @@ -191,42 +191,42 @@ RSpec.describe ' fill_in "quick_filter", with: li1.product.name page.find('.filter-actions .button.icon-search').click - expect_line_items_results [li1], [li2, li3] + expect_line_items li1, excluding: [li2, li3] end it "by supplier name" do fill_in "quick_filter", with: li1.variant.supplier.name page.find('.filter-actions .button.icon-search').click - expect_line_items_results [li1], [li2, li3] + expect_line_items li1, excluding: [li2, li3] end it "by email" do fill_in "quick_filter", with: o1.email page.find('.filter-actions .button.icon-search').click - expect_line_items_results [li1], [li2, li3] + expect_line_items li1, excluding: [li2, li3] end it "by order number" do fill_in "quick_filter", with: o1.number page.find('.filter-actions .button.icon-search').click - expect_line_items_results [li1], [li2, li3] + expect_line_items li1, excluding: [li2, li3] end it "by phone number" do fill_in "quick_filter", with: o1.bill_address.phone page.find('.filter-actions .button.icon-search').click - expect_line_items_results [li1], [li2, li3] + expect_line_items li1, excluding: [li2, li3] end it "by distributor name" do fill_in "quick_filter", with: o1.distributor.name page.find('.filter-actions .button.icon-search').click - expect_line_items_results [li1], [li2, li3] + expect_line_items li1, excluding: [li2, li3] end it "by customer name" do @@ -234,59 +234,59 @@ RSpec.describe ' fill_in "quick_filter", with: o1.bill_address.firstname page.find('.filter-actions .button.icon-search').click - expect_line_items_results [li1], [li2, li3] + expect_line_items li1, excluding: [li2, li3] # by lastname fill_in "quick_filter", with: o1.bill_address.lastname page.find('.filter-actions .button.icon-search').click - expect_line_items_results [li1], [li2, li3] + expect_line_items li1, excluding: [li2, li3] # by fullname fill_in "quick_filter", with: "#{o1.bill_address.firstname} #{o1.bill_address.lastname}" page.find('.filter-actions .button.icon-search').click - expect_line_items_results [li1], [li2, li3] + expect_line_items li1, excluding: [li2, li3] fill_in "quick_filter", with: "#{o2.bill_address.firstname} #{o2.bill_address.lastname}" page.find('.filter-actions .button.icon-search').click - expect_line_items_results [li2, li3], [li1] + expect_line_items li2, li3, excluding: [li1] # by fullname reversed fill_in "quick_filter", with: "#{o1.bill_address.lastname} #{o1.bill_address.firstname}" page.find('.filter-actions .button.icon-search').click - expect_line_items_results [li1], [li2, li3] + expect_line_items li1, excluding: [li2, li3] fill_in "quick_filter", with: "#{o2.bill_address.lastname} #{o2.bill_address.firstname}" page.find('.filter-actions .button.icon-search').click - expect_line_items_results [li2, li3], [li1] + expect_line_items li2, li3, excluding: [li1] # by fullname with comma fill_in "quick_filter", with: "#{o1.bill_address.firstname}, #{o1.bill_address.lastname}" page.find('.filter-actions .button.icon-search').click - expect_line_items_results [li1], [li2, li3] + expect_line_items li1, excluding: [li2, li3] fill_in "quick_filter", with: "#{o2.bill_address.firstname}, #{o2.bill_address.lastname}" page.find('.filter-actions .button.icon-search').click - expect_line_items_results [li2, li3], [li1] + expect_line_items li2, li3, excluding: [li1] # by fullname with comma reversed fill_in "quick_filter", with: "#{o1.bill_address.lastname}, #{o1.bill_address.firstname}" page.find('.filter-actions .button.icon-search').click - expect_line_items_results [li1], [li2, li3] + expect_line_items li1, excluding: [li2, li3] fill_in "quick_filter", with: "#{o2.bill_address.lastname}, #{o2.bill_address.firstname}" page.find('.filter-actions .button.icon-search').click - expect_line_items_results [li2, li3], [li1] + expect_line_items li2, li3, excluding: [li1] end end @@ -1315,13 +1315,4 @@ RSpec.describe ' expect(page).not_to have_selector "tr#li_#{line_item.id}" end end - - def expect_line_items_results(line_items, excluded_line_items) - line_items.each do |li| - expect(page).to have_selector "tr#li_#{li.id}" - end - excluded_line_items.each do |li| - expect(page).not_to have_selector "tr#li_#{li.id}" - end - end end