import React from "react";
import { render, screen, fireEvent } from "@testing-library/react";
import { ISelectLabel, ISelectTeam } from "interfaces/target";
import TargetChipSelector from "./TargetChipSelector";
describe("TargetChipSelector", () => {
const mockOnClick = jest.fn();
const mockLabel: ISelectLabel = {
id: 1,
name: "Example Label",
label_type: "regular",
description: "A test label",
};
const mockTeam: ISelectTeam = {
id: 2,
name: "Example Team",
description: "A test team",
};
it("renders the correct display text for a label", () => {
render(
);
expect(screen.getByText("Example Label")).toBeInTheDocument();
});
it("renders the correct display text for a team", () => {
render(
);
expect(screen.getByText("Example Team")).toBeInTheDocument();
});
it("renders the correct icon when selected", () => {
render(
);
expect(screen.getByLabelText("check")).toBeInTheDocument();
});
it("renders the correct icon when not selected", () => {
render(
);
expect(screen.getByLabelText("plus")).toBeInTheDocument();
});
it("calls the onClick handler with the correct entity when clicked", () => {
render(
(event) => mockOnClick(value, event)}
/>
);
fireEvent.click(screen.getByRole("button"));
expect(mockOnClick).toHaveBeenCalledWith(mockLabel, expect.any(Object));
});
it("applies the correct data-selected attribute when selected", () => {
render(
);
const button = screen.getByRole("button");
expect(button).toHaveAttribute("data-selected", "true");
});
it("applies the correct data-selected attribute when not selected", () => {
render(
);
const button = screen.getByRole("button");
expect(button).toHaveAttribute("data-selected", "false");
});
});