mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-01 21:47:16 +00:00
Make total number of products in exchange work again.
Currently we are just loading the products from the server and count them. This can be improved easily in two ways: - we can switch this to a specific product count call to the server so that we dont load all products all the time - or we paginate the products result and fetch the total_number from the payload of the first page.
This commit is contained in:
@@ -13,14 +13,23 @@ describe 'AdminOrderCycleIncomingCtrl', ->
|
||||
location =
|
||||
absUrl: ->
|
||||
'example.com/admin/order_cycles/27/edit'
|
||||
Enterprise =
|
||||
totalVariants: jasmine.createSpy('totalVariants').and.returnValue('variants total')
|
||||
ocInstance = {}
|
||||
|
||||
module('admin.orderCycles')
|
||||
inject ($controller) ->
|
||||
ctrl = $controller 'AdminOrderCycleIncomingCtrl', {$scope: scope, $location: location, OrderCycle: OrderCycle, Enterprise: Enterprise, EnterpriseFee: EnterpriseFee, ocInstance: ocInstance}
|
||||
|
||||
it 'Delegates totalVariants to Enterprise', ->
|
||||
expect(scope.enterpriseTotalVariants('enterprise')).toEqual('variants total')
|
||||
expect(Enterprise.totalVariants).toHaveBeenCalledWith('enterprise')
|
||||
it 'counts total variants in a list of products', ->
|
||||
products = [
|
||||
{variants: [{}]},
|
||||
{variants: [{}]},
|
||||
{variants: [{}, {}, {}]}
|
||||
]
|
||||
|
||||
expect(scope.countVariants(products)).toEqual(5)
|
||||
|
||||
it 'returns zero when products list is null', ->
|
||||
expect(scope.countVariants(null)).toEqual(0)
|
||||
|
||||
it 'returns zero when products list is empty', ->
|
||||
expect(scope.countVariants([])).toEqual(0)
|
||||
|
||||
@@ -56,16 +56,3 @@ describe 'Enterprise service', ->
|
||||
master_id: 1
|
||||
variants: [{id: 2}, {id: 3}]
|
||||
expect(Enterprise.variantsOf(p)).toEqual [2, 3]
|
||||
|
||||
it 'counts total variants supplied by an enterprise', ->
|
||||
enterprise =
|
||||
supplied_products: [
|
||||
{variants: []},
|
||||
{variants: []},
|
||||
{variants: [{}, {}, {}]}
|
||||
]
|
||||
|
||||
expect(Enterprise.totalVariants(enterprise)).toEqual(5)
|
||||
|
||||
it 'returns zero when enterprise is null', ->
|
||||
expect(Enterprise.totalVariants(null)).toEqual(0)
|
||||
|
||||
Reference in New Issue
Block a user