From 1fe752dca3aba65e6906d91fa68af905eb81a747 Mon Sep 17 00:00:00 2001 From: KoloMl Date: Sat, 31 Aug 2024 23:57:24 +0400 Subject: [PATCH] Tests: Looping selection between from end to start and from start to end --- assets/js/utils/__tests__/suggestions.spec.ts | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/assets/js/utils/__tests__/suggestions.spec.ts b/assets/js/utils/__tests__/suggestions.spec.ts index c9a248d0..59102d2b 100644 --- a/assets/js/utils/__tests__/suggestions.spec.ts +++ b/assets/js/utils/__tests__/suggestions.spec.ts @@ -157,6 +157,36 @@ describe('Suggestions', () => { 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', () => { [popup, input] = mockBaseSuggestionsPopup(true);