Skip to content

Commit

Permalink
Fixed broken unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrown-ScottLogic committed May 16, 2024
1 parent 448fdd6 commit 14eb05b
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/app/components/chips/chips.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Chips>;

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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();
Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand Down Expand Up @@ -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();

Expand All @@ -242,15 +242,15 @@ describe('Chips', () => {
chips.onKeyDown(event as KeyboardEvent);
fixture.detectChanges();

event.which = 81;
event.code = "Backspace";
chips.onKeyDown(event as KeyboardEvent);
fixture.detectChanges();

expect(chips.value.length).toEqual(2);
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();
Expand All @@ -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'));
Expand All @@ -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;
Expand All @@ -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();

Expand Down Expand Up @@ -314,6 +320,7 @@ describe('Chips', () => {

chips.disabled = true;
fixture.detectChanges();
let event: Event = new Event("Keyboard");

chips.removeItem(event, 0);
fixture.detectChanges();
Expand Down

0 comments on commit 14eb05b

Please sign in to comment.