test(combo-box): add keyboard navigation test

This commit is contained in:
Eric Liu 2025-05-20 08:59:14 -07:00
commit 50b4761791

View file

@ -69,6 +69,26 @@ describe("ComboBox", () => {
expect(screen.getByRole("textbox")).toHaveValue(""); 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", () => { it("should use custom translations when translateWithId is provided", () => {
const customTranslations = { const customTranslations = {
clearSelection: "Remove selected item", clearSelection: "Remove selected item",