mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
OrderCycle can fetch the direction of an exchange (incoming/outgoing)
This commit is contained in:
@@ -21,6 +21,9 @@ angular.module('order_cycle', ['ngResource'])
|
||||
$scope.incomingExchangesVariants = ->
|
||||
OrderCycle.incomingExchangesVariants()
|
||||
|
||||
$scope.exchangeDirection = (exchange) ->
|
||||
OrderCycle.exchangeDirection(exchange)
|
||||
|
||||
$scope.participatingEnterprises = ->
|
||||
$scope.enterprises[id] for id in OrderCycle.participatingEnterpriseIds()
|
||||
|
||||
@@ -82,6 +85,9 @@ angular.module('order_cycle', ['ngResource'])
|
||||
$scope.incomingExchangesVariants = ->
|
||||
OrderCycle.incomingExchangesVariants()
|
||||
|
||||
$scope.exchangeDirection = (exchange) ->
|
||||
OrderCycle.exchangeDirection(exchange)
|
||||
|
||||
$scope.participatingEnterprises = ->
|
||||
$scope.enterprises[id] for id in OrderCycle.participatingEnterpriseIds()
|
||||
|
||||
@@ -141,6 +147,9 @@ angular.module('order_cycle', ['ngResource'])
|
||||
numActiveVariants++ for id, active of exchange.variants when active
|
||||
numActiveVariants
|
||||
|
||||
exchangeDirection: (exchange) ->
|
||||
if this.order_cycle.incoming_exchanges.indexOf(exchange) == -1 then 'outgoing' else 'incoming'
|
||||
|
||||
toggleProducts: (exchange) ->
|
||||
exchange.showProducts = !exchange.showProducts
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ describe 'OrderCycle controllers', ->
|
||||
exchangeSelectedVariants: jasmine.createSpy('exchangeSelectedVariants').andReturn('variants selected')
|
||||
productSuppliedToOrderCycle: jasmine.createSpy('productSuppliedToOrderCycle').andReturn('product supplied')
|
||||
variantSuppliedToOrderCycle: jasmine.createSpy('variantSuppliedToOrderCycle').andReturn('variant supplied')
|
||||
exchangeDirection: jasmine.createSpy('exchangeDirection').andReturn('exchange direction')
|
||||
toggleProducts: jasmine.createSpy('toggleProducts')
|
||||
addSupplier: jasmine.createSpy('addSupplier')
|
||||
addDistributor: jasmine.createSpy('addDistributor')
|
||||
@@ -66,6 +67,10 @@ describe 'OrderCycle controllers', ->
|
||||
expect(scope.variantSuppliedToOrderCycle('variant')).toEqual('variant supplied')
|
||||
expect(OrderCycle.variantSuppliedToOrderCycle).toHaveBeenCalledWith('variant')
|
||||
|
||||
it 'Delegates exchangeDirection to OrderCycle', ->
|
||||
expect(scope.exchangeDirection('exchange')).toEqual('exchange direction')
|
||||
expect(OrderCycle.exchangeDirection).toHaveBeenCalledWith('exchange')
|
||||
|
||||
it 'Finds enterprises participating in the order cycle', ->
|
||||
scope.enterprises =
|
||||
1: {id: 1, name: 'Eaterprises'}
|
||||
@@ -141,6 +146,7 @@ describe 'OrderCycle controllers', ->
|
||||
exchangeSelectedVariants: jasmine.createSpy('exchangeSelectedVariants').andReturn('variants selected')
|
||||
productSuppliedToOrderCycle: jasmine.createSpy('productSuppliedToOrderCycle').andReturn('product supplied')
|
||||
variantSuppliedToOrderCycle: jasmine.createSpy('variantSuppliedToOrderCycle').andReturn('variant supplied')
|
||||
exchangeDirection: jasmine.createSpy('exchangeDirection').andReturn('exchange direction')
|
||||
toggleProducts: jasmine.createSpy('toggleProducts')
|
||||
addSupplier: jasmine.createSpy('addSupplier')
|
||||
addDistributor: jasmine.createSpy('addDistributor')
|
||||
@@ -189,6 +195,10 @@ describe 'OrderCycle controllers', ->
|
||||
expect(scope.variantSuppliedToOrderCycle('variant')).toEqual('variant supplied')
|
||||
expect(OrderCycle.variantSuppliedToOrderCycle).toHaveBeenCalledWith('variant')
|
||||
|
||||
it 'Delegates exchangeDirection to OrderCycle', ->
|
||||
expect(scope.exchangeDirection('exchange')).toEqual('exchange direction')
|
||||
expect(OrderCycle.exchangeDirection).toHaveBeenCalledWith('exchange')
|
||||
|
||||
it 'Finds enterprises participating in the order cycle', ->
|
||||
scope.enterprises =
|
||||
1: {id: 1, name: 'Eaterprises'}
|
||||
@@ -350,6 +360,19 @@ describe 'OrderCycle services', ->
|
||||
result = OrderCycle.exchangeSelectedVariants({variants: {1: true, 2: false, 3: true}})
|
||||
expect(result).toEqual(2)
|
||||
|
||||
describe 'fetching the direction for an exchange', ->
|
||||
it 'returns "incoming" for incoming exchanges', ->
|
||||
exchange = {id: 1}
|
||||
OrderCycle.order_cycle.incoming_exchanges = [exchange]
|
||||
OrderCycle.order_cycle.outgoing_exchanges = []
|
||||
expect(OrderCycle.exchangeDirection(exchange)).toEqual 'incoming'
|
||||
|
||||
it 'returns "outgoing" for outgoing exchanges', ->
|
||||
exchange = {id: 1}
|
||||
OrderCycle.order_cycle.incoming_exchanges = []
|
||||
OrderCycle.order_cycle.outgoing_exchanges = [exchange]
|
||||
expect(OrderCycle.exchangeDirection(exchange)).toEqual 'outgoing'
|
||||
|
||||
describe 'toggling products', ->
|
||||
exchange = null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user