/
app.spec.ts
75 lines (64 loc) · 2.94 KB
/
app.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By, BrowserModule } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { FormsModule } from "@angular/forms";
import { AppComponent } from './app';
import { PasswordStrengthBarModule } from '../index'
describe('App', function () {
let de: DebugElement;
let comp: AppComponent;
let fixture: ComponentFixture<AppComponent>;
let bar0: DebugElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ BrowserModule, FormsModule, PasswordStrengthBarModule ],
declarations: [ AppComponent ]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AppComponent);
comp = fixture.componentInstance;
de = fixture.debugElement.query(By.css('div'));
bar0 = fixture.debugElement.query(By.css('#bar0'));
});
it('Should create App', () => expect(comp).toBeDefined() );
it('App should have expected text', () => {
fixture.detectChanges();
expect(de.nativeElement.innerText).toMatch(/Password strength:/);
});
it('should correctly set custom bar colors', () => {
comp.account.password = 'testinput';
fixture.detectChanges();
expect(bar0.nativeElement.style.backgroundColor).toBe('rgb(221, 44, 0)'); // #DD2C00
expect(de.nativeElement.innerText).toMatch(/\(Useless\)/);
});
it('should correctly use default bar colors', () => {
comp.account.password = 'testinputN';
comp.myColors = null;
fixture.detectChanges();
expect(bar0.nativeElement.style.backgroundColor).toBe('rgb(255, 153, 0)'); // #F90 == #FF9900
expect(de.nativeElement.innerText).toMatch(/\(Weak\)/);
comp.account.password = 'testinput';
comp.myColors = ['#DD2C00', '#FF6D00', '#FFD600', '#AEEA00']; // only 4 items
fixture.detectChanges();
expect(bar0.nativeElement.style.backgroundColor).toBe('rgb(255, 0, 0)'); // #F00 == #FF0000
expect(de.nativeElement.innerText).toMatch(/\(Useless\)/);
});
it('should correctly show custom base color', () => {
fixture.detectChanges();
expect(bar0.nativeElement.style.backgroundColor).toBe('rgb(255, 255, 255)'); // #FFF
expect(de.nativeElement.innerText).toMatch(/\(Useless\)/);
});
it('should correctly show default base color and strength label (none)', () => {
comp.baseColor = null;
comp.strengthLabels = null;
fixture.detectChanges();
expect(bar0.nativeElement.style.backgroundColor).toBe('rgb(221, 221, 221)'); // #DDD
expect(de.nativeElement.innerText).not.toMatch(/\(Useless\)/);
});
it('should correctly show default base color on a bad base color', () => {
comp.baseColor = 'EEE'; // invalid color
fixture.detectChanges();
expect(bar0.nativeElement.style.backgroundColor).toBe('rgb(221, 221, 221)'); // #DDD
});
});