When submitting checkout, if field is invalid, show errors

This commit is contained in:
Rohan Mitchell
2014-11-06 12:53:02 +11:00
parent e8e5f7033c
commit 75b250d3fe
8 changed files with 29 additions and 13 deletions

View File

@@ -33,13 +33,28 @@ describe "CheckoutCtrl", ->
spyOn(storage, "bind").andCallThrough()
scope = $rootScope.$new()
ctrl = $controller 'CheckoutCtrl', {$scope: scope, Checkout: Checkout, CurrentUser: {}}
it "delegates to the service on submit", ->
describe "submitting", ->
event =
preventDefault: ->
spyOn(Checkout, "submit")
scope.purchase(event)
expect(Checkout.submit).toHaveBeenCalled()
beforeEach ->
spyOn(Checkout, "submit")
scope.submitted = false
it "delegates to the service when valid", ->
scope.checkout =
$valid: true
scope.purchase(event)
expect(Checkout.submit).toHaveBeenCalled()
expect(scope.submitted).toBe(true)
it "does nothing when invalid", ->
scope.checkout =
$valid: false
scope.purchase(event)
expect(Checkout.submit).not.toHaveBeenCalled()
expect(scope.submitted).toBe(true)
it "is enabled", ->
expect(scope.enabled).toEqual true