69 lines
2.3 KiB
TypeScript
69 lines
2.3 KiB
TypeScript
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
|
|
import { PasswordEntryComponent } from './password-entry';
|
|
|
|
describe('PasswordEntryComponent global test', () => {
|
|
let component: PasswordEntryComponent;
|
|
let fixture: ComponentFixture<PasswordEntryComponent>;
|
|
let input: HTMLInputElement;
|
|
let button: HTMLButtonElement;
|
|
|
|
beforeEach(async () => {
|
|
await TestBed.configureTestingModule({
|
|
declarations: [PasswordEntryComponent],
|
|
}).compileComponents();
|
|
fixture = TestBed.createComponent(PasswordEntryComponent);
|
|
component = fixture.componentInstance;
|
|
input = fixture.nativeElement.querySelector('div').querySelector('input');
|
|
button = fixture.nativeElement.querySelector('div').querySelector('button');
|
|
});
|
|
|
|
it('Test mode password (default)', () => {
|
|
fixture.detectChanges();
|
|
expect(input.textContent).toEqual('');
|
|
expect(button.textContent).toEqual('visibility_off');
|
|
expect(input.type).toEqual('password');
|
|
});
|
|
|
|
it('Test mode text', () => {
|
|
component.passwordVisibility = true;
|
|
fixture.detectChanges();
|
|
expect(input.textContent).toEqual('');
|
|
expect(button.textContent).toEqual('visibility');
|
|
expect(input.type).toEqual('text');
|
|
});
|
|
|
|
it('test click on hide button', fakeAsync(() => {
|
|
fixture.detectChanges();
|
|
expect(component.passwordVisibility).toEqual(false);
|
|
button.click();
|
|
tick();
|
|
fixture.detectChanges();
|
|
expect(component.passwordVisibility).toEqual(true);
|
|
expect(button.textContent).toEqual('visibility');
|
|
expect(input.type).toEqual('text');
|
|
button.click();
|
|
tick();
|
|
fixture.detectChanges();
|
|
expect(component.passwordVisibility).toEqual(false);
|
|
expect(button.textContent).toEqual('visibility_off');
|
|
expect(input.type).toEqual('password');
|
|
}));
|
|
|
|
it('Set password', fakeAsync(() => {
|
|
fixture.detectChanges();
|
|
expect(component.passwordVisibility).toEqual(false);
|
|
let tmpData = 'My beautifull Password';
|
|
input.value = tmpData;
|
|
input.dispatchEvent(new Event('input'));
|
|
fixture.detectChanges();
|
|
expect(input.textContent).toEqual(tmpData);
|
|
expect(component.value).toEqual(tmpData);
|
|
tmpData = '';
|
|
input.value = tmpData;
|
|
input.dispatchEvent(new Event('input'));
|
|
fixture.detectChanges();
|
|
expect(input.textContent).toEqual(tmpData);
|
|
expect(component.value).toEqual(tmpData);
|
|
}));
|
|
});
|