Files
openfoodnetwork/spec/javascripts/unit/darkswarm/controllers/checkout_controller_spec.js.coffee
2014-04-10 12:54:18 +10:00

45 lines
1.1 KiB
CoffeeScript

describe "CheckoutCtrl", ->
ctrl = null
scope = null
order = null
beforeEach ->
module("Darkswarm")
order = {
submit: ->
}
inject ($controller, $rootScope) ->
scope = $rootScope.$new()
ctrl = $controller 'CheckoutCtrl', {$scope: scope, Order: order}
it "defaults the user accordion to visible", ->
expect(scope.accordion.user).toEqual true
it "delegates to the service on submit", ->
event = {
preventDefault: ->
}
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 ", "