Skip to content

Commit 087cef6

Browse files
authored
test(combo): fix flickering scroll test (#15041)
1 parent d21f4ec commit 087cef6

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

projects/igniteui-angular/src/lib/combo/combo.component.spec.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,71 +1745,60 @@ describe('igxCombo', () => {
17451745
expect(dropdown).toBeDefined();
17461746
expect(dropdown.focusedItem).toBeFalsy();
17471747
expect(combo.virtualScrollContainer).toBeDefined();
1748+
combo.allowCustomValues = true;
17481749
const mockClick = jasmine.createSpyObj('event', ['preventDefault', 'stopPropagation']);
17491750
const virtualMockUP = spyOn<any>(dropdown, 'navigatePrev').and.callThrough();
17501751
const virtualMockDOWN = spyOn<any>(dropdown, 'navigateNext').and.callThrough();
17511752
expect(dropdown.focusedItem).toEqual(null);
17521753
expect(combo.collapsed).toBeTruthy();
17531754
combo.toggle();
1754-
await wait(30);
1755+
await wait();
17551756
fixture.detectChanges();
17561757
expect(combo.collapsed).toBeFalsy();
17571758
combo.virtualScrollContainer.scrollTo(51);
1758-
await wait(30);
1759+
await firstValueFrom(combo.virtualScrollContainer.chunkLoad);
17591760
fixture.detectChanges();
17601761
let items = fixture.debugElement.queryAll(By.css(`.${CSS_CLASS_DROPDOWNLISTITEM}`));
17611762
let lastItem = items[items.length - 1].componentInstance;
17621763
expect(lastItem).toBeDefined();
17631764
lastItem.clicked(mockClick);
1764-
await wait(30);
17651765
fixture.detectChanges();
17661766
expect(dropdown.focusedItem).toEqual(lastItem);
17671767
dropdown.navigateItem(-1);
1768-
await wait(30);
17691768
fixture.detectChanges();
17701769
expect(virtualMockDOWN).toHaveBeenCalledTimes(0);
17711770
lastItem.clicked(mockClick);
1772-
await wait(30);
17731771
fixture.detectChanges();
17741772
expect(dropdown.focusedItem).toEqual(lastItem);
17751773
dropdown.navigateNext();
1776-
await wait(30);
17771774
fixture.detectChanges();
17781775
expect(virtualMockDOWN).toHaveBeenCalledTimes(1);
17791776
combo.searchValue = 'New';
17801777
combo.handleInputChange();
17811778
fixture.detectChanges();
1782-
await wait(30);
1783-
items = fixture.debugElement.queryAll(By.css(`.${CSS_CLASS_DROPDOWNLISTITEM}`));
1784-
lastItem = items[items.length - 1].componentInstance;
1785-
(lastItem as IgxComboAddItemComponent).clicked(mockClick);
1786-
await wait(30);
1779+
await firstValueFrom(combo.virtualScrollContainer.chunkLoad);
1780+
const addItemButton = fixture.debugElement.query(By.directive(IgxComboAddItemComponent));
1781+
addItemButton.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
17871782
fixture.detectChanges();
17881783
// After `Add Item` is clicked, the input is focused and the item is added to the list
1789-
// expect(dropdown.focusedItem).toEqual(null);
1784+
expect(dropdown.focusedItem).toEqual(null);
17901785
expect(document.activeElement).toEqual(combo.searchInput.nativeElement);
17911786
expect(combo.customValueFlag).toBeFalsy();
17921787
expect(combo.searchInput.nativeElement.value).toBeTruthy();
17931788

17941789
// TEST move from first item
1795-
combo.virtualScrollContainer.scrollTo(0);
1796-
await wait();
1797-
fixture.detectChanges();
17981790
const firstItem = fixture.debugElement.queryAll(By.css(`.${CSS_CLASS_DROPDOWNLISTITEM}`))[0].componentInstance;
17991791
firstItem.clicked(mockClick);
1800-
await wait(30);
18011792
fixture.detectChanges();
18021793
expect(dropdown.focusedItem).toEqual(firstItem);
18031794
expect(dropdown.focusedItem.itemIndex).toEqual(0);
1804-
// spyOnProperty(dropdown, 'focusedItem', 'get').and.returnValue(firstItem);
18051795
dropdown.navigateFirst();
1806-
await wait(30);
18071796
fixture.detectChanges();
18081797
dropdown.navigatePrev();
1809-
await wait(30);
18101798
fixture.detectChanges();
1811-
// Called once before the `await` and called once more, because item @ index 0 is a header
1799+
// Called once manually and called once more, because item @ index 0 is a header
18121800
expect(virtualMockUP).toHaveBeenCalledTimes(2);
1801+
expect(dropdown.focusedItem).toBeNull();
18131802
}));
18141803
it('should properly get the first focusable item when focusing the component list', () => {
18151804
const expectedItemText = 'State: MichiganRegion: East North Central';

0 commit comments

Comments
 (0)