From 50b4761791e6ca0252bd46e3a15aab1778ab4456 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Tue, 20 May 2025 08:59:14 -0700 Subject: [PATCH] test(combo-box): add keyboard navigation test --- tests/ComboBox/ComboBox.test.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/ComboBox/ComboBox.test.ts b/tests/ComboBox/ComboBox.test.ts index 67cdf8b4..765ae52f 100644 --- a/tests/ComboBox/ComboBox.test.ts +++ b/tests/ComboBox/ComboBox.test.ts @@ -69,6 +69,26 @@ describe("ComboBox", () => { expect(screen.getByRole("textbox")).toHaveValue(""); }); + it("should handle clear selection via keyboard navigation", async () => { + const consoleLog = vi.spyOn(console, "log"); + render(ComboBox, { + props: { + selectedId: "1", + value: "Email", + }, + }); + + const clearButton = screen.getByRole("button", { + name: /clear/i, + }); + clearButton.focus(); + expect(clearButton).toHaveFocus(); + await user.keyboard("{Enter}"); + + expect(consoleLog).toHaveBeenCalledWith("clear", expect.any(String)); + expect(screen.getByRole("textbox")).toHaveValue(""); + }); + it("should use custom translations when translateWithId is provided", () => { const customTranslations = { clearSelection: "Remove selected item",