@etsoo/materialui 1.3.43 → 1.3.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/NotifierMUTests.tsx +140 -140
- package/__tests__/ResponsePage.tsx +48 -0
- package/__tests__/SelectEx.tsx +2 -2
- package/__tests__/SwitchAnt.tsx +17 -17
- package/package.json +1 -1
- package/src/pages/ResponsivePageProps.ts +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from
|
|
5
|
-
import React from
|
|
6
|
-
import { createRoot } from
|
|
7
|
-
import { act } from
|
|
8
|
-
import { NotifierMU } from
|
|
2
|
+
INotification,
|
|
3
|
+
NotificationMessageType
|
|
4
|
+
} from "@etsoo/notificationbase";
|
|
5
|
+
import React from "react";
|
|
6
|
+
import { createRoot } from "react-dom/client";
|
|
7
|
+
import { act } from "react-dom/test-utils";
|
|
8
|
+
import { NotifierMU } from "../src";
|
|
9
9
|
|
|
10
10
|
// Without it will popup error:
|
|
11
11
|
// The current testing environment is not configured to support act
|
|
@@ -13,7 +13,7 @@ import { NotifierMU } from '../src';
|
|
|
13
13
|
|
|
14
14
|
// Root
|
|
15
15
|
const root = document.body;
|
|
16
|
-
const container: HTMLElement = document.createElement(
|
|
16
|
+
const container: HTMLElement = document.createElement("div");
|
|
17
17
|
root.append(container);
|
|
18
18
|
|
|
19
19
|
// The state provider
|
|
@@ -21,8 +21,8 @@ const Provider = NotifierMU.setup();
|
|
|
21
21
|
const reactRoot = createRoot(container);
|
|
22
22
|
|
|
23
23
|
act(() => {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
// Concorrent renderer needs act block
|
|
25
|
+
reactRoot.render(<Provider />);
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
// Notifier
|
|
@@ -32,186 +32,186 @@ const notifier = NotifierMU.instance;
|
|
|
32
32
|
// https://jestjs.io/docs/en/timer-mocks
|
|
33
33
|
jest.useFakeTimers();
|
|
34
34
|
|
|
35
|
-
test(
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
test("Alert tests", async () => {
|
|
36
|
+
// Click
|
|
37
|
+
const handleClick = jest.fn();
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
act(() => {
|
|
40
|
+
// Add the notification
|
|
41
|
+
notifier.alert("Alert message", handleClick);
|
|
42
|
+
});
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
// Button
|
|
45
|
+
const button = root.getElementsByTagName("button");
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
expect(button.length).toBe(1);
|
|
48
|
+
expect(button[0].innerHTML).toContain("OK");
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
await act(async () => {
|
|
51
|
+
button[0].click();
|
|
52
|
+
});
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
expect(handleClick).toHaveBeenCalled();
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
// Fast forward
|
|
57
|
+
jest.runOnlyPendingTimers();
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
test(
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
test("Confirm tests", async () => {
|
|
61
|
+
// Click
|
|
62
|
+
const handleClick = jest.fn();
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
act(() => {
|
|
65
|
+
// Add the notification
|
|
66
|
+
notifier.confirm("Confirm message", undefined, handleClick);
|
|
67
|
+
});
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
// Button
|
|
70
|
+
const button = root.getElementsByTagName("button");
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
expect(button.length).toBe(2);
|
|
73
|
+
expect(button[0].innerHTML).toContain("Cancel");
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
await act(async () => {
|
|
76
|
+
button[0].click();
|
|
77
|
+
});
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
expect(handleClick).toHaveBeenCalled();
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
// Fast forward
|
|
82
|
+
jest.runOnlyPendingTimers();
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
-
test(
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
test("Confirm tests without cancel button", async () => {
|
|
86
|
+
// Click
|
|
87
|
+
const handleClick = jest.fn();
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
});
|
|
89
|
+
act(() => {
|
|
90
|
+
// Add the notification
|
|
91
|
+
notifier.confirm("Confirm message", undefined, handleClick, {
|
|
92
|
+
cancelButton: false
|
|
94
93
|
});
|
|
94
|
+
});
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
// Button
|
|
97
|
+
const button = root.getElementsByTagName("button");
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
expect(button.length).toBe(1);
|
|
100
|
+
expect(button[0].innerHTML).toContain("OK");
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
await act(async () => {
|
|
103
|
+
button[0].click();
|
|
104
|
+
});
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
expect(handleClick).toHaveBeenCalled();
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
// Fast forward
|
|
109
|
+
jest.runOnlyPendingTimers();
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
-
test(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
test("Prompt tests", async () => {
|
|
113
|
+
// Click
|
|
114
|
+
const handleClick = jest.fn((result: boolean) => {
|
|
115
|
+
expect(result).toBeTruthy();
|
|
116
|
+
});
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
});
|
|
118
|
+
act(() => {
|
|
119
|
+
// Add the notification
|
|
120
|
+
notifier.prompt<boolean>("Prompt message", handleClick, undefined, {
|
|
121
|
+
type: "switch",
|
|
122
|
+
inputProps: { required: false }
|
|
124
123
|
});
|
|
124
|
+
});
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
// Button
|
|
127
|
+
const button = root.getElementsByTagName("button");
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
expect(button.length).toBe(2); // Switch will generate a button
|
|
130
|
+
expect(button[1].innerHTML).toContain("OK");
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
await act(async () => {
|
|
133
|
+
button[1].click();
|
|
134
|
+
});
|
|
135
135
|
|
|
136
|
-
|
|
136
|
+
expect(handleClick).toHaveBeenCalled();
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
jest.runOnlyPendingTimers();
|
|
139
139
|
});
|
|
140
140
|
|
|
141
|
-
test(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
141
|
+
test("Prompt tests with form submit", async () => {
|
|
142
|
+
// Click
|
|
143
|
+
const handleClick = jest.fn((result: boolean) => {
|
|
144
|
+
expect(result).toBeTruthy();
|
|
145
|
+
});
|
|
146
146
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
});
|
|
147
|
+
act(() => {
|
|
148
|
+
// Add the notification
|
|
149
|
+
notifier.prompt<boolean>("Prompt message", handleClick, undefined, {
|
|
150
|
+
type: "switch",
|
|
151
|
+
inputProps: { required: false }
|
|
153
152
|
});
|
|
153
|
+
});
|
|
154
154
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
155
|
+
await act(async () => {
|
|
156
|
+
(
|
|
157
|
+
root
|
|
158
|
+
.getElementsByTagName("form")[0]
|
|
159
|
+
.elements.namedItem("okButton") as HTMLButtonElement
|
|
160
|
+
)?.click();
|
|
161
|
+
});
|
|
162
162
|
|
|
163
|
-
|
|
163
|
+
expect(handleClick).toHaveBeenCalled();
|
|
164
164
|
|
|
165
|
-
|
|
165
|
+
jest.runOnlyPendingTimers();
|
|
166
166
|
});
|
|
167
167
|
|
|
168
|
-
test(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
let n: INotification<React.ReactNode, any> | undefined;
|
|
173
|
-
act(() => {
|
|
174
|
-
// Add the notification
|
|
175
|
-
n = notifier.message(
|
|
176
|
-
NotificationMessageType.Danger,
|
|
177
|
-
'Error Message',
|
|
178
|
-
undefined,
|
|
179
|
-
{
|
|
180
|
-
callback
|
|
181
|
-
}
|
|
182
|
-
);
|
|
183
|
-
});
|
|
168
|
+
test("Message tests", (done) => {
|
|
169
|
+
// Callback
|
|
170
|
+
const callback = jest.fn(() => done());
|
|
184
171
|
|
|
185
|
-
|
|
172
|
+
let n: INotification<React.ReactNode, any> | undefined;
|
|
173
|
+
act(() => {
|
|
174
|
+
// Add the notification
|
|
175
|
+
n = notifier.message(
|
|
176
|
+
NotificationMessageType.Danger,
|
|
177
|
+
"Error Message",
|
|
178
|
+
undefined,
|
|
179
|
+
{
|
|
180
|
+
callback
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
});
|
|
186
184
|
|
|
187
|
-
|
|
185
|
+
expect(n?.timespan).toBe(5);
|
|
188
186
|
|
|
189
|
-
|
|
190
|
-
// Here is the bug need further study...
|
|
191
|
-
n?.dismiss();
|
|
187
|
+
expect(root.innerHTML).toContain("Error Message");
|
|
192
188
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
189
|
+
act(() => {
|
|
190
|
+
// Here is the bug need further study...
|
|
191
|
+
n?.dismiss();
|
|
196
192
|
|
|
197
|
-
|
|
198
|
-
|
|
193
|
+
// Fast forward
|
|
194
|
+
jest.runOnlyPendingTimers();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
expect(root.innerHTML).not.toContain("Error Message");
|
|
198
|
+
expect(callback).toHaveBeenCalled();
|
|
199
199
|
});
|
|
200
200
|
|
|
201
|
-
test(
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
201
|
+
test("Loading tests", () => {
|
|
202
|
+
act(() => {
|
|
203
|
+
// Add the notification
|
|
204
|
+
notifier.showLoading("Loading");
|
|
205
|
+
});
|
|
206
206
|
|
|
207
|
-
|
|
207
|
+
expect(root.innerHTML).toContain("Loading");
|
|
208
208
|
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
act(() => {
|
|
210
|
+
notifier.hideLoading();
|
|
211
211
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
212
|
+
// Fast forward
|
|
213
|
+
jest.runOnlyPendingTimers();
|
|
214
|
+
});
|
|
215
215
|
|
|
216
|
-
|
|
216
|
+
expect(root.innerHTML).not.toContain("Loading");
|
|
217
217
|
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { act, render } from "@testing-library/react";
|
|
2
|
+
import { MUGlobal, MobileListItemRenderer, ResponsivePage } from "../src";
|
|
3
|
+
import React from "react";
|
|
4
|
+
|
|
5
|
+
global.ResizeObserver = jest.fn().mockImplementation(() => ({
|
|
6
|
+
observe: jest.fn(),
|
|
7
|
+
unobserve: jest.fn(),
|
|
8
|
+
disconnect: jest.fn()
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
type Data = { id: number; name: string };
|
|
12
|
+
|
|
13
|
+
// Timer mock
|
|
14
|
+
// https://jestjs.io/docs/en/timer-mocks
|
|
15
|
+
jest.useFakeTimers();
|
|
16
|
+
|
|
17
|
+
it("Render ResponsePage", async () => {
|
|
18
|
+
// Act
|
|
19
|
+
render(
|
|
20
|
+
<ResponsivePage<Data>
|
|
21
|
+
fields={[]}
|
|
22
|
+
columns={[
|
|
23
|
+
{ field: "id", header: "ID" },
|
|
24
|
+
{ field: "name", header: "Name" }
|
|
25
|
+
]}
|
|
26
|
+
itemSize={[118, MUGlobal.pagePaddings]}
|
|
27
|
+
loadData={(_data) =>
|
|
28
|
+
Promise.resolve([
|
|
29
|
+
{ id: 1, name: "Name 1" },
|
|
30
|
+
{ id: 2, name: "Name 2" }
|
|
31
|
+
])
|
|
32
|
+
}
|
|
33
|
+
innerItemRenderer={(props) =>
|
|
34
|
+
MobileListItemRenderer(props, (data) => {
|
|
35
|
+
return [data.name, undefined, [], <React.Fragment></React.Fragment>];
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
act(() => {
|
|
42
|
+
// Fast forward
|
|
43
|
+
jest.runOnlyPendingTimers();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Assert
|
|
47
|
+
expect(document.getElementById("page-container")).not.toBeNull();
|
|
48
|
+
});
|
package/__tests__/SelectEx.tsx
CHANGED
|
@@ -31,7 +31,7 @@ it("Render SelectEx", async () => {
|
|
|
31
31
|
/>
|
|
32
32
|
);
|
|
33
33
|
|
|
34
|
-
expect(itemChangeCallback).
|
|
34
|
+
expect(itemChangeCallback).toHaveBeenCalled();
|
|
35
35
|
|
|
36
36
|
// Act, click to show the list
|
|
37
37
|
const button = screen.getByRole("combobox");
|
|
@@ -110,5 +110,5 @@ it("Render multiple SelectEx", async () => {
|
|
|
110
110
|
|
|
111
111
|
expect(checkbox3?.checked).toBeTruthy();
|
|
112
112
|
|
|
113
|
-
expect(itemChangeCallback).
|
|
113
|
+
expect(itemChangeCallback).toHaveBeenCalledTimes(2);
|
|
114
114
|
});
|
package/__tests__/SwitchAnt.tsx
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { getByText, render } from
|
|
2
|
-
import React from
|
|
3
|
-
import { act } from
|
|
4
|
-
import { SwitchAnt } from
|
|
1
|
+
import { getByText, render } from "@testing-library/react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { act } from "react-dom/test-utils";
|
|
4
|
+
import { SwitchAnt } from "../src/SwitchAnt";
|
|
5
5
|
|
|
6
|
-
it(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
it("SwitchAnt Tests", () => {
|
|
7
|
+
const onChange = jest.fn((event: React.ChangeEvent<HTMLInputElement>) =>
|
|
8
|
+
expect(event.target.checked).toBeTruthy()
|
|
9
|
+
);
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
// Render component
|
|
12
|
+
const { baseElement } = render(
|
|
13
|
+
<SwitchAnt startLabel="No" endLabel="Yes" onChange={onChange} />
|
|
14
|
+
);
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
const yes = getByText(baseElement, "Yes");
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
act(() => {
|
|
19
|
+
yes.click();
|
|
20
|
+
});
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
expect(onChange).toHaveBeenCalled();
|
|
23
23
|
});
|
package/package.json
CHANGED