test(multi-select): reuse openMenu/closeMenu utilities

This commit is contained in:
Eric Liu 2025-08-17 13:57:24 -07:00
commit be4f2f13a2

View file

@ -465,7 +465,7 @@ describe("MultiSelect", () => {
selectedIds: ["0", "1"], selectedIds: ["0", "1"],
}, },
}); });
await user.click(screen.getAllByRole("button")[0]); await openMenu();
const options = screen.getAllByRole("option"); const options = screen.getAllByRole("option");
expect(options[0]).toHaveAttribute("aria-selected", "true"); expect(options[0]).toHaveAttribute("aria-selected", "true");
@ -474,7 +474,7 @@ describe("MultiSelect", () => {
const clearButton = screen.getByRole("button", { name: /clear/i }); const clearButton = screen.getByRole("button", { name: /clear/i });
await user.click(clearButton); await user.click(clearButton);
await user.click(screen.getByRole("button")); await closeMenu();
expect(options[0]).toHaveAttribute("aria-selected", "false"); expect(options[0]).toHaveAttribute("aria-selected", "false");
expect(options[1]).toHaveAttribute("aria-selected", "false"); expect(options[1]).toHaveAttribute("aria-selected", "false");
@ -493,7 +493,7 @@ describe("MultiSelect", () => {
placeholder: "Filter...", placeholder: "Filter...",
}, },
}); });
await user.click(screen.getByRole("button")); await openMenu();
const input = screen.getByPlaceholderText("Filter..."); const input = screen.getByPlaceholderText("Filter...");
await user.type(input, "a"); await user.type(input, "a");
@ -513,7 +513,7 @@ describe("MultiSelect", () => {
placeholder: "Filter...", placeholder: "Filter...",
}, },
}); });
await user.click(screen.getByRole("button")); await openMenu();
const input = screen.getByPlaceholderText("Filter..."); const input = screen.getByPlaceholderText("Filter...");
expect(input).toHaveFocus(); expect(input).toHaveFocus();
}); });
@ -528,7 +528,7 @@ describe("MultiSelect", () => {
], ],
}, },
}); });
await user.click(screen.getByRole("button")); await openMenu();
const disabledOption = screen.getByText("B").closest("[role='option']"); const disabledOption = screen.getByText("B").closest("[role='option']");
await user.click(disabledOption!); await user.click(disabledOption!);