Skip to content

Commit

Permalink
Merge pull request #15577 from robGardiner01/orderlist-test-fix
Browse files Browse the repository at this point in the history
Orderlist test fix
  • Loading branch information
cetincakiroglu committed May 16, 2024
2 parents 3b6ba2c + 60be94b commit a82f2fb
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/app/components/orderlist/orderlist.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,30 +493,24 @@ describe('OrderList', () => {
});

it('should select item with keyboard navigation', () => {
const findNextItemSpy = spyOn(orderlist, 'findNextItem').and.callThrough();
const findPrevItemSpy = spyOn(orderlist, 'findPrevItem').and.callThrough();
const onArrowDownKeySpy = spyOn(orderlist, 'onArrowDownKey').and.callThrough();
const onArrowUpKeySpy = spyOn(orderlist, 'onArrowUpKey').and.callThrough();
fixture.detectChanges();

const itemListEl = fixture.debugElement.query(By.css('ul'));
const bmwEl = itemListEl.queryAll(By.css('.p-orderlist-item'))[3].nativeElement;
const event: any = document.createEvent('CustomEvent');
event.which = 40;
event.initEvent('keydown');
bmwEl.dispatchEvent(event);
fixture.detectChanges();
const itemListEl = fixture.debugElement.query(By.css('.p-orderlist-list')).nativeElement;

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

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

expect(orderlist.selection.length).toEqual(1);
expect(orderlist.selection[0].brand).toEqual('BMW');
expect(findNextItemSpy).toHaveBeenCalled();
expect(findPrevItemSpy).toHaveBeenCalled();
expect(bmwEl.className).toContain('p-highlight');
expect(orderlist.selection[0].brand).toEqual('VW');
expect(onArrowDownKeySpy).toHaveBeenCalled();
expect(onArrowUpKeySpy).toHaveBeenCalled();
});
});

0 comments on commit a82f2fb

Please sign in to comment.