From 14eb05bae89bf2d67c5ee8c13a967b4d7250aa7c Mon Sep 17 00:00:00 2001 From: Nathanael Brown Date: Thu, 16 May 2024 15:36:49 +0100 Subject: [PATCH 1/2] Fixed broken unit tests --- src/app/components/chips/chips.spec.ts | 33 ++++++++++++++++---------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/app/components/chips/chips.spec.ts b/src/app/components/chips/chips.spec.ts index e7b3737f9bf..80df5d8e019 100755 --- a/src/app/components/chips/chips.spec.ts +++ b/src/app/components/chips/chips.spec.ts @@ -4,7 +4,7 @@ import { Chips } from './chips'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { TimesCircleIcon } from 'primeng/icons/timescircle'; -describe('Chips', () => { +fdescribe('Chips', () => { let chips: Chips; let fixture: ComponentFixture; @@ -55,7 +55,7 @@ describe('Chips', () => { chips.disabled = true; fixture.detectChanges(); - const listEl = fixture.debugElement.query(By.css('ul')); + const listEl = fixture.debugElement.query(By.css('.p-chips')); const inputEl = fixture.debugElement.query(By.css('input')); const tokenIconEl = fixture.debugElement.query(By.css('.p-chips-token-icon')); expect(listEl.nativeElement.className).toContain('p-disabled'); @@ -102,8 +102,8 @@ describe('Chips', () => { inputEl.nativeElement.value = 'primeng'; fixture.detectChanges(); - let event = { which: 13, preventDefault() {} }; - chips.onKeyDown(event as KeyboardEvent); + let event = { code: "Enter", target: inputEl.nativeElement, preventDefault() {} }; + chips.onKeyDown(event); fixture.detectChanges(); chips.cd.detectChanges(); @@ -123,7 +123,7 @@ describe('Chips', () => { inputEl.nativeElement.value = 'primeng'; fixture.detectChanges(); - let event = { which: 13, preventDefault() {} }; + let event = { code: "Enter", target: inputEl.nativeElement, preventDefault() {} }; chips.onKeyDown(event as KeyboardEvent); fixture.detectChanges(); @@ -146,7 +146,7 @@ describe('Chips', () => { inputEl.nativeElement.value = 'primeng'; fixture.detectChanges(); - let event = { which: 13, preventDefault() {} }; + let event = { code: "Enter", target: inputEl.nativeElement, preventDefault() {} }; chips.onKeyDown(event as KeyboardEvent); fixture.detectChanges(); @@ -169,7 +169,7 @@ describe('Chips', () => { inputEl.nativeElement.value = 'primeng'; fixture.detectChanges(); - let event = { which: 13, preventDefault() {} }; + let event = { code: "Enter", target: inputEl.nativeElement, preventDefault() {} }; chips.onKeyDown(event as KeyboardEvent); fixture.detectChanges(); @@ -194,7 +194,7 @@ describe('Chips', () => { inputEl.nativeElement.value = 'primeng'; fixture.detectChanges(); - let event = { which: 9, preventDefault() {} }; + let event = { code: "Tab", target: inputEl.nativeElement, preventDefault() {} }; chips.onKeyDown(event as KeyboardEvent); fixture.detectChanges(); @@ -232,7 +232,7 @@ describe('Chips', () => { inputEl.nativeElement.value = 'primeng'; fixture.detectChanges(); - let event = { which: 13, preventDefault() {} }; + let event = { code: "Enter", target: inputEl.nativeElement, preventDefault() {} }; chips.onKeyDown(event as KeyboardEvent); fixture.detectChanges(); @@ -242,7 +242,7 @@ describe('Chips', () => { chips.onKeyDown(event as KeyboardEvent); fixture.detectChanges(); - event.which = 81; + event.code = "Backspace"; chips.onKeyDown(event as KeyboardEvent); fixture.detectChanges(); @@ -250,7 +250,7 @@ describe('Chips', () => { expect(chips.value[0]).toEqual('primeng'); expect(chips.value[1]).toEqual('primeng'); expect(inputEl.nativeElement.disabled).toEqual(true); - event.which = 8; + event.code = "Backspace"; chips.onKeyDown(event as KeyboardEvent); chips.updateMaxedOut(); fixture.detectChanges(); @@ -259,7 +259,7 @@ describe('Chips', () => { }); it('should set maxlength to input element', () => { - chips.max = 2; + chips.maxLength = 2; fixture.detectChanges(); const inputEl = fixture.debugElement.query(By.css('input')); @@ -268,6 +268,8 @@ describe('Chips', () => { it('should delete item', () => { chips.value = ['primeng']; + const inputEl = fixture.debugElement.query(By.css('input')); + fixture.detectChanges(); let data; @@ -276,7 +278,11 @@ describe('Chips', () => { expect(chips.value[0]).toEqual('primeng'); fixture.detectChanges(); - let event = { which: 8, preventDefault() {} }; + // let event = { which: 8, preventDefault() {} }; + let event = { code: "Backspace", target: inputEl.nativeElement, preventDefault() {} }; + + + chips.onKeyDown(event as KeyboardEvent); chips.onKeyDown(event as KeyboardEvent); fixture.detectChanges(); @@ -314,6 +320,7 @@ describe('Chips', () => { chips.disabled = true; fixture.detectChanges(); + let event: Event = new Event("Keyboard"); chips.removeItem(event, 0); fixture.detectChanges(); From 92101428f89fc3c24756480db473fb23fc9c9af8 Mon Sep 17 00:00:00 2001 From: Nathanael Brown Date: Thu, 16 May 2024 15:38:45 +0100 Subject: [PATCH 2/2] Fixed fdescribe --- src/app/components/chips/chips.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/components/chips/chips.spec.ts b/src/app/components/chips/chips.spec.ts index 80df5d8e019..85bd0b86834 100755 --- a/src/app/components/chips/chips.spec.ts +++ b/src/app/components/chips/chips.spec.ts @@ -4,7 +4,7 @@ import { Chips } from './chips'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { TimesCircleIcon } from 'primeng/icons/timescircle'; -fdescribe('Chips', () => { +describe('Chips', () => { let chips: Chips; let fixture: ComponentFixture;