Debian Codegraph @

install/freeipa-webui/src/components/layouts/Skeleton/SkeletonOnTableLayout/SkeletonOnTableLayout.test.tsx

raw
1 import React from "react";
2 import { render, screen, cleanup } from "@testing-library/react";
3 import { describe, expect, it, afterEach } from "vitest";
4 // Component
5 import SkeletonOnTableLayout from "./SkeletonOnTableLayout";
6
7 describe("SkeletonOnTableLayout Component", () => {
8 afterEach(() => {
9 cleanup();
10 });
11
12 it("render component with default props", () => {
13 render(<SkeletonOnTableLayout rows={2} colSpan={1} />);
14
15 const skeleton = screen.getAllByText("Loading content");
16 expect(skeleton.length).toBe(2);
17 });
18
19 it("renders with correct number of skeleton rows", () => {
20 render(<SkeletonOnTableLayout rows={5} colSpan={3} />);
21
22 const rows = screen.getAllByRole("row");
23 expect(rows).toHaveLength(5);
24 });
25
26 it("renders with accessible text", () => {
27 render(<SkeletonOnTableLayout rows={2} colSpan={1} />);
28
29 const strText = screen.getAllByText("Loading content");
30 // Check if the skeleton text is present in the document
31 strText.forEach((text) => {
32 expect(text).toBeInTheDocument();
33 });
34 });
35
36 it("renders with custom accessible text", () => {
37 const customText = "Loading data...";
38
39 render(
40 <SkeletonOnTableLayout
41 rows={2}
42 colSpan={1}
43 screenreaderText={customText}
44 />
45 );
46
47 const strText = screen.getAllByText(customText);
48 // Check if the skeleton text is present in the document
49 strText.forEach((text) => {
50 expect(text).toBeInTheDocument();
51 });
52 });
53
54 it("renders with custom colspan", () => {
55 render(<SkeletonOnTableLayout rows={1} colSpan={5} />);
56 const td = screen.getByRole("cell");
57 expect(td).toHaveAttribute("colspan", "5");
58 });
59 });