Skip to content

Commit f84c743

Browse files
committed
Add Skeleton.test.tsx
1 parent 4be9d7e commit f84c743

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
 (0)