capsLock doc and test

pull/17267/head
Sinan997 1 year ago
parent 5c066c5b3f
commit b61cd17d31

@ -0,0 +1,58 @@
import { Component, DebugElement } from '@angular/core'
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { TrackCapsLockDirective } from '../directives';
import { By } from '@angular/platform-browser';
@Component({
standalone:true,
template: `
<input (abpCapsLock)="capsLock = $event" />
`,
imports:[TrackCapsLockDirective]
})
class TestComponent {
capsLock:boolean = false
}
describe('TrackCapsLockDirective',()=>{
let fixture: ComponentFixture<TestComponent>;;
let des : DebugElement[];
beforeEach(()=>{
fixture = TestBed.configureTestingModule({
imports: [ TestComponent ]
}).createComponent(TestComponent);
fixture.detectChanges();
des = fixture.debugElement.queryAll(By.directive(TrackCapsLockDirective));
});
// tests
test.each(['keydown','keyup'])('is %p works when press capslock and is emit status', (eventName) => {
const event = new KeyboardEvent(eventName, {
key: 'CapsLock',
modifierCapsLock: true
});
window.dispatchEvent(event);
fixture.detectChanges();
expect(fixture.componentInstance.capsLock).toBe(true)
});
test.each(['keydown','keyup'])('is %p detect the change capslock is emit status', (eventName) => {
const trueEvent = new KeyboardEvent(eventName, {
key: 'CapsLock',
modifierCapsLock: true
});
window.dispatchEvent(trueEvent);
fixture.detectChanges();
expect(fixture.componentInstance.capsLock).toBe(true)
const falseEvent = new KeyboardEvent(eventName, {
key: 'CapsLock',
modifierCapsLock: false
});
window.dispatchEvent(falseEvent);
fixture.detectChanges();
expect(fixture.componentInstance.capsLock).toBe(false)
});
});

@ -39,7 +39,7 @@ describe('ShowPasswordDirective',()=>{
bareInput = fixture.debugElement.query(By.css('input:not([abpShowPassword])'));
})
// color tests
// tests
it('should have three input has ShowPasswordDirective elements', () => {
expect(des.length).toBe(3);
});

Loading…
Cancel
Save