From b18bf7c9028caa93e1f1fbc9364f139ed848a1a4 Mon Sep 17 00:00:00 2001 From: Tara Gibbs Date: Thu, 11 Feb 2016 13:51:24 -0800 Subject: [PATCH 1/2] 13 - add unit tests for failed login message --- src/app/view/application.directive.spec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/app/view/application.directive.spec.js b/src/app/view/application.directive.spec.js index d55f507fef..ea25f3498a 100644 --- a/src/app/view/application.directive.spec.js +++ b/src/app/view/application.directive.spec.js @@ -53,6 +53,14 @@ expect(applicationCtrl.loggedIn).toBe(false); }); + it('should have properties `failedLogin` defined', function () { + expect(applicationCtrl.failedLogin).toBeDefined(); + }); + + it('should have properties `failedLogin` defined as false by default', function () { + expect(applicationCtrl.failedLogin).toBe(false); + }); + // method definitions it('should have method `login` defined', function () { @@ -67,6 +75,10 @@ expect(angular.isFunction(applicationCtrl.onLoggedIn)).toBe(true); }); + it('should have method `onLoginFailed` defined', function () { + expect(angular.isFunction(applicationCtrl.onLoginFailed)).toBe(true); + }); + it('should have method `onLoggedOut` defined', function () { expect(angular.isFunction(applicationCtrl.onLoggedOut)).toBe(true); }); @@ -80,6 +92,7 @@ applicationCtrl.login('dev', 'dev'); $httpBackend.flush(); expect(applicationCtrl.loggedIn).toBe(true); + expect(applicationCtrl.failedLogin).toBe(false); }); it('invoke `login` method - failure', function () { @@ -89,6 +102,7 @@ applicationCtrl.login('dev', 'dev'); $httpBackend.flush(); expect(applicationCtrl.loggedIn).toBe(false); + expect(applicationCtrl.failedLogin).toBe(true); }); it('invoke `logout` method - success', function () { @@ -98,6 +112,7 @@ applicationCtrl.logout(); $httpBackend.flush(); expect(applicationCtrl.loggedIn).toBe(false); + expect(applicationCtrl.failedLogin).toBe(false); }); it('invoke `logout` method - failure', function () { @@ -107,6 +122,7 @@ applicationCtrl.logout(); $httpBackend.flush(); expect(applicationCtrl.loggedIn).toBe(true); + expect(applicationCtrl.failedLogin).toBe(false); }); }); From 3d9e617ed6c9459cfb50baad5c7d3fb5c104644e Mon Sep 17 00:00:00 2001 From: Tara Gibbs Date: Thu, 11 Feb 2016 14:12:32 -0800 Subject: [PATCH 2/2] 13 - add unit tests for checking that password is cleared on failed login --- .../login-page/login-form/login-form.directive.spec.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/app/view/login-page/login-form/login-form.directive.spec.js b/src/app/view/login-page/login-form/login-form.directive.spec.js index ac41d53a14..3ccb061934 100644 --- a/src/app/view/login-page/login-form/login-form.directive.spec.js +++ b/src/app/view/login-page/login-form/login-form.directive.spec.js @@ -38,10 +38,20 @@ expect($controller).toBeDefined(); }); + it('should have properties `eventService` defined', function () { + expect($controller.eventService).toBeDefined(); + }); + it('should not show password in plain text by default', function () { expect($controller.showPassword).toBe(false); }); + it('`clearPassword` should called when events.LOGIN_FAILED triggered', function () { + spyOn($controller, 'clearPassword'); + $controller.eventService.$emit($controller.eventService.events.LOGIN_FAILED); + expect($controller.clearPassword).toHaveBeenCalled(); + }); + it('should allow toggling of password in plain text', function () { $controller.showHidePassword(); expect($controller.showPassword).toBe(true);