@@ -3,10 +3,12 @@ import {async, ComponentFixture, TestBed} from '@angular/core/testing';
3
3
import { Colors , PasswordStrengthComponent } from './password-strength.component' ;
4
4
import { MatProgressBarModule } from '@angular/material' ;
5
5
import { SimpleChange } from '@angular/core' ;
6
+ import { NgxCombinationGeneratorService } from 'ngx-combination-generator' ;
6
7
7
8
describe ( 'PasswordStrengthComponent' , ( ) => {
8
9
let component : PasswordStrengthComponent ;
9
10
let fixture : ComponentFixture < PasswordStrengthComponent > ;
11
+ const generator = new NgxCombinationGeneratorService ( ) ;
10
12
11
13
beforeEach ( async ( ( ) => {
12
14
TestBed . configureTestingModule ( {
@@ -69,16 +71,42 @@ describe('PasswordStrengthComponent', () => {
69
71
} ) ;
70
72
} ) ;
71
73
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' ;
79
77
component . calculatePasswordStrength ( ) ;
80
78
expect ( component . strength ) . toBe ( 40 ) ;
81
79
expect ( component . color ) . toBe ( Colors . accent ) ;
82
80
} ) ;
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
+ } ) ;
84
112
} ) ;
0 commit comments