Skip to content

Commit

Permalink
Merge pull request primefaces#15595 from nbrown-ScottLogic/chipsTestFit
Browse files Browse the repository at this point in the history
Fixed broken unit tests for Chips component
  • Loading branch information
cetincakiroglu authored May 30, 2024
2 parents 8d5cb92 + 9210142 commit 5a42a3f
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/app/components/chips/chips.spec.ts
Original file line number Diff line number Diff line change
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 5a42a3f

Please sign in to comment.