import { describe, it, expect } from "vitest";
import { render, screen } from "@testing-library/react";
import { Loader } from ".";
describe("Loader", () => {
describe("snapshots", () => {
it("matches snapshot without children", () => {
const res = render();
expect(res.asFragment()).toMatchSnapshot();
});
it("matches snapshot with children", () => {
const res = render(Loading...);
expect(res.asFragment()).toMatchSnapshot();
});
});
it("renders children when isLoading", () => {
render(Loading...);
expect(screen.getByText("Loading...")).toBeTruthy();
});
it("does not render children when not isLoading", () => {
render(Loading...);
expect(screen.queryByText("Loading...")).toBeNull();
});
describe("Loading States", () => {
it("Renders the children when loading", () => {
render(Loading...);
expect(screen.getByText("Loading...")).toBeTruthy();
});
it("Renders a check mark when not loading", () => {
render(Loading...);
expect(screen.getByTestId("checkmark")).toBeTruthy();
});
it("Renders children in both state when children is a function", () => {
render(
{({ isLoading }) => (
Loading...
)}
);
expect(screen.getByTestId("not-loading")).toBeTruthy();
render(
{({ isLoading }) => (
Loading...
)}
);
expect(screen.getByTestId("loading")).toBeTruthy();
});
});
});