Working with ngForm and subcontrollers. Also fixing bulk order specs

This commit is contained in:
Will Marshall
2014-04-10 16:32:08 +10:00
parent 00f5d09d65
commit 5f62cb7ddb
15 changed files with 205 additions and 172 deletions

View File

@@ -23,20 +23,19 @@ describe "AdminOrderMgmtCtrl", ->
httpBackend.expectGET("/api/order_cycles/managed").respond returnedOrderCycles
spyOn(scope, "initialiseVariables").andCallThrough()
spyOn(scope, "fetchOrders").andReturn "nothing"
spyOn(returnedSuppliers, "unshift")
spyOn(returnedDistributors, "unshift")
spyOn(returnedOrderCycles, "unshift")
#spyOn(returnedSuppliers, "unshift")
#spyOn(returnedDistributors, "unshift")
#spyOn(returnedOrderCycles, "unshift")
scope.initialise "api_key"
httpBackend.flush()
#expect(scope.suppliers).toEqual ["list of suppliers"]
expect(scope.distributors).toEqual ["list of distributors"]
expect(scope.orderCycles).toEqual [ "oc1", "oc2", "oc3" ]
expect(scope.initialiseVariables.calls.length).toEqual 1
expect(scope.fetchOrders.calls.length).toEqual 1
expect(returnedSuppliers.unshift.calls.length).toEqual 1
expect(returnedDistributors.unshift.calls.length).toEqual 1
expect(returnedOrderCycles.unshift.calls.length).toEqual 1
expect(scope.spree_api_key_ok).toEqual true
expect(scope.suppliers).toEqual [{ id : '', name : 'All' }, 'list of suppliers']
expect(scope.distributors).toEqual [ { id : '', name : 'All' }, 'list of distributors' ]
expect(scope.orderCycles).toEqual [ { id : '', name : 'All' }, 'oc1', 'oc2', 'oc3' ]
expect(scope.initialiseVariables.calls.length).toBe 1
expect(scope.fetchOrders.calls.length).toBe 1
expect(scope.spree_api_key_ok).toBe true
describe "fetching orders", ->
beforeEach ->

View File

@@ -0,0 +1,31 @@
describe "DetailsCtrl", ->
ctrl = null
scope = null
order = null
beforeEach ->
module("Darkswarm")
inject ($controller, $rootScope) ->
scope = $rootScope.$new()
ctrl = $controller 'DetailsCtrl', {$scope: scope}
it "finds a field by path", ->
scope.details =
path: "test"
expect(scope.field('path')).toEqual "test"
it "tests validity", ->
scope.details =
path:
$dirty: true
$invalid: true
expect(scope.fieldValid('path')).toEqual false
it "returns errors by path", ->
scope.details =
path:
$error:
email: true
required: true
expect(scope.fieldErrors('path')).toEqual ["must be email address", "must not be blank"].join ", "

View File

@@ -7,6 +7,7 @@ describe "CheckoutCtrl", ->
module("Darkswarm")
order = {
submit: ->
navigate: ->
}
inject ($controller, $rootScope) ->
scope = $rootScope.$new()
@@ -22,23 +23,3 @@ describe "CheckoutCtrl", ->
spyOn(order, "submit")
scope.purchase(event)
expect(order.submit).toHaveBeenCalled()
it "finds a field by path", ->
scope.checkout =
path: "test"
expect(scope.field('path')).toEqual "test"
it "tests validity", ->
scope.checkout =
path:
$dirty: true
$invalid: true
expect(scope.fieldValid('path')).toEqual false
it "returns errors by path", ->
scope.checkout =
path:
$error:
email: true
required: true
expect(scope.fieldErrors('path')).toEqual ["must be email address", "must not be blank"].join ", "

View File

@@ -7,8 +7,8 @@ describe 'Order service', ->
orderData = {
id: 3102
payment_method_id: null
bill_address: {}
ship_address: {}
bill_address: {test: "foo"}
ship_address: {test: "bar"}
shipping_methods:
7:
require_ship_address: true
@@ -26,12 +26,14 @@ describe 'Order service', ->
inject ($injector, _$httpBackend_)->
$httpBackend = _$httpBackend_
Order = $injector.get("Order")
spyOn(Order, "navigate") # Stubbing out writes to window.location
it "defaults the shipping method to the first", ->
expect(Order.order.shipping_method_id).toEqual 7
expect(Order.shippingMethod()).toEqual { require_ship_address : true, price : 0 }
it "defaults to 'same as billing' for address", ->
# This is now handled via localStorage defaults
xit "defaults to 'same as billing' for address", ->
expect(Order.order.ship_address_same_as_billing).toEqual true
it 'Tracks whether a ship address is required', ->
@@ -59,3 +61,9 @@ describe 'Order service', ->
expect(Order.preprocess().bill_address).toBe(undefined)
expect(Order.preprocess().ship_address_attributes).not.toBe(undefined)
expect(Order.preprocess().ship_address).toBe(undefined)
it "Munges the order attributes to clone ship address from bill address", ->
Order.order.ship_address_same_as_billing = false
expect(Order.preprocess().ship_address_attributes).toEqual(orderData.ship_address)
Order.order.ship_address_same_as_billing = true
expect(Order.preprocess().ship_address_attributes).toEqual(orderData.bill_address)