mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-18 00:17:25 +00:00
Building out and testing our Product and OrderCycle Angular stuff
This commit is contained in:
@@ -1,30 +1,46 @@
|
||||
describe 'Shop controllers', ->
|
||||
describe 'All controllers', ->
|
||||
describe 'ProductsCtrl', ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
event = null
|
||||
rootScope = null
|
||||
Product = null
|
||||
|
||||
beforeEach ->
|
||||
module('Shop')
|
||||
scope = {}
|
||||
Product =
|
||||
all: ->
|
||||
'testy mctest'
|
||||
inject ($controller) ->
|
||||
inject ($controller, $rootScope) ->
|
||||
rootScope = $rootScope
|
||||
scope = $rootScope.$new()
|
||||
ctrl = $controller 'ProductsCtrl', {$scope: scope, Product : Product}
|
||||
|
||||
it 'Fetches products from Product', ->
|
||||
expect(scope.products).toEqual 'testy mctest'
|
||||
|
||||
#it "updates products when the changeOrderCycle event is seen", ->
|
||||
#spyOn(scope, "updateProducts")
|
||||
#rootScope.$emit "changeOrderCycle"
|
||||
#expect(scope.updateProducts).toHaveBeenCalled()
|
||||
|
||||
describe 'OrderCycleCtrl', ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
event = null
|
||||
rootScope = null
|
||||
product_ctrl = null
|
||||
OrderCycle = null
|
||||
|
||||
beforeEach ->
|
||||
module 'Shop'
|
||||
scope = {}
|
||||
inject ($controller) ->
|
||||
ctrl = $controller 'OrderCycleCtrl'
|
||||
inject ($controller, $rootScope) ->
|
||||
rootScope = $rootScope
|
||||
scope = $rootScope.$new()
|
||||
ctrl = $controller 'OrderCycleCtrl', {$scope: scope}
|
||||
|
||||
#it "triggers an event when the order cycle changes", ->
|
||||
#spyOn(rootScope, "$emit")
|
||||
#scope.changeOrderCycle()
|
||||
#expect(scope.$emit).toHaveBeenCalledWith "changeOrderCycle"
|
||||
|
||||
23
spec/javascripts/unit/darkswarm/order_cycle_spec.js.coffee
Normal file
23
spec/javascripts/unit/darkswarm/order_cycle_spec.js.coffee
Normal file
@@ -0,0 +1,23 @@
|
||||
describe 'OrderCycle service', ->
|
||||
$httpBackend = null
|
||||
OrderCycle = null
|
||||
mockProduct = {
|
||||
update: ->
|
||||
}
|
||||
|
||||
beforeEach ->
|
||||
module 'Shop', ($provide)->
|
||||
$provide.value "Product", mockProduct
|
||||
null # IMPORTANT
|
||||
# You must return null because module() is a bit dumb
|
||||
inject (_OrderCycle_, _$httpBackend_)->
|
||||
$httpBackend = _$httpBackend_
|
||||
OrderCycle = _OrderCycle_
|
||||
|
||||
|
||||
it "posts the order_cycle ID and tells product to update", ->
|
||||
$httpBackend.expectPOST("/shop/order_cycle", {"order_cycle_id" : 10}).respond(200)
|
||||
spyOn(mockProduct, "update")
|
||||
OrderCycle.set_order_cycle(10)
|
||||
$httpBackend.flush()
|
||||
expect(mockProduct.update).toHaveBeenCalled()
|
||||
@@ -8,7 +8,7 @@ describe 'Product service', ->
|
||||
Product = $injector.get("Product")
|
||||
$httpBackend = _$httpBackend_
|
||||
|
||||
it "Fetches products from the backend", ->
|
||||
it "Fetches products from the backend on init", ->
|
||||
$httpBackend.expectGET("/shop/products").respond([{test : "cats"}])
|
||||
products = Product.all()
|
||||
$httpBackend.flush()
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
describe 'Shop services', ->
|
||||
$httpBackend = null
|
||||
Product = null
|
||||
|
||||
beforeEach ->
|
||||
module 'Shop'
|
||||
inject ($injector, _$httpBackend_)->
|
||||
Product = $injector.get("Product")
|
||||
$httpBackend = _$httpBackend_
|
||||
|
||||
it "Fetches products from the backend", ->
|
||||
$httpBackend.expectGET("/shop/products").respond([{test : "cats"}])
|
||||
products = Product.all()
|
||||
$httpBackend.flush()
|
||||
expect(products[0].test).toEqual "cats"
|
||||
@@ -1,18 +0,0 @@
|
||||
describe 'Shop controllers', ->
|
||||
describe 'ProductsCtrl', ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
event = null
|
||||
Product = null
|
||||
|
||||
beforeEach ->
|
||||
module('Shop')
|
||||
scope = {}
|
||||
Product =
|
||||
all: ->
|
||||
'testy mctest'
|
||||
inject ($controller) ->
|
||||
ctrl = $controller 'ProductsCtrl', {$scope: scope, Product : Product}
|
||||
|
||||
it 'Fetches products from Product', ->
|
||||
expect(scope.products).toEqual 'testy mctest'
|
||||
Reference in New Issue
Block a user