diff --git a/assets/eslint.config.js b/assets/eslint.config.js index aaae607d..51715805 100644 --- a/assets/eslint.config.js +++ b/assets/eslint.config.js @@ -294,7 +294,7 @@ export default tsEslint.config( 'error', { // Custom `expectStuff()` functions must also count as assertions. - assertFunctionNames: ['expect*', '*.expect*'], + assertFunctionNames: ['expect*', '*.expect*', 'assert*'], }, ], }, diff --git a/assets/js/utils/__tests__/suggestion-view.spec.ts b/assets/js/utils/__tests__/suggestion-view.spec.ts index e6da562d..8facca1c 100644 --- a/assets/js/utils/__tests__/suggestion-view.spec.ts +++ b/assets/js/utils/__tests__/suggestion-view.spec.ts @@ -61,7 +61,16 @@ describe('Suggestions', () => { [popup, input] = mockBaseSuggestionsPopup(); expect(document.querySelector('.autocomplete')).toBeInstanceOf(HTMLElement); - expect(popup.isHidden).toBe(false); + assert(popup.isHidden); + }); + + it('should hide the popup when there are no suggestions to show', () => { + [popup, input] = mockBaseSuggestionsPopup(); + + popup.setSuggestions({ history: [], tags: [] }); + popup.showForElement(input); + + assert(popup.isHidden); }); it('should render suggestions', () => { diff --git a/assets/js/utils/suggestions-view.ts b/assets/js/utils/suggestions-view.ts index 361af00e..2454c706 100644 --- a/assets/js/utils/suggestions-view.ts +++ b/assets/js/utils/suggestions-view.ts @@ -321,6 +321,13 @@ export class SuggestionsPopupComponent { } showForElement(targetElement: HTMLElement) { + if (this.items.length === 0) { + // Hide the popup because there are no suggestions to show. We have to do it + // explicitly, because a border is still rendered even for an empty popup. + this.hide(); + return; + } + this.container.style.position = 'absolute'; this.container.style.left = `${targetElement.offsetLeft}px`;