import { screen, render, act } from "@testing-library/react";
import { axe } from "jest-axe";
import { Alert, AlertVariant } from "../../components/Alert/Alert";
describe("Alert", () => {
test("Should render component correctly.", () => {
const { container } = render(This is an alert!);
expect(container.firstChild).toMatchSnapshot();
});
});
describe("Accessibility", () => {
test("Should have no accessibility violations.", async () => {
const { container } = render(This is an alert!);
const results = await axe(container);
expect(results).toHaveNoViolations();
});
});
describe("Props", () => {
test("Should render children correctly.", () => {
render(Alert);
expect(screen.getByText("Alert")).toBeInTheDocument();
});
test("Should render close button correctly.", () => {
render(Alert);
const closeButton = screen.getByRole("button");
expect(closeButton).toBeInTheDocument();
act(() => closeButton.click());
});
test.each(["error", "info", "success", "warning"])(
"Should render variants correctly.",
(variant) => {
render(
Alert
);
expect(
document.getElementsByClassName("alertContainer")[0]
).toHaveClass(variant);
expect(screen.getByRole("button")).toBeInTheDocument();
}
);
});