Skip to content

Commit

Permalink
Merge pull request #761 from Enterprise-CMCS/main
Browse files Browse the repository at this point in the history
Release to val
  • Loading branch information
mdial89f committed Sep 9, 2024
2 parents e5cf561 + fb5f650 commit eaef3a7
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions react-app/src/components/Chip/Chip.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { render } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, test, vi } from "vitest";
import { Chip } from ".";

describe("Chip", () => {
test("onChipClick is called", async () => {
const mockedOnChipClick = vi.fn();

const { container } = render(<Chip onChipClick={mockedOnChipClick} />);

const chipButton = container.getElementsByClassName(
"h-8 py-2 cursor-pointer",
)[0];

await userEvent.click(chipButton);

expect(mockedOnChipClick).toHaveBeenCalled();
});

test("onIconClick is called", async () => {
const mockedOnIconClick = vi.fn();

const { getByRole } = render(<Chip onIconClick={mockedOnIconClick} />);

const chipButton = getByRole("button");

await userEvent.click(chipButton);

expect(mockedOnIconClick).toHaveBeenCalled();
});

test("noIcon or destructive variants do not render an icon", () => {
const { queryByRole, rerender } = render(<Chip variant="destructive" />);

expect(queryByRole("button")).not.toBeInTheDocument();

rerender(<Chip variant="noIcon" />);

expect(queryByRole("button")).not.toBeInTheDocument();
});
});

0 comments on commit eaef3a7

Please sign in to comment.