@@ -3,10 +3,12 @@ import {async, ComponentFixture, TestBed} from '@angular/core/testing';
33import { Colors , PasswordStrengthComponent } from './password-strength.component' ;
44import { MatProgressBarModule } from '@angular/material' ;
55import { SimpleChange } from '@angular/core' ;
6+ import { NgxCombinationGeneratorService } from 'ngx-combination-generator' ;
67
78describe ( 'PasswordStrengthComponent' , ( ) => {
89 let component : PasswordStrengthComponent ;
910 let fixture : ComponentFixture < PasswordStrengthComponent > ;
11+ const generator = new NgxCombinationGeneratorService ( ) ;
1012
1113 beforeEach ( async ( ( ) => {
1214 TestBed . configureTestingModule ( {
@@ -69,16 +71,42 @@ describe('PasswordStrengthComponent', () => {
6971 } ) ;
7072 } ) ;
7173
72- it ( 'should strength = 40 and color = warn when the password fulfills 2 criteria ' , ( ) => {
73- const combinations = [ 'Aa' , 'aA' , '1a' , 'A!' ] ;
74- // const combinations = generator(chars, 2, 3);
75- console . log ( 'combinations = ' , combinations ) ;
76- combinations . forEach ( combination => {
77- component . password = combination ;
78- console . log ( 'combination = ' , combination ) ;
74+ it ( 'should strength = 40 and color = accent when the password ave at least 8 chars with lower case letters' ,
75+ ( ) => {
76+ component . password = 'abcdefgw' ;
7977 component . calculatePasswordStrength ( ) ;
8078 expect ( component . strength ) . toBe ( 40 ) ;
8179 expect ( component . color ) . toBe ( Colors . accent ) ;
8280 } ) ;
83- } ) ;
81+
82+ it ( 'should strength = 40 and color = accent when the password fulfills 2 criteria ' ,
83+ ( ) => {
84+ const charsList = [ 'a' , 'A' , '1' , '!' ] ;
85+ const combinations = generator . loadCombinationList ( charsList , 2 , 2 , true ) ;
86+ console . log ( 'combinations = ' , combinations ) ;
87+ combinations . forEach ( combination => {
88+ component . password = combination ;
89+ console . log ( 'combination = ' , combination ) ;
90+ component . calculatePasswordStrength ( ) ;
91+ expect ( component . strength ) . toBe ( 40 ) ;
92+ expect ( component . color ) . toBe ( Colors . accent ) ;
93+ } ) ;
94+ } ) ;
95+
96+ it ( 'should strength = 60 and color = accent when the password fulfills 3 criteria ' ,
97+ ( ) => {
98+ const charsList = [ 'a' , 'A' , '1' , '!' , '1234567' ] ;
99+ const combinations = generator . loadCombinationList ( charsList , 3 , 3 , true ) ;
100+ console . log ( 'combinations = ' , combinations ) ;
101+
102+ combinations . forEach ( combination => {
103+ console . log ( 'combination = ' , combination ) ;
104+ const repeats = / ( .) \1/ ;
105+ console . log ( 'repeats = ' , repeats . test ( combination ) ) ;
106+ component . password = combination ;
107+ component . calculatePasswordStrength ( ) ;
108+ // expect(component.strength).toBe(60);
109+ // expect(component.color).toBe(Colors.accent);
110+ } ) ;
111+ } ) ;
84112} ) ;
0 commit comments