Skip to content

Commit

Permalink
Merge pull request #15565 from dobanisola-scottlogic/fix-listbox-unit…
Browse files Browse the repository at this point in the history
…-test

fix unit test
  • Loading branch information
cetincakiroglu authored May 15, 2024
2 parents ac55ac3 + 2de3c39 commit 9197738
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/app/components/inputmask/inputmask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const INPUTMASK_VALUE_ACCESSOR: any = {
(keydown)="onInputKeydown($event)"
(keypress)="onKeyPress($event)"
pAutoFocus
[variant]="variant"
[attr.variant]="variant"
[autofocus]="autofocus"
(input)="onInputChange($event)"
(paste)="handleInputChange($event)"
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/inputnumber/inputnumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const INPUTNUMBER_VALUE_ACCESSOR: any = {
[ngStyle]="inputStyle"
[class]="inputStyleClass"
[value]="formattedValue()"
[variant]="variant"
[attr.variant]="variant"
[attr.aria-valuemin]="min"
[attr.aria-valuemax]="max"
[attr.aria-valuenow]="value"
Expand Down
33 changes: 14 additions & 19 deletions src/app/components/listbox/listbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Listbox', () => {
{ label: 'VW', value: 'VW' },
{ label: 'Volvo', value: 'Volvo' }
];
const onOptionSelectSpy = spyOn(listbox, 'onOptionSelect').and.callThrough();
const onClickSpy = spyOn(listbox.onClick, 'emit').and.callThrough();
fixture.detectChanges();

const bmwEl = fixture.debugElement.query(By.css('ul')).children[1].nativeElement;
Expand All @@ -52,7 +52,7 @@ describe('Listbox', () => {

const filterInputEl = fixture.debugElement.query(By.css('.p-listbox-filter-container')).query(By.css('input')).nativeElement;
expect(filterInputEl.disabled).toEqual(true);
expect(onOptionSelectSpy).not.toHaveBeenCalled();
expect(onClickSpy).not.toHaveBeenCalled();
});

it('should call onOptionTouchEnd', () => {
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('Listbox', () => {
fixture.detectChanges();

expect(onOptionTouchEndSpy).toHaveBeenCalled();
expect(listbox.optionTouched).toEqual(undefined);
expect(listbox.optionTouched).toBeTrue();
});

it('should change style and styleClass', () => {
Expand Down Expand Up @@ -259,7 +259,6 @@ describe('Listbox', () => {
fixture.detectChanges();

expect(listbox.value.length).toEqual(10);
expect(listbox.selectAll).toEqual(true);
expect(selectAllEl.className).toContain('p-highlight');
expect(onToggleAllSpy).toHaveBeenCalled();
});
Expand All @@ -278,6 +277,7 @@ describe('Listbox', () => {
{ label: 'Volvo', value: 'Volvo' }
];
listbox.filter = true;
listbox.optionLabel = 'label';
fixture.detectChanges();

const filterInputEl = fixture.debugElement.query(By.css('.p-listbox-filter-container')).children[0].nativeElement;
Expand Down Expand Up @@ -503,7 +503,6 @@ describe('Listbox', () => {
fixture.detectChanges();

expect(listbox.value.length).toEqual(0);
expect(listbox.selectAll).toEqual(false);
expect(selectAllEl.className).not.toContain('p-highlight');
expect(toggleAllSpy).toHaveBeenCalledTimes(2);
});
Expand Down Expand Up @@ -577,6 +576,7 @@ describe('Listbox', () => {
listbox.checkbox = true;
listbox.filter = true;
listbox.filterValue = 'o';
listbox.optionLabel = 'label';
fixture.detectChanges();

const headerCheckBoxReadonlyEl = fixture.debugElement.query(By.css('.p-checkbox.p-component')).query(By.css('input'));
Expand Down Expand Up @@ -609,27 +609,22 @@ describe('Listbox', () => {
{ label: 'VW', value: 'VW' },
{ label: 'Volvo', value: 'Volvo' }
];
const findNextOptionIndexSpy = spyOn(listbox, 'findNextOptionIndex').and.callThrough();
const findPrevOptionIndexSpy = spyOn(listbox, 'findPrevOptionIndex').and.callThrough();
const onArrowDownKeySpy = spyOn(listbox, 'onArrowDownKey').and.callThrough();
const onArrowUpKeySpy = spyOn(listbox, 'onArrowUpKey').and.callThrough();
fixture.detectChanges();

const bmwEl = fixture.debugElement.query(By.css('ul')).children[1].nativeElement;
const event: any = document.createEvent('CustomEvent');
event.which = 40;
event.initEvent('keydown');
bmwEl.dispatchEvent(event);
const bmwEl = fixture.debugElement.query(By.css('.p-listbox-list')).nativeElement;
bmwEl.dispatchEvent(new KeyboardEvent('keydown', { code: 'ArrowDown' }));
fixture.detectChanges();

event.which = 38;
bmwEl.dispatchEvent(event);
bmwEl.dispatchEvent(new KeyboardEvent('keydown', { code: 'ArrowUp' }));
fixture.detectChanges();

event.which = 13;
bmwEl.dispatchEvent(event);
bmwEl.dispatchEvent(new KeyboardEvent('keydown', { code: 'Enter' }));
fixture.detectChanges();

expect(findNextOptionIndexSpy).toHaveBeenCalled();
expect(findPrevOptionIndexSpy).toHaveBeenCalled();
expect(listbox.value).toEqual('BMW');
expect(onArrowDownKeySpy).toHaveBeenCalled();
expect(onArrowUpKeySpy).toHaveBeenCalled();
expect(listbox.value).toEqual('Audi');
});
});
2 changes: 1 addition & 1 deletion src/app/components/listbox/listbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export const LISTBOX_VALUE_ACCESSOR: any = {
[attr.aria-selected]="isSelected(option)"
[attr.aria-disabled]="isOptionDisabled(option)"
[attr.aria-setsize]="ariaSetSize"
[ariaPosInset]="getAriaPosInset(getOptionIndex(i, scrollerOptions))"
[attr.ariaPosInset]="getAriaPosInset(getOptionIndex(i, scrollerOptions))"
(click)="onOptionSelect($event, option, getOptionIndex(i, scrollerOptions))"
(dblclick)="onOptionDoubleClick($event, option)"
(mousedown)="onOptionMouseDown($event, getOptionIndex(i, scrollerOptions))"
Expand Down

0 comments on commit 9197738

Please sign in to comment.