Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored reset password to use controllerAs syntax and default the …
…login from the email through to the form
- Loading branch information
Showing
6 changed files
with
163 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,107 @@ | ||
describe('ResetPassword', () => { | ||
|
||
describe('Configuration', () => { | ||
|
||
let ResetPasswordController:ng.IControllerService, | ||
$scope:ng.IScope, | ||
$mdDialog:ng.material.IDialogService, | ||
$timeout:ng.ITimeoutService, | ||
$rootScope:ng.IRootScopeService, | ||
$q:ng.IQService, | ||
$mdToast:ng.material.IToastService, | ||
userService = { | ||
resetPassword:(email:string) => { | ||
if(email == 'invalid@email.com') { | ||
return $q.reject({data:{message:'this failure message'}}); | ||
} | ||
else { | ||
return $q.when(true); | ||
namespace app.guest.resetPassword { | ||
|
||
describe('ResetPassword', () => { | ||
|
||
describe('Configuration', () => { | ||
|
||
let ResetPasswordController:ResetPasswordController, | ||
$scope:ng.IScope, | ||
$mdDialog:ng.material.IDialogService, | ||
$timeout:ng.ITimeoutService, | ||
$rootScope:ng.IRootScopeService, | ||
$q:ng.IQService, | ||
$mdToast:ng.material.IToastService, | ||
userService = { | ||
resetPassword: (email:string) => { | ||
if (email == 'invalid@email.com') { | ||
return $q.reject({data: {message: 'this failure message'}}); | ||
} | ||
else { | ||
return $q.when(true); | ||
} | ||
} | ||
} | ||
} | ||
; | ||
|
||
beforeEach(() => { | ||
module('app'); | ||
}); | ||
|
||
|
||
beforeEach(()=> { | ||
; | ||
|
||
inject(($controller, _$rootScope_, _$mdDialog_, _$timeout_, _$q_, _$mdToast_) => { | ||
$rootScope = _$rootScope_; | ||
$scope = $rootScope.$new(); | ||
$mdDialog = _$mdDialog_; | ||
$timeout = _$timeout_; | ||
$mdToast = _$mdToast_; | ||
$q = _$q_; | ||
beforeEach(() => { | ||
module('app'); | ||
}); | ||
|
||
ResetPasswordController = $controller(app.guest.resetPassword.namespace+'.controller', { | ||
$scope: $scope, | ||
$mdDialog: $mdDialog, | ||
userService: userService | ||
}); | ||
}) | ||
}); | ||
beforeEach(()=> { | ||
|
||
inject(($controller, _$rootScope_, _$mdDialog_, _$timeout_, _$q_, _$mdToast_) => { | ||
$rootScope = _$rootScope_; | ||
$scope = $rootScope.$new(); | ||
$mdDialog = _$mdDialog_; | ||
$timeout = _$timeout_; | ||
$mdToast = _$mdToast_; | ||
$q = _$q_; | ||
|
||
ResetPasswordController = $controller(app.guest.resetPassword.namespace + '.controller', { | ||
$mdDialog: $mdDialog, | ||
userService: userService, | ||
$mdToast: $mdToast, | ||
defaultEmail: null, | ||
}); | ||
}) | ||
}); | ||
|
||
beforeEach(() => { | ||
beforeEach(() => { | ||
|
||
sinon.spy($mdDialog, 'hide'); | ||
sinon.spy($mdDialog, 'cancel'); | ||
sinon.spy($mdDialog, 'show'); | ||
sinon.spy($mdToast, 'show'); | ||
sinon.spy($mdToast, 'simple'); | ||
sinon.spy($mdDialog, 'hide'); | ||
sinon.spy($mdDialog, 'cancel'); | ||
sinon.spy($mdDialog, 'show'); | ||
sinon.spy($mdToast, 'show'); | ||
sinon.spy($mdToast, 'simple'); | ||
|
||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
afterEach(() => { | ||
|
||
(<any>$mdDialog).hide.restore(); | ||
(<any>$mdDialog).cancel.restore(); | ||
(<any>$mdDialog).show.restore(); | ||
(<any>$mdDialog).hide.restore(); | ||
(<any>$mdDialog).cancel.restore(); | ||
(<any>$mdDialog).show.restore(); | ||
|
||
}); | ||
}); | ||
|
||
describe('dialog interactions - reset password', () => { | ||
describe('dialog interactions - reset password', () => { | ||
|
||
it('should cancel dialog when requested', () => { | ||
it('should cancel dialog when requested', () => { | ||
|
||
(<any>$scope).cancelResetPasswordDialog(); | ||
ResetPasswordController.cancelResetPasswordDialog(); | ||
|
||
$timeout.flush(); //flush timeout as the modal is delayed | ||
$timeout.flush(); //flush timeout as the modal is delayed | ||
|
||
expect($mdDialog.cancel).to.have.been.called; | ||
expect($mdDialog.cancel).to.have.been.called; | ||
|
||
}); | ||
}); | ||
|
||
it('should display an error message when an invalid email is entered', () => { | ||
it('should display an error message when an invalid email is entered', () => { | ||
|
||
let email = 'invalid@email.com'; | ||
let email = 'invalid@email.com'; | ||
|
||
(<any>$scope).resetPassword(email); | ||
ResetPasswordController.resetPassword(email); | ||
|
||
$scope.$apply(); | ||
$scope.$apply(); | ||
|
||
expect($mdToast.show).to.have.been.calledWith(sinon.match.has("template", sinon.match(/this failure message/))); | ||
expect($mdToast.show).to.have.been.calledWith(sinon.match.has("template", sinon.match(/this failure message/))); | ||
|
||
}); | ||
}); | ||
|
||
it('should display a success message when a valid email is entered', () => { | ||
it('should display a success message when a valid email is entered', () => { | ||
|
||
let email = 'valid@email.com'; | ||
let email = 'valid@email.com'; | ||
|
||
(<any>$scope).resetPassword(email); | ||
ResetPasswordController.resetPassword(email); | ||
|
||
$scope.$apply(); | ||
$scope.$apply(); | ||
|
||
expect($mdToast.show).to.have.been.called.and.not.to.be.calledWith(sinon.match.has("template", sinon.match(/this failure message/))); | ||
expect($mdToast.show).to.have.been.called.and.not.to.be.calledWith(sinon.match.has("template", sinon.match(/this failure message/))); | ||
|
||
}); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
} |
Oops, something went wrong.