fix(list-box): correct button/description translations based on selection count

The `ListBoxSelection` component now properly handles
translations for the clear button based on the selected items:

- Fix `buttonLabel` and `description` to use the same translation logic
- Add tests for custom translations in both `ComboBox` and `MultiSelect`
This commit is contained in:
Eric Liu 2025-03-23 11:12:48 -07:00
commit 5c332bae5e
4 changed files with 75 additions and 13 deletions

View file

@ -60,13 +60,35 @@ describe("ComboBox", () => {
},
});
const clearButton = screen.getByRole("button", { name: /clear/i });
const clearButton = screen.getByRole("button", {
name: "Clear selected item",
});
await user.click(clearButton);
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",
clearAll: "Remove all items",
} as const;
render(ComboBox, {
props: {
selectedId: "1",
value: "Email",
translateWithIdSelection: (id) => customTranslations[id],
},
});
const clearButton = screen.getByRole("button", {
name: "Remove selected item",
});
expect(clearButton).toBeInTheDocument();
});
it("should handle disabled state", () => {
render(ComboBox, { props: { disabled: true } });