Skip to content

Commit 8b5438f

Browse files
committed
test: cover "re-open on focus" behaviour
1 parent cb78994 commit 8b5438f

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
<div align="center">
44

55
[![Continuous integration](https://github.com/jquery/typesense-minibar/actions/workflows/CI.yaml/badge.svg)](https://github.com/jquery/typesense-minibar/actions/workflows/CI.yaml?query=event%3Apush+branch%3Amain)
6-
[![Test coverage](https://img.shields.io/badge/coverage-93%25-brightgreen.svg)](https://jquery.github.io/typesense-minibar/coverage/)
6+
[![Test coverage](https://img.shields.io/badge/coverage-95%25-brightgreen.svg)](https://jquery.github.io/typesense-minibar/coverage/)
77
[![Tested with QUnit](https://img.shields.io/badge/tested_with-qunit-9c3493.svg)](https://qunitjs.com/)
88

99
</div>
1010

11-
**minibar** is a fast 2kB autocomplete search bar for [Typesense](https://typesense.org/). It is an alternative to typesense-docsearch.js, Algolia DocSearch, InstantSearch, autocomplete-js, and typesense-js.
11+
**minibar** is a fast 2kB autocomplete search bar for [Typesense](https://typesense.org/). It is an alternative to Algolia DocSearch, InstantSearch, autocomplete-js, typesense-docsearch.js, and typesense-js.
1212

1313
## Features
1414

test/test.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,15 +432,37 @@ QUnit.module('typesense-minibar', hooks => {
432432
const form = parseHTML('<form><input type="search"></form>');
433433
const input = form.firstChild;
434434
document.body.append(form);
435-
assert.true(!document.activeElement || !form.contains(document.activeElement), 'initial focus');
435+
assert.false(form.contains(document.activeElement || null), 'initial focus');
436436

437437
bar = tsminibar(form);
438-
assert.true(!document.activeElement || !form.contains(document.activeElement), 'focus after contruct');
438+
assert.false(form.contains(document.activeElement || null), 'focus after contruct');
439439

440440
simulate(document, 'keydown', {}, { key: '/' });
441441
assert.strictEqual(document.activeElement, input, 'focus after slash');
442442
});
443443

444+
QUnit.test('focus [re-open results]', async assert => {
445+
const form = parseHTML('<form><input type="search"></form>');
446+
const input = form.firstChild;
447+
document.body.append(form);
448+
bar = tsminibar(form);
449+
const listbox = form.querySelector('[role=listbox]');
450+
451+
mockFetchResponse = API_RESP_FULL_MATCH_SOMETHING;
452+
input.value = 'something';
453+
await expectRender(form, () => {
454+
simulate(input, 'input');
455+
});
456+
assert.false(listbox.hidden, 'listbox not hidden');
457+
458+
mockFetchResponse = null;
459+
simulate(document.body, 'click', { bubbles: true });
460+
assert.true(listbox.hidden, 'listbox hidden');
461+
462+
input.focus();
463+
assert.false(listbox.hidden, 'listbox re-opened');
464+
});
465+
444466
QUnit.test('focus [preconnect]', async assert => {
445467
const form = parseHTML('<form><input type="search"></form>');
446468
const input = form.firstChild;

0 commit comments

Comments
 (0)