(react) add icon to Button

The DS does not offer an icons set yet but it seems important to
already provide a support for external icons in Button.
This commit is contained in:
Nathan Vasse
2023-01-16 11:17:27 +01:00
committed by NathanVss
parent 9fa0ff8ad3
commit 05f9252029
5 changed files with 111 additions and 3 deletions

View File

@@ -12,6 +12,24 @@ describe("<Button/>", () => {
expect(button.classList.contains("c__button")).toBe(true);
});
it("renders with custom class when using left icon", () => {
render(<Button icon={<div>Icon</div>}>Test button</Button>);
const button = screen.getByText("Test button");
expect(button.classList.contains("c__button")).toBe(true);
expect(button.classList.contains("c__button--with-icon--left")).toBe(true);
});
it("renders with custom class when using right icon", () => {
render(
<Button icon={<div>Icon</div>} iconPosition="right">
Test button
</Button>
);
const button = screen.getByText("Test button");
expect(button.classList.contains("c__button")).toBe(true);
expect(button.classList.contains("c__button--with-icon--right")).toBe(true);
});
it("call onClick when click occurs", async () => {
const user = userEvent.setup();
const handleClick = vi.fn();