From e79e74a6c8875ee8b35268272d307b2378e10dc6 Mon Sep 17 00:00:00 2001 From: Rob Gardiner Date: Wed, 15 May 2024 13:26:24 +0100 Subject: [PATCH 1/3] fixed keyboard navigation test on orderlist --- .../components/orderlist/orderlist.spec.ts | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/app/components/orderlist/orderlist.spec.ts b/src/app/components/orderlist/orderlist.spec.ts index 1be6025b1a4..26c2b0ef614 100755 --- a/src/app/components/orderlist/orderlist.spec.ts +++ b/src/app/components/orderlist/orderlist.spec.ts @@ -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(); }); }); From f4f081cd6f1547434a27e12a3522c25f47e6bc62 Mon Sep 17 00:00:00 2001 From: Rob Gardiner Date: Wed, 15 May 2024 13:26:50 +0100 Subject: [PATCH 2/3] Revert "fixed keyboard navigation test on orderlist" This reverts commit e79e74a6c8875ee8b35268272d307b2378e10dc6. --- .../components/orderlist/orderlist.spec.ts | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/app/components/orderlist/orderlist.spec.ts b/src/app/components/orderlist/orderlist.spec.ts index 26c2b0ef614..1be6025b1a4 100755 --- a/src/app/components/orderlist/orderlist.spec.ts +++ b/src/app/components/orderlist/orderlist.spec.ts @@ -493,24 +493,30 @@ describe('OrderList', () => { }); it('should select item with keyboard navigation', () => { - const onArrowDownKeySpy = spyOn(orderlist, 'onArrowDownKey').and.callThrough(); - const onArrowUpKeySpy = spyOn(orderlist, 'onArrowUpKey').and.callThrough(); + const findNextItemSpy = spyOn(orderlist, 'findNextItem').and.callThrough(); + const findPrevItemSpy = spyOn(orderlist, 'findPrevItem').and.callThrough(); fixture.detectChanges(); - const itemListEl = fixture.debugElement.query(By.css('.p-orderlist-list')).nativeElement; - - itemListEl.dispatchEvent(new KeyboardEvent('keydown', { code: 'ArrowDown' })); - fixture.detectChanges(); - itemListEl.dispatchEvent(new KeyboardEvent('keydown', { code: 'ArrowDown' })); + 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(); - itemListEl.dispatchEvent(new KeyboardEvent('keydown', { code: 'ArrowUp' })); + + event.which = 38; + bmwEl.dispatchEvent(event); fixture.detectChanges(); - itemListEl.dispatchEvent(new KeyboardEvent('keydown', { code: 'Enter' })); + + event.which = 13; + bmwEl.dispatchEvent(event); fixture.detectChanges(); expect(orderlist.selection.length).toEqual(1); - expect(orderlist.selection[0].brand).toEqual('VW'); - expect(onArrowDownKeySpy).toHaveBeenCalled(); - expect(onArrowUpKeySpy).toHaveBeenCalled(); + expect(orderlist.selection[0].brand).toEqual('BMW'); + expect(findNextItemSpy).toHaveBeenCalled(); + expect(findPrevItemSpy).toHaveBeenCalled(); + expect(bmwEl.className).toContain('p-highlight'); }); }); From 60be94bae428b20c9632d4cf8fdc4cc69fc9cd8d Mon Sep 17 00:00:00 2001 From: Rob Gardiner Date: Wed, 15 May 2024 13:28:37 +0100 Subject: [PATCH 3/3] fixed orderlist keyboard test --- .../components/orderlist/orderlist.spec.ts | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/app/components/orderlist/orderlist.spec.ts b/src/app/components/orderlist/orderlist.spec.ts index 1be6025b1a4..26c2b0ef614 100755 --- a/src/app/components/orderlist/orderlist.spec.ts +++ b/src/app/components/orderlist/orderlist.spec.ts @@ -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(); }); });