From b61cd17d3167653b0f0a84b9717769bcafffa1f6 Mon Sep 17 00:00:00 2001 From: Sinan997 Date: Sun, 30 Jul 2023 23:48:51 +0300 Subject: [PATCH] capsLock doc and test --- .../src/lib/tests/capsLock.directive.spec.ts | 58 +++++++++++++++++++ .../lib/tests/show-password-directive.spec.ts | 2 +- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 npm/ng-packs/packages/core/src/lib/tests/capsLock.directive.spec.ts diff --git a/npm/ng-packs/packages/core/src/lib/tests/capsLock.directive.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/capsLock.directive.spec.ts new file mode 100644 index 0000000000..17d50ba697 --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/tests/capsLock.directive.spec.ts @@ -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: ` + + `, + imports:[TrackCapsLockDirective] +}) +class TestComponent { + capsLock:boolean = false +} + +describe('TrackCapsLockDirective',()=>{ + let fixture: ComponentFixture;; + 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) + }); + }); \ No newline at end of file diff --git a/npm/ng-packs/packages/core/src/lib/tests/show-password-directive.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/show-password-directive.spec.ts index 6b07997bc9..e1e9750995 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/show-password-directive.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/show-password-directive.spec.ts @@ -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); });