@etsoo/materialui 1.3.43 → 1.3.45

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.
@@ -1,11 +1,11 @@
1
1
  import {
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';
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('div');
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
- // Concorrent renderer needs act block
25
- reactRoot.render(<Provider />);
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('Alert tests', async () => {
36
- // Click
37
- const handleClick = jest.fn();
35
+ test("Alert tests", async () => {
36
+ // Click
37
+ const handleClick = jest.fn();
38
38
 
39
- act(() => {
40
- // Add the notification
41
- notifier.alert('Alert message', handleClick);
42
- });
39
+ act(() => {
40
+ // Add the notification
41
+ notifier.alert("Alert message", handleClick);
42
+ });
43
43
 
44
- // Button
45
- const button = root.getElementsByTagName('button');
44
+ // Button
45
+ const button = root.getElementsByTagName("button");
46
46
 
47
- expect(button.length).toBe(1);
48
- expect(button[0].innerHTML).toContain('OK');
47
+ expect(button.length).toBe(1);
48
+ expect(button[0].innerHTML).toContain("OK");
49
49
 
50
- await act(async () => {
51
- button[0].click();
52
- });
50
+ await act(async () => {
51
+ button[0].click();
52
+ });
53
53
 
54
- expect(handleClick).toBeCalled();
54
+ expect(handleClick).toHaveBeenCalled();
55
55
 
56
- // Fast forward
57
- jest.runOnlyPendingTimers();
56
+ // Fast forward
57
+ jest.runOnlyPendingTimers();
58
58
  });
59
59
 
60
- test('Confirm tests', async () => {
61
- // Click
62
- const handleClick = jest.fn();
60
+ test("Confirm tests", async () => {
61
+ // Click
62
+ const handleClick = jest.fn();
63
63
 
64
- act(() => {
65
- // Add the notification
66
- notifier.confirm('Confirm message', undefined, handleClick);
67
- });
64
+ act(() => {
65
+ // Add the notification
66
+ notifier.confirm("Confirm message", undefined, handleClick);
67
+ });
68
68
 
69
- // Button
70
- const button = root.getElementsByTagName('button');
69
+ // Button
70
+ const button = root.getElementsByTagName("button");
71
71
 
72
- expect(button.length).toBe(2);
73
- expect(button[0].innerHTML).toContain('Cancel');
72
+ expect(button.length).toBe(2);
73
+ expect(button[0].innerHTML).toContain("Cancel");
74
74
 
75
- await act(async () => {
76
- button[0].click();
77
- });
75
+ await act(async () => {
76
+ button[0].click();
77
+ });
78
78
 
79
- expect(handleClick).toBeCalled();
79
+ expect(handleClick).toHaveBeenCalled();
80
80
 
81
- // Fast forward
82
- jest.runOnlyPendingTimers();
81
+ // Fast forward
82
+ jest.runOnlyPendingTimers();
83
83
  });
84
84
 
85
- test('Confirm tests without cancel button', async () => {
86
- // Click
87
- const handleClick = jest.fn();
85
+ test("Confirm tests without cancel button", async () => {
86
+ // Click
87
+ const handleClick = jest.fn();
88
88
 
89
- act(() => {
90
- // Add the notification
91
- notifier.confirm('Confirm message', undefined, handleClick, {
92
- cancelButton: false
93
- });
89
+ act(() => {
90
+ // Add the notification
91
+ notifier.confirm("Confirm message", undefined, handleClick, {
92
+ cancelButton: false
94
93
  });
94
+ });
95
95
 
96
- // Button
97
- const button = root.getElementsByTagName('button');
96
+ // Button
97
+ const button = root.getElementsByTagName("button");
98
98
 
99
- expect(button.length).toBe(1);
100
- expect(button[0].innerHTML).toContain('OK');
99
+ expect(button.length).toBe(1);
100
+ expect(button[0].innerHTML).toContain("OK");
101
101
 
102
- await act(async () => {
103
- button[0].click();
104
- });
102
+ await act(async () => {
103
+ button[0].click();
104
+ });
105
105
 
106
- expect(handleClick).toBeCalled();
106
+ expect(handleClick).toHaveBeenCalled();
107
107
 
108
- // Fast forward
109
- jest.runOnlyPendingTimers();
108
+ // Fast forward
109
+ jest.runOnlyPendingTimers();
110
110
  });
111
111
 
112
- test('Prompt tests', async () => {
113
- // Click
114
- const handleClick = jest.fn((result: boolean) => {
115
- expect(result).toBeTruthy();
116
- });
112
+ test("Prompt tests", async () => {
113
+ // Click
114
+ const handleClick = jest.fn((result: boolean) => {
115
+ expect(result).toBeTruthy();
116
+ });
117
117
 
118
- act(() => {
119
- // Add the notification
120
- notifier.prompt<boolean>('Prompt message', handleClick, undefined, {
121
- type: 'switch',
122
- inputProps: { required: false }
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
- // Button
127
- const button = root.getElementsByTagName('button');
126
+ // Button
127
+ const button = root.getElementsByTagName("button");
128
128
 
129
- expect(button.length).toBe(2); // Switch will generate a button
130
- expect(button[1].innerHTML).toContain('OK');
129
+ expect(button.length).toBe(2); // Switch will generate a button
130
+ expect(button[1].innerHTML).toContain("OK");
131
131
 
132
- await act(async () => {
133
- button[1].click();
134
- });
132
+ await act(async () => {
133
+ button[1].click();
134
+ });
135
135
 
136
- expect(handleClick).toBeCalled();
136
+ expect(handleClick).toHaveBeenCalled();
137
137
 
138
- jest.runOnlyPendingTimers();
138
+ jest.runOnlyPendingTimers();
139
139
  });
140
140
 
141
- test('Prompt tests with form submit', async () => {
142
- // Click
143
- const handleClick = jest.fn((result: boolean) => {
144
- expect(result).toBeTruthy();
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
- act(() => {
148
- // Add the notification
149
- notifier.prompt<boolean>('Prompt message', handleClick, undefined, {
150
- type: 'switch',
151
- inputProps: { required: false }
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
- await act(async () => {
156
- (
157
- root
158
- .getElementsByTagName('form')[0]
159
- .elements.namedItem('okButton') as HTMLButtonElement
160
- )?.click();
161
- });
155
+ await act(async () => {
156
+ (
157
+ root
158
+ .getElementsByTagName("form")[0]
159
+ .elements.namedItem("okButton") as HTMLButtonElement
160
+ )?.click();
161
+ });
162
162
 
163
- expect(handleClick).toBeCalled();
163
+ expect(handleClick).toHaveBeenCalled();
164
164
 
165
- jest.runOnlyPendingTimers();
165
+ jest.runOnlyPendingTimers();
166
166
  });
167
167
 
168
- test('Message tests', (done) => {
169
- // Callback
170
- const callback = jest.fn(() => done());
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
- expect(n?.timespan).toBe(5);
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
- expect(root.innerHTML).toContain('Error Message');
185
+ expect(n?.timespan).toBe(5);
188
186
 
189
- act(() => {
190
- // Here is the bug need further study...
191
- n?.dismiss();
187
+ expect(root.innerHTML).toContain("Error Message");
192
188
 
193
- // Fast forward
194
- jest.runOnlyPendingTimers();
195
- });
189
+ act(() => {
190
+ // Here is the bug need further study...
191
+ n?.dismiss();
196
192
 
197
- expect(root.innerHTML).not.toContain('Error Message');
198
- expect(callback).toBeCalled();
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('Loading tests', () => {
202
- act(() => {
203
- // Add the notification
204
- notifier.showLoading('Loading');
205
- });
201
+ test("Loading tests", () => {
202
+ act(() => {
203
+ // Add the notification
204
+ notifier.showLoading("Loading");
205
+ });
206
206
 
207
- expect(root.innerHTML).toContain('Loading');
207
+ expect(root.innerHTML).toContain("Loading");
208
208
 
209
- act(() => {
210
- notifier.hideLoading();
209
+ act(() => {
210
+ notifier.hideLoading();
211
211
 
212
- // Fast forward
213
- jest.runOnlyPendingTimers();
214
- });
212
+ // Fast forward
213
+ jest.runOnlyPendingTimers();
214
+ });
215
215
 
216
- expect(root.innerHTML).not.toContain('Loading');
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
+ });
@@ -31,7 +31,7 @@ it("Render SelectEx", async () => {
31
31
  />
32
32
  );
33
33
 
34
- expect(itemChangeCallback).toBeCalled();
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).toBeCalledTimes(2);
113
+ expect(itemChangeCallback).toHaveBeenCalledTimes(2);
114
114
  });
@@ -1,23 +1,23 @@
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';
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('SwitchAnt Tests', () => {
7
- const onChange = jest.fn((event: React.ChangeEvent<HTMLInputElement>) =>
8
- expect(event.target.checked).toBeTruthy()
9
- );
6
+ it("SwitchAnt Tests", () => {
7
+ const onChange = jest.fn((event: React.ChangeEvent<HTMLInputElement>) =>
8
+ expect(event.target.checked).toBeTruthy()
9
+ );
10
10
 
11
- // Render component
12
- const { baseElement } = render(
13
- <SwitchAnt startLabel="No" endLabel="Yes" onChange={onChange} />
14
- );
11
+ // Render component
12
+ const { baseElement } = render(
13
+ <SwitchAnt startLabel="No" endLabel="Yes" onChange={onChange} />
14
+ );
15
15
 
16
- const yes = getByText(baseElement, 'Yes');
16
+ const yes = getByText(baseElement, "Yes");
17
17
 
18
- act(() => {
19
- yes.click();
20
- });
18
+ act(() => {
19
+ yes.click();
20
+ });
21
21
 
22
- expect(onChange).toBeCalled();
22
+ expect(onChange).toHaveBeenCalled();
23
23
  });
package/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.3.43",
3
+ "version": "1.3.45",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
- "type": "module",
7
6
  "types": "lib/index.d.ts",
8
7
  "scripts": {
9
8
  "build": "tsc",
@@ -51,10 +50,10 @@
51
50
  "@emotion/css": "^11.11.2",
52
51
  "@emotion/react": "^11.11.4",
53
52
  "@emotion/styled": "^11.11.0",
54
- "@etsoo/appscript": "^1.4.79",
55
- "@etsoo/notificationbase": "^1.1.40",
56
- "@etsoo/react": "^1.7.31",
57
- "@etsoo/shared": "^1.2.31",
53
+ "@etsoo/appscript": "^1.4.80",
54
+ "@etsoo/notificationbase": "^1.1.41",
55
+ "@etsoo/react": "^1.7.32",
56
+ "@etsoo/shared": "^1.2.33",
58
57
  "@mui/icons-material": "^5.15.11",
59
58
  "@mui/material": "^5.15.11",
60
59
  "@mui/x-data-grid": "^6.19.6",
@@ -83,13 +82,13 @@
83
82
  "@types/jest": "^29.5.12",
84
83
  "@types/pica": "^9.0.4",
85
84
  "@types/pulltorefreshjs": "^0.1.7",
86
- "@types/react": "^18.2.61",
85
+ "@types/react": "^18.2.62",
87
86
  "@types/react-avatar-editor": "^13.0.2",
88
87
  "@types/react-dom": "^18.2.19",
89
88
  "@types/react-input-mask": "^3.0.5",
90
89
  "@types/react-window": "^1.8.8",
91
- "@typescript-eslint/eslint-plugin": "^7.1.0",
92
- "@typescript-eslint/parser": "^7.1.0",
90
+ "@typescript-eslint/eslint-plugin": "^7.1.1",
91
+ "@typescript-eslint/parser": "^7.1.1",
93
92
  "jest": "^29.7.0",
94
93
  "jest-environment-jsdom": "^29.7.0",
95
94
  "typescript": "^5.3.3"
@@ -1,5 +1,5 @@
1
1
  import { GridMethodRef } from "@etsoo/react";
2
- import { DataTypes, IdDefaultType } from "@etsoo/shared";
2
+ import { DataTypes } from "@etsoo/shared";
3
3
  import { ListChildComponentProps } from "react-window";
4
4
  import {
5
5
  ScrollerListExInnerItemRendererProps,