-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTable.test.tsx
More file actions
102 lines (89 loc) · 2.63 KB
/
Table.test.tsx
File metadata and controls
102 lines (89 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { describe, expect, it } from "vitest";
import { fireEvent, render, screen } from "@testing-library/react";
import "@testing-library/jest-dom";
import { Table } from "@/plugins/mui/Table";
import { createChangeHandler } from "@/plugins/mui/common.test";
describe("Table", () => {
const rows = [
["John", "Doe"],
["Johnie", "Undoe"],
];
const columns = [
{ id: "firstName", label: "First Name" },
{ id: "lastName", label: "Last Name" },
];
it("should render the Table component", () => {
render(
<Table
id="table"
type={"Table"}
rows={rows}
columns={columns}
onChange={() => {}}
/>,
);
const table = screen.getByRole("table");
expect(table).toBeDefined();
columns.forEach((column) => {
expect(screen.getByText(column.label)).toBeInTheDocument();
});
rows.forEach((row, index) => {
expect(screen.getByText(row[index])).toBeInTheDocument();
});
});
it("should not render the Table component when no columns provided", () => {
render(<Table id="table" type={"Table"} rows={rows} onChange={() => {}} />);
const table = screen.queryByRole("table");
expect(table).toBeNull();
});
it("should not render the Table component when no rows provided", () => {
render(<Table id="table" type={"Table"} rows={rows} onChange={() => {}} />);
const table = screen.queryByRole("table");
expect(table).toBeNull();
});
it("should call onChange on row click", () => {
const { recordedEvents, onChange } = createChangeHandler();
render(
<Table
id="table"
type={"Table"}
rows={rows}
columns={columns}
onChange={onChange}
/>,
);
fireEvent.click(screen.getAllByRole("row")[1]);
expect(recordedEvents.length).toEqual(1);
expect(recordedEvents[0]).toEqual({
componentType: "Table",
id: "table",
property: "value",
value: {
firstName: "John",
lastName: "Doe",
},
});
});
it("should not render the Table component when no id provided", () => {
render(<Table type={"Table"} rows={rows} onChange={() => {}} />);
const table = screen.queryByRole("table");
expect(table).toBeNull();
});
it(
"should render the Table component with skeleton when skeletonProps are" +
" provided",
() => {
render(
<Table
id="table"
type={"Table"}
rows={rows}
onChange={() => {}}
skeletonProps={{ variant: "rectangular" }}
/>,
);
const table = screen.queryByRole("table");
expect(table).toBeNull();
},
);
});