mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-07 22:46:06 +00:00
Move preventDefault from service to controller
This commit is contained in:
@@ -3,11 +3,14 @@ describe 'OrderCycle controllers', ->
|
||||
describe 'AdminCreateOrderCycleCtrl', ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
event = null
|
||||
OrderCycle = null
|
||||
Enterprise = null
|
||||
|
||||
beforeEach ->
|
||||
scope = {}
|
||||
event =
|
||||
preventDefault: jasmine.createSpy('preventDefault')
|
||||
OrderCycle =
|
||||
order_cycle: 'my order cycle'
|
||||
toggleProducts: jasmine.createSpy('toggleProducts')
|
||||
@@ -25,13 +28,15 @@ describe 'OrderCycle controllers', ->
|
||||
expect(scope.order_cycle).toEqual('my order cycle')
|
||||
|
||||
it 'Delegates toggleProducts to OrderCycle', ->
|
||||
scope.toggleProducts('event', 'exchange')
|
||||
expect(OrderCycle.toggleProducts).toHaveBeenCalledWith('event', 'exchange')
|
||||
scope.toggleProducts(event, 'exchange')
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.toggleProducts).toHaveBeenCalledWith('exchange')
|
||||
|
||||
it 'Adds order cycle suppliers', ->
|
||||
scope.new_supplier_id = 'new supplier id'
|
||||
scope.addSupplier('event')
|
||||
expect(OrderCycle.addSupplier).toHaveBeenCalledWith('event', 'new supplier id')
|
||||
scope.addSupplier(event)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.addSupplier).toHaveBeenCalledWith('new supplier id')
|
||||
|
||||
it 'Submits the order cycle via OrderCycle create', ->
|
||||
scope.submit()
|
||||
@@ -40,12 +45,15 @@ describe 'OrderCycle controllers', ->
|
||||
describe 'AdminEditOrderCycleCtrl', ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
event = null
|
||||
location = null
|
||||
OrderCycle = null
|
||||
Enterprise = null
|
||||
|
||||
beforeEach ->
|
||||
scope = {}
|
||||
event =
|
||||
preventDefault: jasmine.createSpy('preventDefault')
|
||||
location =
|
||||
absUrl: ->
|
||||
'example.com/admin/order_cycles/27/edit'
|
||||
@@ -66,13 +74,15 @@ describe 'OrderCycle controllers', ->
|
||||
expect(OrderCycle.load).toHaveBeenCalledWith('27')
|
||||
|
||||
it 'Delegates toggleProducts to OrderCycle', ->
|
||||
scope.toggleProducts('event', 'exchange')
|
||||
expect(OrderCycle.toggleProducts).toHaveBeenCalledWith('event', 'exchange')
|
||||
scope.toggleProducts(event, 'exchange')
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.toggleProducts).toHaveBeenCalledWith('exchange')
|
||||
|
||||
it 'Adds order cycle suppliers', ->
|
||||
scope.new_supplier_id = 'new supplier id'
|
||||
scope.addSupplier('event')
|
||||
expect(OrderCycle.addSupplier).toHaveBeenCalledWith('event', 'new supplier id')
|
||||
scope.addSupplier(event)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.addSupplier).toHaveBeenCalledWith('new supplier id')
|
||||
|
||||
it 'Submits the order cycle via OrderCycle update', ->
|
||||
scope.submit()
|
||||
@@ -134,46 +144,30 @@ describe 'OrderCycle services', ->
|
||||
outgoing_exchanges: []
|
||||
|
||||
describe 'toggling products', ->
|
||||
event = null
|
||||
exchange = null
|
||||
|
||||
beforeEach ->
|
||||
event =
|
||||
preventDefault: jasmine.createSpy('preventDefault')
|
||||
exchange = {}
|
||||
|
||||
it 'prevents the default action', ->
|
||||
OrderCycle.toggleProducts(event, exchange)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
|
||||
it 'sets a blank value to true', ->
|
||||
OrderCycle.toggleProducts(event, exchange)
|
||||
OrderCycle.toggleProducts(exchange)
|
||||
expect(exchange.showProducts).toEqual(true)
|
||||
|
||||
it 'sets a true value to false', ->
|
||||
exchange.showProducts = true
|
||||
OrderCycle.toggleProducts(event, exchange)
|
||||
OrderCycle.toggleProducts(exchange)
|
||||
expect(exchange.showProducts).toEqual(false)
|
||||
|
||||
it 'sets a false value to true', ->
|
||||
exchange.showProducts = false
|
||||
OrderCycle.toggleProducts(event, exchange)
|
||||
OrderCycle.toggleProducts(exchange)
|
||||
expect(exchange.showProducts).toEqual(true)
|
||||
|
||||
describe 'adding suppliers', ->
|
||||
event = null
|
||||
exchange = null
|
||||
|
||||
beforeEach ->
|
||||
event =
|
||||
preventDefault: jasmine.createSpy('preventDefault')
|
||||
|
||||
it 'prevents the default action', ->
|
||||
OrderCycle.addSupplier(event, '123')
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
|
||||
it 'adds the supplier to incoming exchanges', ->
|
||||
OrderCycle.addSupplier(event, '123')
|
||||
OrderCycle.addSupplier('123')
|
||||
expect(OrderCycle.order_cycle.incoming_exchanges).toEqual [
|
||||
{enterprise_id: '123', active: true}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user