Tests: Looping selection between from end to start and from start to end

This commit is contained in:
KoloMl 2024-08-31 23:57:24 +04:00
parent 098ec6c6db
commit 1fe752dca3

View file

@ -157,6 +157,36 @@ describe('Suggestions', () => {
expect(thirdItem).toHaveClass(selectedItemClassName); expect(thirdItem).toHaveClass(selectedItemClassName);
}); });
it('should loop around when selecting next on last and previous on first', () => {
[popup, input] = mockBaseSuggestionsPopup(true);
const firstItem = document.querySelector('.autocomplete__item:first-child');
const lastItem = document.querySelector('.autocomplete__item:last-child');
if (lastItem) {
fireEvent.mouseOver(lastItem);
fireEvent.mouseMove(lastItem);
}
expect(lastItem).toHaveClass(selectedItemClassName);
popup.selectNext();
expect(document.querySelector(`.${selectedItemClassName}`)).toBeNull();
popup.selectNext();
expect(firstItem).toHaveClass(selectedItemClassName);
popup.selectPrevious();
expect(document.querySelector(`.${selectedItemClassName}`)).toBeNull();
popup.selectPrevious();
expect(lastItem).toHaveClass(selectedItemClassName);
});
it('should return selected item value', () => { it('should return selected item value', () => {
[popup, input] = mockBaseSuggestionsPopup(true); [popup, input] = mockBaseSuggestionsPopup(true);