This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
765 additions
and
5 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
208 changes: 208 additions & 0 deletions
208
modules/users/tests/client/password-validator.client.directive.tests.js
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 |
---|---|---|
@@ -0,0 +1,208 @@ | ||
'use strict'; | ||
|
||
(function() { | ||
// Password Validator Directive Spec | ||
describe('PasswordValidatorDirective', function() { | ||
// Initialize global variables | ||
var scope, | ||
element, | ||
$compile, | ||
form; | ||
|
||
// Load the main application module | ||
beforeEach(module(ApplicationConfiguration.applicationModuleName)); | ||
|
||
beforeEach(inject(function(_$rootScope_, _$compile_) { | ||
// Set a new global scope | ||
scope = _$rootScope_.$new(); | ||
$compile = _$compile_; | ||
|
||
scope.passwordMock = { | ||
password: 'P@ssw0rd!!' | ||
}; | ||
})); | ||
|
||
function compileDirective(template) { | ||
// function to compile a fresh directive with the given template, or a default one | ||
// input form with directive | ||
if (!template) template = '<input type="password" id="password" name="password" ng-model="passwordMock.password" password-validator required>'; | ||
template = '<form name="form"><div>' + template + '<input type="submit">submit form</input></div></form>'; | ||
|
||
// inject allows you to use AngularJS dependency injection | ||
// to retrieve and use other services | ||
inject(function($compile) { | ||
var form = $compile(template)(scope); | ||
element = form.find('div'); | ||
|
||
// $digest is necessary to finalize the directive generation | ||
scope.$digest(); | ||
}); | ||
} | ||
|
||
describe('Initialize', function() { | ||
beforeEach(function () { | ||
compileDirective(); | ||
}); | ||
|
||
it('should produce the password input', function () { | ||
expect(element.find('input').length).toEqual(2); | ||
}); | ||
|
||
it('should check form validity upon initializing', function () { | ||
expect(scope.form.$valid).toBeTruthy(); | ||
}); | ||
|
||
}); | ||
|
||
it('should set form to invalid with empty password', function () { | ||
scope.passwordMock.password = ''; | ||
compileDirective(); | ||
scope.$digest(); | ||
|
||
expect(scope.form.password.$valid).toBeFalsy(); | ||
expect(scope.form.password.$error.required).toBeTruthy(); | ||
expect(scope.requirementsColor).toEqual(undefined); | ||
expect(scope.requirementsProgress).toEqual(undefined); | ||
}); | ||
|
||
it('should be valid when password meets requirements - "P@ssw0rd!!""', function() { | ||
scope.passwordMock.password = 'P@ssw0rd!!'; | ||
compileDirective(); | ||
scope.$digest(); | ||
|
||
expect(scope.form.password.$valid).toBeTruthy(); | ||
expect(scope.form.password.$error).toEqual({}); | ||
expect(scope.requirementsColor).toEqual('success'); | ||
expect(scope.requirementsProgress).toEqual('100'); | ||
}); | ||
|
||
it('should be valid when password meets requirements with a passphrase', function() { | ||
scope.passwordMock.password = 'Open-Source Full-Stack Solution for MEAN'; | ||
compileDirective(); | ||
scope.$digest(); | ||
|
||
expect(scope.form.password.$valid).toBeTruthy(); | ||
expect(scope.form.password.$error).toEqual({}); | ||
expect(scope.requirementsColor).toEqual('success'); | ||
expect(scope.requirementsProgress).toEqual('100'); | ||
}); | ||
|
||
it('should not allow a less than 10 characters long - "P@$$w0rd!"', function() { | ||
scope.passwordMock.password = 'P@$$w0rd!'; | ||
compileDirective(); | ||
scope.$digest(); | ||
|
||
expect(scope.form.password.$valid).toBeFalsy(); | ||
expect(scope.form.password.$error.required).toBeFalsy(); | ||
expect(scope.passwordErrors).toEqual(['The password must be at least 10 characters long.']); | ||
expect(scope.requirementsColor).toEqual('primary'); | ||
expect(scope.requirementsProgress).toEqual('80'); | ||
}); | ||
|
||
it('should not allow a greater than 128 characters long', function() { | ||
scope.passwordMock.password = ')!/uLT="lh&:`6X!]|15o!$!TJf,.13l?vG].-j],lFPe/QhwN#{Z<[*1nX@n1^?WW-%_.*D)m$toB+N7z}kcN#B_d(f41h%w@0F!]igtSQ1gl~6sEV&r~}~1ub>If1c+'; | ||
compileDirective(); | ||
scope.$digest(); | ||
|
||
expect(scope.form.password.$valid).toBeFalsy(); | ||
expect(scope.form.password.$error.required).toBeFalsy(); | ||
expect(scope.passwordErrors).toEqual(['The password must be fewer than 128 characters.']); | ||
expect(scope.requirementsColor).toEqual('primary'); | ||
expect(scope.requirementsProgress).toEqual('80'); | ||
}); | ||
|
||
it('should not allow more than 3 or more repeating characters - "P@$$w0rd!!!"', function() { | ||
scope.passwordMock.password = 'P@$$w0rd!!!'; | ||
compileDirective(); | ||
scope.$digest(); | ||
|
||
expect(scope.form.password.$valid).toBeFalsy(); | ||
expect(scope.form.password.$error.required).toBeFalsy(); | ||
expect(scope.passwordErrors).toEqual(['The password may not contain sequences of three or more repeated characters.']); | ||
expect(scope.requirementsColor).toEqual('primary'); | ||
expect(scope.requirementsProgress).toEqual('80'); | ||
}); | ||
|
||
it('should not allow a password with no uppercase letters - "p@$$w0rd!!"', function() { | ||
scope.passwordMock.password = 'p@$$w0rd!!'; | ||
compileDirective(); | ||
scope.$digest(); | ||
|
||
expect(scope.form.password.$valid).toBeFalsy(); | ||
expect(scope.form.password.$error.required).toBeFalsy(); | ||
expect(scope.passwordErrors).toEqual(['The password must contain at least one uppercase letter.']); | ||
expect(scope.requirementsColor).toEqual('primary'); | ||
expect(scope.requirementsProgress).toEqual('80'); | ||
}); | ||
|
||
it('should not allow a password with less than one number - "P@$$word!!"', function() { | ||
scope.passwordMock.password = 'P@$$word!!'; | ||
compileDirective(); | ||
scope.$digest(); | ||
|
||
expect(scope.form.password.$valid).toBeFalsy(); | ||
expect(scope.form.password.$error.required).toBeFalsy(); | ||
expect(scope.passwordErrors).toEqual(['The password must contain at least one number.']); | ||
expect(scope.requirementsColor).toEqual('primary'); | ||
expect(scope.requirementsProgress).toEqual('80'); | ||
}); | ||
|
||
it('should not allow a password with less than one special character - "Passw0rdss"', function() { | ||
scope.passwordMock.password = 'Passw0rdss'; | ||
compileDirective(); | ||
scope.$digest(); | ||
|
||
expect(scope.form.password.$valid).toBeFalsy(); | ||
expect(scope.form.password.$error.required).toBeFalsy(); | ||
expect(scope.passwordErrors).toEqual(['The password must contain at least one special character.']); | ||
expect(scope.requirementsColor).toEqual('primary'); | ||
expect(scope.requirementsProgress).toEqual('80'); | ||
}); | ||
|
||
it('should show 20% progress and "danger" color', function() { | ||
scope.passwordMock.password = 'P'; | ||
compileDirective(); | ||
scope.$digest(); | ||
|
||
expect(scope.requirementsColor).toEqual('danger'); | ||
expect(scope.requirementsProgress).toEqual('20'); | ||
}); | ||
|
||
it('should show 40% progress and "warning" color', function() { | ||
scope.passwordMock.password = 'Pa'; | ||
compileDirective(); | ||
scope.$digest(); | ||
|
||
expect(scope.requirementsColor).toEqual('warning'); | ||
expect(scope.requirementsProgress).toEqual('40'); | ||
}); | ||
|
||
it('should show 60% progress and "info" color', function() { | ||
scope.passwordMock.password = 'Pa$'; | ||
compileDirective(); | ||
scope.$digest(); | ||
|
||
expect(scope.requirementsColor).toEqual('info'); | ||
expect(scope.requirementsProgress).toEqual('60'); | ||
}); | ||
|
||
it('should show 80% progress and "primary" color', function() { | ||
scope.passwordMock.password = 'Pa$$w0rd'; | ||
compileDirective(); | ||
scope.$digest(); | ||
|
||
expect(scope.requirementsColor).toEqual('primary'); | ||
expect(scope.requirementsProgress).toEqual('80'); | ||
}); | ||
|
||
it('should show 100% progress and "success" color', function() { | ||
scope.passwordMock.password = 'Pa$$w0rd!!'; | ||
compileDirective(); | ||
scope.$digest(); | ||
|
||
expect(scope.requirementsColor).toEqual('success'); | ||
expect(scope.requirementsProgress).toEqual('100'); | ||
}); | ||
|
||
}); | ||
}()); |
86 changes: 86 additions & 0 deletions
86
modules/users/tests/client/password-verify.client.directive.tests.js
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
'use strict'; | ||
|
||
(function() { | ||
// Password Verify Directive Spec | ||
describe('PasswordVerifyDirective', function() { | ||
// Initialize global variables | ||
var scope, | ||
element, | ||
$compile, | ||
form; | ||
|
||
// Load the main application module | ||
beforeEach(module(ApplicationConfiguration.applicationModuleName)); | ||
|
||
beforeEach(inject(function(_$rootScope_, _$compile_) { | ||
// Set a new global scope | ||
scope = _$rootScope_.$new(); | ||
$compile = _$compile_; | ||
|
||
scope.passwordMock = { | ||
newPassword: 'P@ssw0rd!!', | ||
verifyPassword: 'P@ssw0rd!!' | ||
}; | ||
})); | ||
|
||
function compileDirective(template) { | ||
// function to compile a fresh directive with the given template, or a default one | ||
// input form with directive | ||
if (!template) template = '<input type="password" id="newPassword" name="newPassword" class="form-control" ng-model="passwordMock.newPassword" placeholder="New Password" autocomplete="new-password" popover="{{popoverMsg}}" popover-trigger="focus" popover-placement="top" password-validator required>' + | ||
'<input type="password" id="verifyPassword" name="verifyPassword" class="form-control" ng-model="passwordMock.verifyPassword" placeholder="Verify Password" password-verify="passwordMock.newPassword" required>'; | ||
template = '<form name="form"><div>' + template + '<input type="submit">submit form</input></div></form>'; | ||
|
||
// inject allows you to use AngularJS dependency injection | ||
// to retrieve and use other services | ||
inject(function($compile) { | ||
var form = $compile(template)(scope); | ||
element = form.find('div'); | ||
|
||
// $digest is necessary to finalize the directive generation | ||
scope.$digest(); | ||
}); | ||
} | ||
|
||
describe('Initialize', function() { | ||
beforeEach(function () { | ||
compileDirective(); | ||
}); | ||
|
||
it('should produce the password input', function () { | ||
expect(element.find('input').length).toEqual(3); | ||
}); | ||
|
||
it('should check form validity upon initializing', function () { | ||
expect(scope.form.$valid).toBeTruthy(); | ||
}); | ||
|
||
}); | ||
|
||
it('should not show error when passwords match', function () { | ||
compileDirective(); | ||
scope.passwordMock.newPassword = 'P@ssw0rd!!'; | ||
scope.passwordMock.verifyPassword = 'P@ssw0rd!!'; | ||
scope.$digest(); | ||
|
||
expect(scope.form.newPassword.$valid).toBeTruthy(); | ||
expect(scope.form.newPassword.$error).toEqual({}); | ||
expect(scope.form.verifyPassword.$valid).toBeTruthy(); | ||
expect(scope.form.verifyPassword.$error).toEqual({}); | ||
expect(scope.form.$valid).toBeTruthy(); | ||
}); | ||
|
||
it('should show error when passwords do not match', function () { | ||
compileDirective(); | ||
scope.passwordMock.newPassword = 'P@ssw0rd!!'; | ||
scope.passwordMock.verifyPassword = 'P@ssw0rd!'; | ||
scope.$digest(); | ||
|
||
expect(scope.form.newPassword.$valid).toBeTruthy(); | ||
expect(scope.form.newPassword.$error).toEqual({}); | ||
expect(scope.form.verifyPassword.$valid).toBeFalsy(); | ||
expect(scope.form.verifyPassword.$error.passwordVerify).toBeTruthy(); | ||
expect(scope.form.$valid).toBeFalsy(); | ||
}); | ||
|
||
}); | ||
}()); |
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
Oops, something went wrong.