Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed broken unit tests for Chips component #15595

Merged
merged 2 commits into from
May 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading