Skip to content

Commit 3a4af0d

Browse files
committed
test(combobox): keyboard interactions
1 parent 8cfd969 commit 3a4af0d

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

test/combo-box.test.ts

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assert, elementUpdated, expect, fixture, waitUntil } from "@open-wc/testing";
1+
import { assert, expect, fixture, waitUntil } from "@open-wc/testing";
22
import { sendKeys } from "@web/test-runner-commands";
33
import { html } from "lit";
44
import sinon from "sinon";
@@ -336,6 +336,26 @@ describe("single select combobox", () => {
336336
await waitUntil(() => el.shadowRoot?.querySelector("sgds-input")?.value === "Apple");
337337
expect(el.value).to.equal("option1");
338338
});
339+
340+
it("Keyboard arrowDown and enter populates the input with badge", async () => {
341+
const el = await fixture<SgdsComboBox>(
342+
html`<sgds-combo-box
343+
.menuList=${[
344+
{ label: "Apple", value: "option1" },
345+
{ label: "Apricot", value: "option2" },
346+
{ label: "Dur", value: "option3" }
347+
]}
348+
></sgds-combo-box>`
349+
);
350+
351+
const input = el.shadowRoot?.querySelector("sgds-input") as SgdsInput;
352+
input.focus();
353+
await sendKeys({ press: "ArrowDown" });
354+
await sendKeys({ press: "Enter" });
355+
await el.updateComplete;
356+
expect(el.value).to.equal("option1");
357+
expect(el.shadowRoot?.querySelector("sgds-input")?.value).to.equal("Apple");
358+
});
339359
});
340360

341361
describe("multi select combobox", () => {
@@ -463,21 +483,44 @@ describe("multi select combobox", () => {
463483
const durItem = el.shadowRoot?.querySelector("sgds-combo-box-item[value='option3']") as SgdsComboBoxItem;
464484
expect(durItem.active).to.be.false;
465485
});
486+
it("Keyboard arrowDown and enter populates the input with badge", async () => {
487+
const el = await fixture<SgdsComboBox>(
488+
html`<sgds-combo-box
489+
multiSelect
490+
.menuList=${[
491+
{ label: "Apple", value: "option1" },
492+
{ label: "Apricot", value: "option2" },
493+
{ label: "Dur", value: "option3" }
494+
]}
495+
></sgds-combo-box>`
496+
);
497+
498+
const input = el.shadowRoot?.querySelector("sgds-input") as SgdsInput;
499+
input.focus();
500+
await sendKeys({ press: "ArrowDown" });
501+
await sendKeys({ press: "Enter" });
502+
await el.updateComplete;
503+
expect(el.value).to.equal("option1");
504+
const badge = input.shadowRoot?.querySelector("sgds-badge") as SgdsBadge;
505+
expect(badge.innerText).to.equal("Apple");
506+
});
466507
});
467508

468509
// UT scenarios
469510
// Single Select
470511
// 1. when initial value is specified, input is populated, item is active (DONE)
471512
// 2. When invalid displayValue is written, it should clear the input after losing focus (DONE)
472-
// 3. When input value matches an item, item menu is shown and focused . On enter populates the input
513+
// 3. When input value matches an item, item menu is shown and focused . On enter populates the input (??? clarify with andy)
473514
// 4. When input is cleared, the active item is no longer active (DONE)
474515
// 5. When a selection is made and input is blurred. The value of input or displayValue will sync with the menu selected item regardless of the value (DONE)
475516
// 6. If a purposeful selection is not made through enter or click, input is blurred. the displayValue clears regardless if value match anot (DONE)
517+
// 7. Keyboard ArrowDown and Enter populates the input with value (DONE)
476518

477519
// UT scenarios
478520
// Multi Select
479521
// 1. when initial value is specified, input is populated, item is checked and active, badge is in input (DONE)
480522
// 2. When invalid displayValue is written, it should clear the input after losing focus (DONE)
481-
// 3. When input value matches an item, item menu is shown and focused . On enter populates the input
523+
// 3. When input value matches an item, item menu is shown and focused . On enter populates the input (??? clarify with andy)
482524
// 4. If a purposeful selection is not made through enter or click, input is blurred. the displayValue clears regardless if value match anot (DONE)
483525
// 5. When a badge is cancelled, it syncs with the removal actie item in the menu (DONE)
526+
// 6. Keyboard arrowdown and enter populates the input with badge (DONE)

0 commit comments

Comments
 (0)