|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { render, screen } from "@testing-library/react"; |
| 3 | +import { Skeleton } from "@/plugins/mui/Skeleton"; |
| 4 | + |
| 5 | +describe("Skeleton", () => { |
| 6 | + it("should render the MUI Skeleton when loading is true", () => { |
| 7 | + render(<Skeleton loading height={10} />); |
| 8 | + const muiSkeleton = screen.getByTestId("skeleton-test-id"); |
| 9 | + expect(muiSkeleton).toBeInTheDocument(); |
| 10 | + expect(muiSkeleton).toHaveClass("MuiSkeleton-root"); |
| 11 | + }); |
| 12 | + |
| 13 | + it("should not render the MUI Skeleton without skeletonProps", () => { |
| 14 | + render(<Skeleton loading />); |
| 15 | + const muiSkeleton = screen.queryByTestId("skeleton-test-id"); |
| 16 | + expect(muiSkeleton).not.toBeInTheDocument(); |
| 17 | + }); |
| 18 | + |
| 19 | + it("should not render the MUI Skeleton and render children when loading is false", () => { |
| 20 | + render( |
| 21 | + <Skeleton loading={false} height={10}> |
| 22 | + <div>Test Content</div> |
| 23 | + </Skeleton>, |
| 24 | + ); |
| 25 | + const muiSkeleton = screen.queryByTestId("skeleton-test-id"); |
| 26 | + expect(muiSkeleton).not.toBeInTheDocument(); |
| 27 | + expect(screen.getByText("Test Content")).toBeInTheDocument(); |
| 28 | + }); |
| 29 | + |
| 30 | + it("should render with the specified variant", () => { |
| 31 | + render(<Skeleton loading variant="circular" />); |
| 32 | + const muiSkeleton = screen.getByTestId("skeleton-test-id"); |
| 33 | + expect(muiSkeleton).toHaveClass("MuiSkeleton-circular"); |
| 34 | + }); |
| 35 | + |
| 36 | + it("should render with specified width and height", () => { |
| 37 | + render(<Skeleton loading width={100} height={50} />); |
| 38 | + const muiSkeleton = screen.getByTestId("skeleton-test-id"); |
| 39 | + expect(muiSkeleton).toHaveStyle("width: 100px"); |
| 40 | + expect(muiSkeleton).toHaveStyle("height: 50px"); |
| 41 | + }); |
| 42 | + |
| 43 | + it("should render with specified style", () => { |
| 44 | + render(<Skeleton loading style={{ backgroundColor: "red" }} height={10} />); |
| 45 | + const muiSkeleton = screen.getByTestId("skeleton-test-id"); |
| 46 | + expect(muiSkeleton).toHaveStyle("background-color: rgb(255, 0, 0);"); |
| 47 | + }); |
| 48 | + |
| 49 | + it("should render with specified animation", () => { |
| 50 | + render(<Skeleton loading animation="wave" />); |
| 51 | + const muiSkeleton = screen.getByTestId("skeleton-test-id"); |
| 52 | + expect(muiSkeleton).toHaveClass("MuiSkeleton-wave"); |
| 53 | + }); |
| 54 | +}); |
0 commit comments