Register products panel listeners after OrderCycle is loaded instead of using recurrent timeouts

Also, use this same approach for the case where a new distributor or new supplier is added to the list of exchanges
This commit is contained in:
luisramos0
2019-11-16 17:35:36 +00:00
parent 6b087adab8
commit 66f3656bb5
9 changed files with 60 additions and 51 deletions

View File

@@ -11,6 +11,7 @@ describe 'AdminEditOrderCycleCtrl', ->
scope =
order_cycle_form: jasmine.createSpyObj('order_cycle_form', ['$dirty', '$setPristine'])
$watch: jasmine.createSpy('$watch')
exchangeListChanged: jasmine.createSpy('exchangeListChanged')
event =
preventDefault: jasmine.createSpy('preventDefault')
location =
@@ -38,9 +39,6 @@ describe 'AdminEditOrderCycleCtrl', ->
expect(EnterpriseFee.index).toHaveBeenCalled()
expect(scope.enterprise_fees).toEqual('enterprise fees list')
it 'Loads order cycles', ->
expect(OrderCycle.load).toHaveBeenCalledWith('27')
it 'Removes coordinator fees', ->
scope.removeCoordinatorFee(event, 0)
expect(event.preventDefault).toHaveBeenCalled()

View File

@@ -10,9 +10,14 @@ describe 'AdminOrderCycleIncomingCtrl', ->
beforeEach ->
scope =
$watch: jasmine.createSpy('$watch')
exchangeListChanged: jasmine.createSpy('exchangeListChanged')
location =
absUrl: ->
'example.com/admin/order_cycles/27/edit'
event =
preventDefault: jasmine.createSpy('preventDefault')
OrderCycle =
addSupplier: jasmine.createSpy('addSupplier')
ocInstance = {}
module('admin.orderCycles')
@@ -33,3 +38,11 @@ describe 'AdminOrderCycleIncomingCtrl', ->
it 'returns zero when products list is empty', ->
expect(scope.countVariants([])).toEqual(0)
it 'adds order cycle suppliers', ->
scope.new_supplier_id = 'new supplier id'
scope.addSupplier(event)
expect(event.preventDefault).toHaveBeenCalled()
expect(OrderCycle.addSupplier).toHaveBeenCalledWith('new supplier id', scope.exchangeListChanged)

View File

@@ -19,8 +19,6 @@ describe 'AdminOrderCycleExchangesCtrl', ->
OrderCycle =
exchangeSelectedVariants: jasmine.createSpy('exchangeSelectedVariants').and.returnValue('variants selected')
exchangeDirection: jasmine.createSpy('exchangeDirection').and.returnValue('exchange direction')
addSupplier: jasmine.createSpy('addSupplier')
addDistributor: jasmine.createSpy('addDistributor')
removeExchange: jasmine.createSpy('removeExchange')
addExchangeFee: jasmine.createSpy('addExchangeFee')
removeExchangeFee: jasmine.createSpy('removeExchangeFee')
@@ -73,18 +71,6 @@ describe 'AdminOrderCycleExchangesCtrl', ->
expect(OrderCycle.removeExchangeFee).toHaveBeenCalledWith('exchange', 0)
expect(scope.order_cycle_form.$dirty).toEqual true
it 'Adds order cycle suppliers', ->
scope.new_supplier_id = 'new supplier id'
scope.addSupplier(event)
expect(event.preventDefault).toHaveBeenCalled()
expect(OrderCycle.addSupplier).toHaveBeenCalledWith('new supplier id')
it 'Adds order cycle distributors', ->
scope.new_distributor_id = 'new distributor id'
scope.addDistributor(event)
expect(event.preventDefault).toHaveBeenCalled()
expect(OrderCycle.addDistributor).toHaveBeenCalledWith('new distributor id')
it 'Removes distribution of a variant', ->
scope.removeDistributionOfVariant('variant')
expect(OrderCycle.removeDistributionOfVariant).toHaveBeenCalledWith('variant')

View File

@@ -10,11 +10,15 @@ describe 'AdminOrderCycleOutgoingCtrl', ->
beforeEach ->
scope =
$watch: jasmine.createSpy('$watch')
exchangeListChanged: jasmine.createSpy('exchangeListChanged')
location =
absUrl: ->
'example.com/admin/order_cycles/27/edit'
event =
preventDefault: jasmine.createSpy('preventDefault')
OrderCycle =
variantSuppliedToOrderCycle: jasmine.createSpy('variantSuppliedToOrderCycle').and.returnValue('variant supplied')
addDistributor: jasmine.createSpy('addDistributor')
ocInstance = {}
module('admin.orderCycles')
@@ -24,3 +28,11 @@ describe 'AdminOrderCycleOutgoingCtrl', ->
it 'Delegates variantSuppliedToOrderCycle to OrderCycle', ->
expect(scope.variantSuppliedToOrderCycle('variant')).toEqual('variant supplied')
expect(OrderCycle.variantSuppliedToOrderCycle).toHaveBeenCalledWith('variant')
it 'Adds order cycle distributors', ->
scope.new_distributor_id = 'new distributor id'
scope.addDistributor(event)
expect(event.preventDefault).toHaveBeenCalled()
expect(OrderCycle.addDistributor).toHaveBeenCalledWith('new distributor id', scope.exchangeListChanged)