@etsoo/materialui 1.4.25 → 1.4.27

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,6 +1,6 @@
1
1
  import React from "react";
2
2
  import { ComboBox } from "../src";
3
- import { fireEvent, render, screen } from "@testing-library/react";
3
+ import { act, fireEvent, render, screen } from "@testing-library/react";
4
4
 
5
5
  it("Render ComboBox", async () => {
6
6
  // Arrange
@@ -10,13 +10,22 @@ it("Render ComboBox", async () => {
10
10
  { id: 2, name: "Name 2" }
11
11
  ];
12
12
 
13
- render(
14
- <ComboBox<T> name="Test" options={options} labelField="name" label="Test" />
15
- );
13
+ act(() => {
14
+ render(
15
+ <ComboBox<T>
16
+ name="Test"
17
+ options={options}
18
+ labelField="name"
19
+ label="Test"
20
+ />
21
+ );
22
+ });
16
23
 
17
24
  // Act, click the list
18
- const clicked = fireEvent.click(screen.getByRole("button"));
19
- expect(clicked).toBeTruthy();
25
+ act(() => {
26
+ const clicked = fireEvent.click(screen.getByRole("button"));
27
+ expect(clicked).toBeTruthy();
28
+ });
20
29
 
21
30
  // Get list item
22
31
  const item = screen.getByText("Name 1");
@@ -107,3 +107,20 @@ test("Test for properties", () => {
107
107
 
108
108
  expect(root.innerHTML).toContain(result.title);
109
109
  });
110
+
111
+ test("Test for alertResult", () => {
112
+ const result: IActionResult = {
113
+ ok: false,
114
+ type: "TokenExpired",
115
+ title: "您的令牌已过期",
116
+ data: {}
117
+ };
118
+
119
+ act(() => {
120
+ app.alertResult(result);
121
+ });
122
+
123
+ expect(root.innerHTML).toContain(
124
+ '<span style="font-size: 9px;">(TokenExpired)</span>'
125
+ );
126
+ });
@@ -21,33 +21,38 @@ const fieldTemplate = {
21
21
  } as const;
22
22
 
23
23
  it("Render ResponsePage", async () => {
24
- // Act
25
- render(
26
- <ResponsivePage<Data, typeof fieldTemplate>
27
- fields={[]}
28
- columns={[
29
- { field: "id", header: "ID" },
30
- { field: "name", header: "Name" }
31
- ]}
32
- height={200}
33
- itemSize={[118, MUGlobal.pagePaddings]}
34
- fieldTemplate={fieldTemplate}
35
- loadData={({ id }) =>
36
- Promise.resolve([
37
- { id: 1, name: "Name 1" },
38
- { id: 2, name: "Name 2" },
39
- { id: id ?? 0, name: "auto" }
40
- ])
41
- }
42
- innerItemRenderer={(props) =>
43
- MobileListItemRenderer(props, (data) => {
44
- return [data.name, undefined, [], <React.Fragment></React.Fragment>];
45
- })
46
- }
47
- />
48
- );
49
-
50
24
  act(() => {
25
+ // Act
26
+ render(
27
+ <ResponsivePage<Data, typeof fieldTemplate>
28
+ fields={[]}
29
+ columns={[
30
+ { field: "id", header: "ID" },
31
+ { field: "name", header: "Name" }
32
+ ]}
33
+ height={200}
34
+ itemSize={[118, MUGlobal.pagePaddings]}
35
+ fieldTemplate={fieldTemplate}
36
+ loadData={({ id }) =>
37
+ Promise.resolve([
38
+ { id: 1, name: "Name 1" },
39
+ { id: 2, name: "Name 2" },
40
+ { id: id ?? 0, name: "auto" }
41
+ ])
42
+ }
43
+ innerItemRenderer={(props) =>
44
+ MobileListItemRenderer(props, (data) => {
45
+ return [
46
+ data.name,
47
+ undefined,
48
+ [],
49
+ <React.Fragment></React.Fragment>
50
+ ];
51
+ })
52
+ }
53
+ />
54
+ );
55
+
51
56
  // Fast forward
52
57
  vi.runOnlyPendingTimers();
53
58
  });
@@ -1,6 +1,6 @@
1
1
  import React, { act } from "react";
2
2
  import { SelectEx } from "../src";
3
- import { findByText, fireEvent, render, screen } from "@testing-library/react";
3
+ import { fireEvent, render, screen } from "@testing-library/react";
4
4
  import { ListType1, Utils } from "@etsoo/shared";
5
5
 
6
6
  it("Render SelectEx", async () => {
@@ -19,16 +19,18 @@ it("Render SelectEx", async () => {
19
19
  });
20
20
 
21
21
  // Render component
22
- const { findByText } = render(
23
- <SelectEx<T>
24
- options={options}
25
- name="test"
26
- onItemChange={itemChangeCallback}
27
- value={1}
28
- search
29
- labelField="name"
30
- />
31
- );
22
+ act(() => {
23
+ render(
24
+ <SelectEx<T>
25
+ options={options}
26
+ name="test"
27
+ onItemChange={itemChangeCallback}
28
+ value={1}
29
+ search
30
+ labelField="name"
31
+ />
32
+ );
33
+ });
32
34
 
33
35
  expect(itemChangeCallback).toHaveBeenCalled();
34
36
 
@@ -45,10 +47,10 @@ it("Render SelectEx", async () => {
45
47
  });
46
48
 
47
49
  // Get list item
48
- const itemName2 = await findByText("Name 2");
50
+ const itemName2 = await screen.findByText("Name 2");
49
51
  expect(itemName2.nodeName).toBe("SPAN");
50
52
 
51
- const itemBlank = await findByText("---");
53
+ const itemBlank = await screen.findByText("---");
52
54
  expect(itemBlank.nodeName).toBe("SPAN");
53
55
 
54
56
  act(() => {
@@ -90,12 +92,12 @@ it("Render multiple SelectEx", async () => {
90
92
  fireEvent.mouseDown(button); // Not click
91
93
 
92
94
  // Get list item
93
- const itemName1 = await findByText(baseElement, "Name 1");
95
+ const itemName1 = await screen.findByText("Name 1");
94
96
  const checkbox1 = itemName1.closest("li")?.querySelector("input");
95
97
 
96
98
  expect(checkbox1?.checked).toBeTruthy();
97
99
 
98
- const itemName3 = await findByText(baseElement, "Name 3");
100
+ const itemName3 = await screen.findByText("Name 3");
99
101
  expect(itemName3.nodeName).toBe("SPAN");
100
102
 
101
103
  // Checkbox
@@ -1,4 +1,4 @@
1
- import { getByText, render } from "@testing-library/react";
1
+ import { screen, render } from "@testing-library/react";
2
2
  import React, { act } from "react";
3
3
  import { SwitchAnt } from "../src/SwitchAnt";
4
4
 
@@ -8,11 +8,11 @@ it("SwitchAnt Tests", () => {
8
8
  );
9
9
 
10
10
  // Render component
11
- const { baseElement } = render(
12
- <SwitchAnt startLabel="No" endLabel="Yes" onChange={onChange} />
13
- );
11
+ act(() => {
12
+ render(<SwitchAnt startLabel="No" endLabel="Yes" onChange={onChange} />);
13
+ });
14
14
 
15
- const yes = getByText(baseElement, "Yes");
15
+ const yes = screen.getByText("Yes");
16
16
 
17
17
  act(() => {
18
18
  yes.click();
@@ -32,8 +32,9 @@ export declare class ServiceApp<U extends IServiceUser = IServiceUser, P extends
32
32
  constructor(settings: S, name: string, debug?: boolean);
33
33
  /**
34
34
  * Load core system UI
35
+ * @param tryLogin Try login or not
35
36
  */
36
- loadCore(): void;
37
+ loadCore(tryLogin?: boolean): void;
37
38
  /**
38
39
  * Go to the login page
39
40
  * @param data Login parameters
@@ -2,6 +2,7 @@ import { AuthApi, BridgeUtils } from "@etsoo/appscript";
2
2
  import { ReactApp } from "./ReactApp";
3
3
  const coreName = "core";
4
4
  const coreTokenKey = "core-refresh-token";
5
+ const tryLoginKey = "tryLogin";
5
6
  /**
6
7
  * Core Service App
7
8
  * Service login to core system, get the refesh token and access token
@@ -39,13 +40,20 @@ export class ServiceApp extends ReactApp {
39
40
  }
40
41
  /**
41
42
  * Load core system UI
43
+ * @param tryLogin Try login or not
42
44
  */
43
- loadCore() {
45
+ loadCore(tryLogin = false) {
44
46
  if (BridgeUtils.host == null) {
45
- globalThis.location.href = this.coreEndpoint.webUrl;
47
+ let url = this.coreEndpoint.webUrl;
48
+ if (!tryLogin)
49
+ url = url.addUrlParam(tryLoginKey, tryLogin);
50
+ globalThis.location.href = url;
46
51
  }
47
52
  else {
48
- BridgeUtils.host.loadApp(coreName);
53
+ const startUrl = tryLogin
54
+ ? undefined
55
+ : "".addUrlParam(tryLoginKey, tryLogin);
56
+ BridgeUtils.host.loadApp(coreName, startUrl);
49
57
  }
50
58
  }
51
59
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.4.25",
3
+ "version": "1.4.27",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
@@ -35,9 +35,9 @@
35
35
  "@emotion/css": "^11.13.5",
36
36
  "@emotion/react": "^11.13.5",
37
37
  "@emotion/styled": "^11.13.5",
38
- "@etsoo/appscript": "^1.5.67",
38
+ "@etsoo/appscript": "^1.5.69",
39
39
  "@etsoo/notificationbase": "^1.1.54",
40
- "@etsoo/react": "^1.8.2",
40
+ "@etsoo/react": "^1.8.3",
41
41
  "@etsoo/shared": "^1.2.55",
42
42
  "@mui/icons-material": "^6.1.8",
43
43
  "@mui/material": "^6.1.8",
@@ -70,9 +70,9 @@
70
70
  "@types/react-dom": "^18.3.1",
71
71
  "@types/react-input-mask": "^3.0.6",
72
72
  "@types/react-window": "^1.8.8",
73
- "@vitejs/plugin-react": "^4.3.3",
73
+ "@vitejs/plugin-react": "^4.3.4",
74
74
  "jsdom": "^25.0.1",
75
75
  "typescript": "^5.7.2",
76
- "vitest": "^2.1.5"
76
+ "vitest": "^2.1.6"
77
77
  }
78
78
  }
@@ -15,6 +15,7 @@ import { ReactApp } from "./ReactApp";
15
15
 
16
16
  const coreName = "core";
17
17
  const coreTokenKey = "core-refresh-token";
18
+ const tryLoginKey = "tryLogin";
18
19
 
19
20
  /**
20
21
  * Core Service App
@@ -65,12 +66,18 @@ export class ServiceApp<
65
66
 
66
67
  /**
67
68
  * Load core system UI
69
+ * @param tryLogin Try login or not
68
70
  */
69
- loadCore() {
71
+ loadCore(tryLogin: boolean = false) {
70
72
  if (BridgeUtils.host == null) {
71
- globalThis.location.href = this.coreEndpoint.webUrl;
73
+ let url = this.coreEndpoint.webUrl;
74
+ if (!tryLogin) url = url.addUrlParam(tryLoginKey, tryLogin);
75
+ globalThis.location.href = url;
72
76
  } else {
73
- BridgeUtils.host.loadApp(coreName);
77
+ const startUrl = tryLogin
78
+ ? undefined
79
+ : "".addUrlParam(tryLoginKey, tryLogin);
80
+ BridgeUtils.host.loadApp(coreName, startUrl);
74
81
  }
75
82
  }
76
83