import { ViewCartButton } from "./index";
import { fireEvent, render, screen } from "@testing-library/react";
describe("ViewCartButton", () => {
const defaultProps = {
cartTotalText: "$49.99/mo",
onClick: jest.fn(),
isOpen: false,
};
beforeEach(() => {
jest.clearAllMocks();
});
it("renders 'View cart' label", () => {
render();
expect(screen.getByText("View cart")).toBeInTheDocument();
});
it("renders cart total text", () => {
render();
expect(screen.getByTestId("cart-total")).toHaveTextContent("$49.99/mo");
});
it("calls onClick when clicked", () => {
render();
fireEvent.click(screen.getByRole("button"));
expect(defaultProps.onClick).toHaveBeenCalledTimes(1);
});
it("renders arrow icon", () => {
render();
expect(screen.getByText("keyboard_arrow_up")).toBeInTheDocument();
});
it("applies rotate-0 class when isOpen is false", () => {
render();
const icon = screen.getByText("keyboard_arrow_up");
expect(icon.className).toContain("rotate-0");
});
it("applies rotate-180 class when isOpen is true", () => {
render();
const icon = screen.getByText("keyboard_arrow_up");
expect(icon.className).toContain("rotate-180");
});
it("passes additional button attributes", () => {
render(
);
const button = screen.getByRole("button");
expect(button).toBeDisabled();
expect(button).toHaveAttribute("aria-label", "cart");
});
});