Building out and testing our Product and OrderCycle Angular stuff

This commit is contained in:
Will Marshall
2013-12-11 12:42:33 +11:00
parent 4db8f755bf
commit 44fe304efb
11 changed files with 80 additions and 60 deletions

View File

@@ -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"

View 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()

View File

@@ -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()

View File

@@ -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"

View File

@@ -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'