-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteam.test.js
201 lines (174 loc) · 6.52 KB
/
team.test.js
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import { render, screen } from "@testing-library/react";
import Team from "./src/scenes/team/index";
//import Header from "../components/Header";
import UserList from "./src/data/UserList";
import { DataGrid } from "@mui/x-data-grid";
import { colorTokens } from "./src/themes";
import AdminPanelSettingsOutlinedIcon from "@mui/icons-material/AdminPanelSettingsOutlined";
import { Typography, Box } from "@mui/material";
import { colors } from "@mui/material";
import { teamColumns } from "./src/data/DataColumns";
import { toHaveStyle } from '@testing-library/jest-dom';
import * as XDataGrid from '@mui/x-data-grid';
jest.mock('@mui/x-data-grid', () => {
return {
DataGrid: jest.fn(),
};
});
jest.mock('@mui/material', () => {
return {
Box: jest.fn(),
Typography: jest.fn(),
colors: jest.fn(),
useTheme: jest.fn(),
};
});
jest.mock('@mui/icons-material/AdminPanelSettingsOutlined', () => {
return {
default: jest.fn(),
};
});
jest.mock('./src/themes', () => {
return {
colorTokens: jest.fn(),
};
});
jest.mock('./src/data/UserList', () => {
return jest.fn();
});
jest.mock('./src/data/DataColumns', () => {
return {
teamColumns: jest.fn(),
};
});
describe("Team", () => {
it("should render the Header component with the correct title and subtitle", () => {
render(<Team />);
const header = screen.getByRole("heading", { name: "TEAM" });
//expect(header).toBeInTheDocument();
expect(header).toHaveTextContent("TEAM");
expect(header).toHaveTextContent("Managing the Team Members");
});
// UserList() returns an empty array
it("should set records state to an empty array", () => {
render(<Team />);
const userList = screen.find(<UserList />);
expect(userList.prop("records")).toEqual([]);
expect(userList.prop("records")).toEqual([]);
expect(userList.prop("records")).toEqual([]);
});
it("should render a DataGrid component with the correct props", () => {
const { render: view } = render(<Team />);
const dataGrid = view.find(DataGrid);
expect(dataGrid.prop("checkboxSelection")).toEqual(true);
expect(dataGrid.prop("rows")).toEqual(UserList());
expect(dataGrid.prop("columns")).toEqual(teamColumns);
expect(dataGrid.prop("sortModel")).toEqual([{ field: "id", sort: "asc" }]);
expect(dataGrid.prop("pageSize")).toEqual(25);
expect(dataGrid.prop("pageSize")).toEqual(25);
});
// Renders the Access Level column with a colored box and corresponding icon and text based on the access level value
it("should render the Access Level column with the correct styling and content", () => {
const { render: view } = render(<Team />);
const accessLevelColumn = view.findWhere(
(node) => node.prop("field") === "accessLevel"
);
const renderCell = accessLevelColumn.prop("renderCell");
const mockRow = { access: "admin" };
const mockTheme = { palette: { mode: "light" } };
const mockColors = colorTokens(mockTheme.palette.mode);
const { render: mockIcon } = render(<AdminPanelSettingsOutlinedIcon />);
const { render: mockTypography } = render(<Typography />);
const { render: mockBox } = render(<Box />);
const mockUseTheme = jest
.spyOn(require("@mui/material"), "useTheme")
.mockReturnValue(mockTheme);
const mockColorTokens = jest
.spyOn(require("../../themes"), "colorTokens")
.mockReturnValue(mockColors);
const mockAdminPanelSettingsOutlinedIcon = jest
.spyOn(
require("@mui/icons-material/AdminPanelSettingsOutlined"),
"default"
)
.mockReturnValue(mockIcon);
const mockTypographyComponent = jest
.spyOn(require("@mui/material"), "Typography")
.mockReturnValue(mockTypography);
const mockBoxComponent = jest
.spyOn(require("@mui/material"), "Box")
.mockReturnValue(mockBox);
renderCell({ row: mockRow });
expect(mockBox.prop("backgroundColor")).toEqual("#03C03C");
expect(mockIcon.exists()).toBe(true);
expect(mockTypography.prop("color")).toEqual(colors.grey[100]);
expect(mockTypography.text()).toEqual("admin");
mockUseTheme.mockRestore();
mockColorTokens.mockRestore();
mockAdminPanelSettingsOutlinedIcon.mockRestore();
mockTypographyComponent.mockRestore();
mockBoxComponent.mockRestore();
});
// Renders the DataGrid with a custom style defined in the sx prop
it("should render the DataGrid with the correct custom style", () => {
const mockTheme = { palette: { mode: "light" } };
const mockColors = colorTokens(mockTheme.palette.mode);
//render(<Team />);
const { render: view } = render(<Team />);
const dataGrid = jest.fn().mockReturnValue({
rows: view,
columns: teamColumns,
sortModel: [{ field: "id", sort: "asc" }],
pageSize: 25,
});
jest.restoreAllMocks(); // Restore all mocked functions
//jest.spyOn(require("@mui/system"), "useTheme").mockReturnValue(mockTheme);
const mockColorTokens = jest
.spyOn(require("./src/themes"), "colorTokens")
.mockReturnValue(mockColors);
const mockDataGrid = jest
.spyOn(require("@mui/x-data-grid"), "DataGrid")
.mockReturnValue(dataGrid);
const mockBox = jest.spyOn(require("@mui/material"), "Box");
const mockDataGridComponent = jest.spyOn(require("@mui/x-data-grid"), "DataGrid");
//const dataGrid = view.find(DataGrid);
expect(mockBox.prop("m")).toEqual("40px 0 0 0");
expect(mockBox.prop("height")).toEqual("75vh");
expect(mockBox.prop("sx")).toEqual({
"& .MuiDataGrid-root": {
border: "none",
},
"& .MuiDataGrid-cell": {
borderBottom: "none",
},
"& .name-column--cell": {
color: mockTheme.palette.mode === "light" ? colors.grey[100] : "#FFFFFF",
},
"& .MuiDataGrid-columnHeaders": {
backgroundColor: "#3676D1",
borderBottom: "none",
},
"& .MuiDataGrid-virtualScroller": {
backgroundColor: mockColors.primary[400],
},
"& .MuiDataGrid-footerContainer": {
borderTop: "none",
backgroundColor: "#3676D1",
},
"& .MuiCheckbox-root": {
color: `#f6da54 !important`,
},
"& .MuiTablePagination-toolbar": {
color: mockTheme.palette.mode === "light" ? "#FFFFFF" : "#FFFFFF",
},
"& MuiTablePagination-actions": {
color: mockTheme.palette.mode === "light" ? "#FFFFFF" : "#FFFFFF",
},
});
mockTheme.mockRestore();
mockColorTokens.mockRestore();
mockDataGrid.mockRestore();
mockBox.mockRestore();
mockDataGridComponent.mockRestore();
});
});