mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Only reloading line_items and orders on BOM, $timeout for adding blankOption
$timeout required for adding a blank option to lists of suppliers, distributors and orderCycles to prevent spec failures related to the use of select2
This commit is contained in:
@@ -4,6 +4,5 @@ angular.module("admin.indexUtils").directive "select2MinSearch", ($timeout) ->
|
||||
element.select2
|
||||
minimumResultsForSearch: attrs.select2MinSearch
|
||||
|
||||
ngModel.$formatters.push (value) ->
|
||||
scope.$watch attrs.ngModel, (newVal, oldVal) ->
|
||||
$timeout -> element.trigger('change')
|
||||
value
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $http, $q, Columns, Dereferencer, Orders, LineItems, Enterprises, OrderCycles, blankOption, VariantUnitManager, RequestMonitor) ->
|
||||
angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $timeout, $http, $q, Columns, Dereferencer, Orders, LineItems, Enterprises, OrderCycles, blankOption, VariantUnitManager, RequestMonitor) ->
|
||||
$scope.initialized = false
|
||||
$scope.RequestMonitor = RequestMonitor
|
||||
$scope.saving = false
|
||||
@@ -40,10 +40,12 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $http, $q
|
||||
$scope.endDate = OrderCycles.orderCyclesByID[$scope.orderCycleFilter].last_order
|
||||
|
||||
RequestMonitor.load $scope.orders = Orders.index("q[state_not_eq]": "canceled", "q[completed_at_not_null]": "true", "q[completed_at_gt]": "#{$scope.startDate}", "q[completed_at_lt]": "#{$scope.endDate}")
|
||||
RequestMonitor.load $scope.distributors = Enterprises.index(action: "for_line_items", ams_prefix: "basic", "q[sells_in][]": ["own", "any"] )
|
||||
RequestMonitor.load $scope.orderCycles = OrderCycles.index(ams_prefix: "basic", as: "distributor", "q[orders_close_at_gt]": "#{formatDate(daysFromToday(-90))}")
|
||||
RequestMonitor.load $scope.lineItems = LineItems.index("q[order][state_not_eq]": "canceled", "q[order][completed_at_not_null]": "true", "q[order][completed_at_gt]": "#{$scope.startDate}", "q[order][completed_at_lt]": "#{$scope.endDate}")
|
||||
RequestMonitor.load $scope.suppliers = Enterprises.index(action: "for_line_items", ams_prefix: "basic", "q[is_primary_producer_eq]": "true" )
|
||||
|
||||
unless $scope.initialized
|
||||
RequestMonitor.load $scope.distributors = Enterprises.index(action: "for_line_items", ams_prefix: "basic", "q[sells_in][]": ["own", "any"] )
|
||||
RequestMonitor.load $scope.orderCycles = OrderCycles.index(ams_prefix: "basic", as: "distributor", "q[orders_close_at_gt]": "#{formatDate(daysFromToday(-90))}")
|
||||
RequestMonitor.load $scope.suppliers = Enterprises.index(action: "for_line_items", ams_prefix: "basic", "q[is_primary_producer_eq]": "true" )
|
||||
|
||||
RequestMonitor.load $q.all([$scope.orders.$promise, $scope.distributors.$promise, $scope.orderCycles.$promise]).then ->
|
||||
Dereferencer.dereferenceAttr $scope.orders, "distributor", Enterprises.enterprisesByID
|
||||
@@ -52,13 +54,14 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $http, $q
|
||||
RequestMonitor.load $q.all([$scope.orders.$promise, $scope.suppliers.$promise, $scope.lineItems.$promise]).then ->
|
||||
Dereferencer.dereferenceAttr $scope.lineItems, "supplier", Enterprises.enterprisesByID
|
||||
Dereferencer.dereferenceAttr $scope.lineItems, "order", Orders.ordersByID
|
||||
$scope.orderCycles.unshift blankOption()
|
||||
$scope.suppliers.unshift blankOption()
|
||||
$scope.distributors.unshift blankOption()
|
||||
$scope.bulk_order_form.$setPristine()
|
||||
unless $scope.initialized
|
||||
$scope.initialized = true
|
||||
$scope.resetSelectFilters()
|
||||
$timeout ->
|
||||
$scope.orderCycles.unshift blankOption()
|
||||
$scope.suppliers.unshift blankOption()
|
||||
$scope.distributors.unshift blankOption()
|
||||
$scope.resetSelectFilters()
|
||||
|
||||
$scope.refreshData()
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ feature %q{
|
||||
visit '/admin/orders/bulk_management'
|
||||
end
|
||||
|
||||
it "displays a select box for distributors, which filters line items by the selected distributor", retry: 3 do
|
||||
it "displays a select box for distributors, which filters line items by the selected distributor" do
|
||||
distributor_names = ["All"]
|
||||
Enterprise.is_distributor.each{ |e| distributor_names << e.name }
|
||||
find("div.select2-container#s2id_distributor_filter").click
|
||||
@@ -258,7 +258,7 @@ feature %q{
|
||||
expect(page).to_not have_selector "tr#li_#{li2.id}", visible: true
|
||||
end
|
||||
|
||||
it "displays all line items when 'All' is selected from distributor filter", retry: 3 do
|
||||
it "displays all line items when 'All' is selected from distributor filter" do
|
||||
select2_select d1.name, from: "distributor_filter"
|
||||
expect(page).to have_selector "tr#li_#{li1.id}", visible: true
|
||||
expect(page).to_not have_selector "tr#li_#{li2.id}", visible: true
|
||||
@@ -281,7 +281,7 @@ feature %q{
|
||||
visit '/admin/orders/bulk_management'
|
||||
end
|
||||
|
||||
it "displays a select box for order cycles, which filters line items by the selected order cycle", retry: 3 do
|
||||
it "displays a select box for order cycles, which filters line items by the selected order cycle" do
|
||||
expect(page).to have_selector '#s2id_order_cycle_filter a.select2-choice', text: 'All'
|
||||
expect(page).to have_select2 'order_cycle_filter', with_options: OrderCycle.pluck(:name).unshift("All")
|
||||
expect(page).to have_selector "tr#li_#{li1.id}"
|
||||
@@ -292,7 +292,7 @@ feature %q{
|
||||
expect(page).to_not have_selector "tr#li_#{li2.id}"
|
||||
end
|
||||
|
||||
it "displays all line items when 'All' is selected from order_cycle filter", retry: 3 do
|
||||
it "displays all line items when 'All' is selected from order_cycle filter" do
|
||||
select2_select oc1.name, from: "order_cycle_filter"
|
||||
expect(page).to have_selector "tr#li_#{li1.id}"
|
||||
expect(page).to_not have_selector "tr#li_#{li2.id}"
|
||||
@@ -337,7 +337,7 @@ feature %q{
|
||||
expect(page).to have_selector "tr#li_#{li2.id}", visible: true
|
||||
end
|
||||
|
||||
it "displays a 'Clear All' button which sets all select filters to 'All'", retry: 3 do
|
||||
it "displays a 'Clear All' button which sets all select filters to 'All'" do
|
||||
select2_select oc1.name, from: "order_cycle_filter"
|
||||
select2_select d1.name, from: "distributor_filter"
|
||||
select2_select s1.name, from: "supplier_filter"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
describe "LineItemsCtrl", ->
|
||||
ctrl = scope = httpBackend = VariantUnitManager = Enterprises = Orders = LineItems = OrderCycles = null
|
||||
ctrl = scope = httpBackend = $timeout = VariantUnitManager = Enterprises = Orders = LineItems = OrderCycles = null
|
||||
supplier = distributor = orderCycle = null
|
||||
|
||||
beforeEach ->
|
||||
@@ -9,9 +9,10 @@ describe "LineItemsCtrl", ->
|
||||
toDeepEqual: (expected) ->
|
||||
return angular.equals(this.actual, expected)
|
||||
|
||||
beforeEach inject(($controller, $rootScope, $httpBackend, _VariantUnitManager_, _Enterprises_, _Orders_, _LineItems_, _OrderCycles_) ->
|
||||
beforeEach inject(($controller, $rootScope, $httpBackend, _$timeout_, _VariantUnitManager_, _Enterprises_, _Orders_, _LineItems_, _OrderCycles_) ->
|
||||
scope = $rootScope.$new()
|
||||
ctrl = $controller
|
||||
$timeout = _$timeout_
|
||||
httpBackend = $httpBackend
|
||||
Enterprises = _Enterprises_
|
||||
Orders = _Orders_
|
||||
@@ -27,14 +28,14 @@ describe "LineItemsCtrl", ->
|
||||
lineItem = { id: 7, quantity: 3, order: { id: 9 }, supplier: { id: 1 } }
|
||||
|
||||
httpBackend.expectGET("/admin/orders.json?q%5Bcompleted_at_gt%5D=SomeDate&q%5Bcompleted_at_lt%5D=SomeDate&q%5Bcompleted_at_not_null%5D=true&q%5Bstate_not_eq%5D=canceled").respond [order]
|
||||
httpBackend.expectGET("/admin/line_items.json?q%5Border%5D%5Bcompleted_at_gt%5D=SomeDate&q%5Border%5D%5Bcompleted_at_lt%5D=SomeDate&q%5Border%5D%5Bcompleted_at_not_null%5D=true&q%5Border%5D%5Bstate_not_eq%5D=canceled").respond [lineItem]
|
||||
httpBackend.expectGET("/admin/enterprises/for_line_items.json?ams_prefix=basic&q%5Bsells_in%5D%5B%5D=own&q%5Bsells_in%5D%5B%5D=any").respond [distributor]
|
||||
httpBackend.expectGET("/admin/order_cycles.json?ams_prefix=basic&as=distributor&q%5Borders_close_at_gt%5D=SomeDate").respond [orderCycle]
|
||||
httpBackend.expectGET("/admin/line_items.json?q%5Border%5D%5Bcompleted_at_gt%5D=SomeDate&q%5Border%5D%5Bcompleted_at_lt%5D=SomeDate&q%5Border%5D%5Bcompleted_at_not_null%5D=true&q%5Border%5D%5Bstate_not_eq%5D=canceled").respond [lineItem]
|
||||
httpBackend.expectGET("/admin/enterprises/for_line_items.json?ams_prefix=basic&q%5Bis_primary_producer_eq%5D=true").respond [supplier]
|
||||
|
||||
scope.bulk_order_form = jasmine.createSpyObj('bulk_order_form', ['$setPristine'])
|
||||
|
||||
ctrl "LineItemsCtrl", {$scope: scope, Enterprises: Enterprises, Orders: Orders, LineItems: LineItems, OrderCycles: OrderCycles}
|
||||
ctrl "LineItemsCtrl", {$scope: scope, $timeout: $timeout, Enterprises: Enterprises, Orders: Orders, LineItems: LineItems, OrderCycles: OrderCycles}
|
||||
)
|
||||
|
||||
describe "before data is returned", ->
|
||||
@@ -53,6 +54,7 @@ describe "LineItemsCtrl", ->
|
||||
describe "after data is returned", ->
|
||||
beforeEach ->
|
||||
httpBackend.flush()
|
||||
$timeout.flush()
|
||||
|
||||
describe "initialisation", ->
|
||||
it "gets suppliers, adds a blank option as the first in the list", ->
|
||||
|
||||
Reference in New Issue
Block a user