@nocobase/test 1.0.0-alpha.3 → 1.0.0-alpha.4
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/es/client/index.mjs +160 -13
- package/es/web/index.d.ts +3 -2
- package/es/web/index.mjs +158 -11
- package/lib/client/utils/utils.js +2 -2
- package/lib/web/dataSourceMainData.json +101 -0
- package/lib/web/index.d.ts +3 -2
- package/lib/web/index.js +30 -10
- package/package.json +3 -3
package/es/client/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ export * from "@testing-library/react";
|
|
|
3
3
|
import React, { Fragment } from "react";
|
|
4
4
|
import MockAdapter from "axios-mock-adapter";
|
|
5
5
|
import _, { pick, get } from "lodash";
|
|
6
|
-
import { observer, useFieldSchema } from "@formily/react";
|
|
6
|
+
import { observer, useForm, useFieldSchema } from "@formily/react";
|
|
7
7
|
import { Application, AntdSchemaComponentPlugin, SchemaSettingsPlugin, CollectionPlugin, LocalDataSource, SchemaSettings, SchemaComponent, DataBlockProvider } from "@nocobase/client";
|
|
8
8
|
import { expect } from "vitest";
|
|
9
9
|
import userEvent from "@testing-library/user-event";
|
|
@@ -1117,6 +1117,113 @@ const dataSourceMainData = {
|
|
|
1117
1117
|
}
|
|
1118
1118
|
}
|
|
1119
1119
|
},
|
|
1120
|
+
"users:get": {
|
|
1121
|
+
data: {
|
|
1122
|
+
createdAt: "2024-04-07T06:50:37.797Z",
|
|
1123
|
+
updatedAt: "2024-04-07T06:50:37.797Z",
|
|
1124
|
+
appLang: null,
|
|
1125
|
+
createdById: null,
|
|
1126
|
+
email: "admin@nocobase.com",
|
|
1127
|
+
f_1gx8uyn3wva: 1,
|
|
1128
|
+
id: 1,
|
|
1129
|
+
nickname: "Super Admin",
|
|
1130
|
+
phone: null,
|
|
1131
|
+
systemSettings: {},
|
|
1132
|
+
updatedById: null,
|
|
1133
|
+
username: "nocobase",
|
|
1134
|
+
roles: [
|
|
1135
|
+
{
|
|
1136
|
+
createdAt: "2024-04-07T06:50:37.700Z",
|
|
1137
|
+
updatedAt: "2024-04-07T06:50:37.700Z",
|
|
1138
|
+
allowConfigure: null,
|
|
1139
|
+
allowNewMenu: true,
|
|
1140
|
+
"default": true,
|
|
1141
|
+
description: null,
|
|
1142
|
+
hidden: false,
|
|
1143
|
+
color: "#1677FF",
|
|
1144
|
+
name: "member",
|
|
1145
|
+
snippets: [
|
|
1146
|
+
"!pm",
|
|
1147
|
+
"!pm.*",
|
|
1148
|
+
"!ui.*"
|
|
1149
|
+
],
|
|
1150
|
+
strategy: {
|
|
1151
|
+
actions: [
|
|
1152
|
+
"view",
|
|
1153
|
+
"update:own",
|
|
1154
|
+
"destroy:own",
|
|
1155
|
+
"create"
|
|
1156
|
+
]
|
|
1157
|
+
},
|
|
1158
|
+
title: '{{t("Member")}}',
|
|
1159
|
+
rolesUsers: {
|
|
1160
|
+
createdAt: "2024-04-07T06:50:37.854Z",
|
|
1161
|
+
updatedAt: "2024-04-07T06:50:37.854Z",
|
|
1162
|
+
"default": null,
|
|
1163
|
+
roleName: "member",
|
|
1164
|
+
userId: 1
|
|
1165
|
+
}
|
|
1166
|
+
},
|
|
1167
|
+
{
|
|
1168
|
+
createdAt: "2024-04-07T06:50:37.622Z",
|
|
1169
|
+
updatedAt: "2024-04-07T06:50:37.622Z",
|
|
1170
|
+
allowConfigure: null,
|
|
1171
|
+
allowNewMenu: null,
|
|
1172
|
+
"default": false,
|
|
1173
|
+
description: null,
|
|
1174
|
+
hidden: true,
|
|
1175
|
+
color: "#1677FF",
|
|
1176
|
+
name: "root",
|
|
1177
|
+
snippets: [
|
|
1178
|
+
"pm",
|
|
1179
|
+
"pm.*",
|
|
1180
|
+
"ui.*"
|
|
1181
|
+
],
|
|
1182
|
+
strategy: null,
|
|
1183
|
+
title: '{{t("Root")}}',
|
|
1184
|
+
rolesUsers: {
|
|
1185
|
+
createdAt: "2024-04-07T06:50:38.152Z",
|
|
1186
|
+
updatedAt: "2024-04-07T06:50:38.186Z",
|
|
1187
|
+
"default": true,
|
|
1188
|
+
roleName: "root",
|
|
1189
|
+
userId: 1
|
|
1190
|
+
}
|
|
1191
|
+
},
|
|
1192
|
+
{
|
|
1193
|
+
createdAt: "2024-04-07T06:50:37.657Z",
|
|
1194
|
+
updatedAt: "2024-04-07T06:50:37.657Z",
|
|
1195
|
+
allowConfigure: true,
|
|
1196
|
+
allowNewMenu: true,
|
|
1197
|
+
"default": false,
|
|
1198
|
+
description: null,
|
|
1199
|
+
hidden: false,
|
|
1200
|
+
name: "admin",
|
|
1201
|
+
color: "#1677FF",
|
|
1202
|
+
snippets: [
|
|
1203
|
+
"pm",
|
|
1204
|
+
"pm.*",
|
|
1205
|
+
"ui.*"
|
|
1206
|
+
],
|
|
1207
|
+
strategy: {
|
|
1208
|
+
actions: [
|
|
1209
|
+
"create",
|
|
1210
|
+
"view",
|
|
1211
|
+
"update",
|
|
1212
|
+
"destroy"
|
|
1213
|
+
]
|
|
1214
|
+
},
|
|
1215
|
+
title: '{{t("Admin")}}',
|
|
1216
|
+
rolesUsers: {
|
|
1217
|
+
createdAt: "2024-04-07T06:50:38.152Z",
|
|
1218
|
+
updatedAt: "2024-04-07T06:50:38.152Z",
|
|
1219
|
+
"default": null,
|
|
1220
|
+
roleName: "admin",
|
|
1221
|
+
userId: 1
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
]
|
|
1225
|
+
}
|
|
1226
|
+
},
|
|
1120
1227
|
"roles:list": {
|
|
1121
1228
|
data: [
|
|
1122
1229
|
{
|
|
@@ -1208,6 +1315,26 @@ const dataSourceMainData = {
|
|
|
1208
1315
|
}
|
|
1209
1316
|
}
|
|
1210
1317
|
},
|
|
1318
|
+
"roles:get": {
|
|
1319
|
+
data: {
|
|
1320
|
+
createdAt: "2024-04-07T06:50:37.622Z",
|
|
1321
|
+
updatedAt: "2024-04-07T06:50:37.622Z",
|
|
1322
|
+
allowConfigure: null,
|
|
1323
|
+
allowNewMenu: null,
|
|
1324
|
+
"default": false,
|
|
1325
|
+
description: null,
|
|
1326
|
+
hidden: true,
|
|
1327
|
+
name: "root",
|
|
1328
|
+
color: "#1677FF",
|
|
1329
|
+
snippets: [
|
|
1330
|
+
"pm",
|
|
1331
|
+
"pm.*",
|
|
1332
|
+
"ui.*"
|
|
1333
|
+
],
|
|
1334
|
+
strategy: null,
|
|
1335
|
+
title: '{{t("Root")}}'
|
|
1336
|
+
}
|
|
1337
|
+
},
|
|
1211
1338
|
"tree:list": {
|
|
1212
1339
|
data: [
|
|
1213
1340
|
{
|
|
@@ -1250,7 +1377,10 @@ const sleep = async (timeout = 0) => {
|
|
|
1250
1377
|
};
|
|
1251
1378
|
const defaultApis = {
|
|
1252
1379
|
"uiSchemas:patch": { data: { result: "ok" } },
|
|
1380
|
+
"uiSchemas:batchPatch": { data: { result: "ok" } },
|
|
1253
1381
|
"uiSchemas:saveAsTemplate": { data: { result: "ok" } },
|
|
1382
|
+
"users:update": { data: { result: "ok" } },
|
|
1383
|
+
"roles:update": { data: { result: "ok" } },
|
|
1254
1384
|
...dataSourceMainData
|
|
1255
1385
|
};
|
|
1256
1386
|
function getProcessMockData(apis, key2) {
|
|
@@ -1260,15 +1390,27 @@ function getProcessMockData(apis, key2) {
|
|
|
1260
1390
|
return [404, { data: { message: "mock data not found" } }];
|
|
1261
1391
|
if (((_a = config == null ? void 0 : config.params) == null ? void 0 : _a.pageSize) || ((_b = config == null ? void 0 : config.params) == null ? void 0 : _b.page)) {
|
|
1262
1392
|
const { data, meta } = apis[key2];
|
|
1263
|
-
const pageSize = config.params.pageSize || (meta == null ? void 0 : meta.pageSize);
|
|
1264
|
-
const page = config.params.page || (meta == null ? void 0 : meta.page);
|
|
1265
|
-
return [
|
|
1393
|
+
const pageSize = config.params.pageSize || (meta == null ? void 0 : meta.pageSize) || 20;
|
|
1394
|
+
const page = config.params.page || (meta == null ? void 0 : meta.page) || 1;
|
|
1395
|
+
return [
|
|
1396
|
+
200,
|
|
1397
|
+
{
|
|
1398
|
+
data: data.slice(pageSize * (page - 1), pageSize * page),
|
|
1399
|
+
meta: {
|
|
1400
|
+
...meta,
|
|
1401
|
+
page,
|
|
1402
|
+
pageSize,
|
|
1403
|
+
count: data.length,
|
|
1404
|
+
totalPage: Math.ceil(data.length / pageSize)
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
];
|
|
1266
1408
|
}
|
|
1267
1409
|
return [200, apis[key2]];
|
|
1268
1410
|
};
|
|
1269
1411
|
}
|
|
1270
|
-
const mockApi = (axiosInstance, apis = {}) => {
|
|
1271
|
-
const mock = new MockAdapter(axiosInstance);
|
|
1412
|
+
const mockApi = (axiosInstance, apis = {}, delayResponse) => {
|
|
1413
|
+
const mock = new MockAdapter(axiosInstance, { delayResponse });
|
|
1272
1414
|
Object.keys(apis).forEach((key2) => {
|
|
1273
1415
|
mock.onAny(key2).reply(getProcessMockData(apis, key2));
|
|
1274
1416
|
});
|
|
@@ -1278,10 +1420,14 @@ const mockApi = (axiosInstance, apis = {}) => {
|
|
|
1278
1420
|
});
|
|
1279
1421
|
};
|
|
1280
1422
|
};
|
|
1281
|
-
const mockAppApi = (app, apis = {}) => {
|
|
1282
|
-
const mock = mockApi(app.apiClient.axios, apis);
|
|
1423
|
+
const mockAppApi = (app, apis = {}, delayResponse) => {
|
|
1424
|
+
const mock = mockApi(app.apiClient.axios, apis, delayResponse);
|
|
1283
1425
|
return mock;
|
|
1284
1426
|
};
|
|
1427
|
+
const ShowFormData = observer(({ children }) => {
|
|
1428
|
+
const form = useForm();
|
|
1429
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("pre", { style: { marginBottom: 20 }, "data-testid": "form-data" }, JSON.stringify(form.values, null, 2)), children);
|
|
1430
|
+
});
|
|
1285
1431
|
const getApp = (options) => {
|
|
1286
1432
|
const {
|
|
1287
1433
|
appOptions = {},
|
|
@@ -1290,7 +1436,8 @@ const getApp = (options) => {
|
|
|
1290
1436
|
disableAcl = true,
|
|
1291
1437
|
apis: optionsApis = {},
|
|
1292
1438
|
enableMultipleDataSource,
|
|
1293
|
-
designable
|
|
1439
|
+
designable,
|
|
1440
|
+
delayResponse
|
|
1294
1441
|
} = options;
|
|
1295
1442
|
const app = appOptions instanceof Application ? appOptions : new Application({
|
|
1296
1443
|
...appOptions,
|
|
@@ -1303,7 +1450,7 @@ const getApp = (options) => {
|
|
|
1303
1450
|
if (schemaSettings) {
|
|
1304
1451
|
app.schemaSettingsManager.add(schemaSettings);
|
|
1305
1452
|
}
|
|
1306
|
-
app.addComponents({ CommonSchemaComponent });
|
|
1453
|
+
app.addComponents({ CommonSchemaComponent, ShowFormData });
|
|
1307
1454
|
app.pluginManager.add(AntdSchemaComponentPlugin);
|
|
1308
1455
|
app.pluginManager.add(SchemaSettingsPlugin);
|
|
1309
1456
|
app.pluginManager.add(CollectionPlugin, { config: { enableRemoteDataSource: false } });
|
|
@@ -1312,7 +1459,7 @@ const getApp = (options) => {
|
|
|
1312
1459
|
if (enableMultipleDataSource) {
|
|
1313
1460
|
app.dataSourceManager.addDataSource(LocalDataSource, dataSource2);
|
|
1314
1461
|
}
|
|
1315
|
-
mockAppApi(app, apis);
|
|
1462
|
+
mockAppApi(app, apis, delayResponse);
|
|
1316
1463
|
const App = app.getRootComponent();
|
|
1317
1464
|
return {
|
|
1318
1465
|
App,
|
|
@@ -1432,9 +1579,9 @@ const WaitApp = async () => {
|
|
|
1432
1579
|
await waitFor(() => {
|
|
1433
1580
|
expectNoTsError(screen.queryByText("Loading...")).not.toBeInTheDocument();
|
|
1434
1581
|
});
|
|
1435
|
-
const loadError = screen.queryByText("
|
|
1582
|
+
const loadError = screen.queryByText("App Error");
|
|
1436
1583
|
if (loadError) {
|
|
1437
|
-
expectNoTsError(screen.queryByText("
|
|
1584
|
+
expectNoTsError(screen.queryByText("App Error")).not.toBeInTheDocument();
|
|
1438
1585
|
}
|
|
1439
1586
|
const renderError = screen.queryByText("Render Failed");
|
|
1440
1587
|
if (renderError) {
|
package/es/web/index.d.ts
CHANGED
|
@@ -14,12 +14,13 @@ type URL = string;
|
|
|
14
14
|
type ResponseData = any;
|
|
15
15
|
type MockApis = Record<URL, ResponseData>;
|
|
16
16
|
type AppOrOptions = Application | ApplicationOptions;
|
|
17
|
-
export declare const mockApi: (axiosInstance: AxiosInstance, apis?: MockApis) => (apis?: MockApis) => void;
|
|
18
|
-
export declare const mockAppApi: (app: Application, apis?: MockApis) => (apis?: MockApis) => void;
|
|
17
|
+
export declare const mockApi: (axiosInstance: AxiosInstance, apis?: MockApis, delayResponse?: number) => (apis?: MockApis) => void;
|
|
18
|
+
export declare const mockAppApi: (app: Application, apis?: MockApis, delayResponse?: number) => (apis?: MockApis) => void;
|
|
19
19
|
export interface GetAppOptions {
|
|
20
20
|
appOptions?: AppOrOptions;
|
|
21
21
|
providers?: (ComponentType | [ComponentType, any])[];
|
|
22
22
|
apis?: MockApis;
|
|
23
|
+
delayResponse?: number;
|
|
23
24
|
designable?: boolean;
|
|
24
25
|
schemaSettings?: SchemaSettings;
|
|
25
26
|
disableAcl?: boolean;
|
package/es/web/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import MockAdapter from "axios-mock-adapter";
|
|
3
3
|
import _, { get, set, pick } from "lodash";
|
|
4
|
-
import { observer, useFieldSchema } from "@formily/react";
|
|
4
|
+
import { observer, useForm, useFieldSchema } from "@formily/react";
|
|
5
5
|
import { Application, AntdSchemaComponentPlugin, SchemaSettingsPlugin, CollectionPlugin, LocalDataSource, SchemaSettings, SchemaComponent, DataBlockProvider } from "@nocobase/client";
|
|
6
6
|
const dataSourceMainCollections = [
|
|
7
7
|
{
|
|
@@ -1110,6 +1110,113 @@ const dataSourceMainData = {
|
|
|
1110
1110
|
}
|
|
1111
1111
|
}
|
|
1112
1112
|
},
|
|
1113
|
+
"users:get": {
|
|
1114
|
+
data: {
|
|
1115
|
+
createdAt: "2024-04-07T06:50:37.797Z",
|
|
1116
|
+
updatedAt: "2024-04-07T06:50:37.797Z",
|
|
1117
|
+
appLang: null,
|
|
1118
|
+
createdById: null,
|
|
1119
|
+
email: "admin@nocobase.com",
|
|
1120
|
+
f_1gx8uyn3wva: 1,
|
|
1121
|
+
id: 1,
|
|
1122
|
+
nickname: "Super Admin",
|
|
1123
|
+
phone: null,
|
|
1124
|
+
systemSettings: {},
|
|
1125
|
+
updatedById: null,
|
|
1126
|
+
username: "nocobase",
|
|
1127
|
+
roles: [
|
|
1128
|
+
{
|
|
1129
|
+
createdAt: "2024-04-07T06:50:37.700Z",
|
|
1130
|
+
updatedAt: "2024-04-07T06:50:37.700Z",
|
|
1131
|
+
allowConfigure: null,
|
|
1132
|
+
allowNewMenu: true,
|
|
1133
|
+
"default": true,
|
|
1134
|
+
description: null,
|
|
1135
|
+
hidden: false,
|
|
1136
|
+
color: "#1677FF",
|
|
1137
|
+
name: "member",
|
|
1138
|
+
snippets: [
|
|
1139
|
+
"!pm",
|
|
1140
|
+
"!pm.*",
|
|
1141
|
+
"!ui.*"
|
|
1142
|
+
],
|
|
1143
|
+
strategy: {
|
|
1144
|
+
actions: [
|
|
1145
|
+
"view",
|
|
1146
|
+
"update:own",
|
|
1147
|
+
"destroy:own",
|
|
1148
|
+
"create"
|
|
1149
|
+
]
|
|
1150
|
+
},
|
|
1151
|
+
title: '{{t("Member")}}',
|
|
1152
|
+
rolesUsers: {
|
|
1153
|
+
createdAt: "2024-04-07T06:50:37.854Z",
|
|
1154
|
+
updatedAt: "2024-04-07T06:50:37.854Z",
|
|
1155
|
+
"default": null,
|
|
1156
|
+
roleName: "member",
|
|
1157
|
+
userId: 1
|
|
1158
|
+
}
|
|
1159
|
+
},
|
|
1160
|
+
{
|
|
1161
|
+
createdAt: "2024-04-07T06:50:37.622Z",
|
|
1162
|
+
updatedAt: "2024-04-07T06:50:37.622Z",
|
|
1163
|
+
allowConfigure: null,
|
|
1164
|
+
allowNewMenu: null,
|
|
1165
|
+
"default": false,
|
|
1166
|
+
description: null,
|
|
1167
|
+
hidden: true,
|
|
1168
|
+
color: "#1677FF",
|
|
1169
|
+
name: "root",
|
|
1170
|
+
snippets: [
|
|
1171
|
+
"pm",
|
|
1172
|
+
"pm.*",
|
|
1173
|
+
"ui.*"
|
|
1174
|
+
],
|
|
1175
|
+
strategy: null,
|
|
1176
|
+
title: '{{t("Root")}}',
|
|
1177
|
+
rolesUsers: {
|
|
1178
|
+
createdAt: "2024-04-07T06:50:38.152Z",
|
|
1179
|
+
updatedAt: "2024-04-07T06:50:38.186Z",
|
|
1180
|
+
"default": true,
|
|
1181
|
+
roleName: "root",
|
|
1182
|
+
userId: 1
|
|
1183
|
+
}
|
|
1184
|
+
},
|
|
1185
|
+
{
|
|
1186
|
+
createdAt: "2024-04-07T06:50:37.657Z",
|
|
1187
|
+
updatedAt: "2024-04-07T06:50:37.657Z",
|
|
1188
|
+
allowConfigure: true,
|
|
1189
|
+
allowNewMenu: true,
|
|
1190
|
+
"default": false,
|
|
1191
|
+
description: null,
|
|
1192
|
+
hidden: false,
|
|
1193
|
+
name: "admin",
|
|
1194
|
+
color: "#1677FF",
|
|
1195
|
+
snippets: [
|
|
1196
|
+
"pm",
|
|
1197
|
+
"pm.*",
|
|
1198
|
+
"ui.*"
|
|
1199
|
+
],
|
|
1200
|
+
strategy: {
|
|
1201
|
+
actions: [
|
|
1202
|
+
"create",
|
|
1203
|
+
"view",
|
|
1204
|
+
"update",
|
|
1205
|
+
"destroy"
|
|
1206
|
+
]
|
|
1207
|
+
},
|
|
1208
|
+
title: '{{t("Admin")}}',
|
|
1209
|
+
rolesUsers: {
|
|
1210
|
+
createdAt: "2024-04-07T06:50:38.152Z",
|
|
1211
|
+
updatedAt: "2024-04-07T06:50:38.152Z",
|
|
1212
|
+
"default": null,
|
|
1213
|
+
roleName: "admin",
|
|
1214
|
+
userId: 1
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
]
|
|
1218
|
+
}
|
|
1219
|
+
},
|
|
1113
1220
|
"roles:list": {
|
|
1114
1221
|
data: [
|
|
1115
1222
|
{
|
|
@@ -1201,6 +1308,26 @@ const dataSourceMainData = {
|
|
|
1201
1308
|
}
|
|
1202
1309
|
}
|
|
1203
1310
|
},
|
|
1311
|
+
"roles:get": {
|
|
1312
|
+
data: {
|
|
1313
|
+
createdAt: "2024-04-07T06:50:37.622Z",
|
|
1314
|
+
updatedAt: "2024-04-07T06:50:37.622Z",
|
|
1315
|
+
allowConfigure: null,
|
|
1316
|
+
allowNewMenu: null,
|
|
1317
|
+
"default": false,
|
|
1318
|
+
description: null,
|
|
1319
|
+
hidden: true,
|
|
1320
|
+
name: "root",
|
|
1321
|
+
color: "#1677FF",
|
|
1322
|
+
snippets: [
|
|
1323
|
+
"pm",
|
|
1324
|
+
"pm.*",
|
|
1325
|
+
"ui.*"
|
|
1326
|
+
],
|
|
1327
|
+
strategy: null,
|
|
1328
|
+
title: '{{t("Root")}}'
|
|
1329
|
+
}
|
|
1330
|
+
},
|
|
1204
1331
|
"tree:list": {
|
|
1205
1332
|
data: [
|
|
1206
1333
|
{
|
|
@@ -1243,7 +1370,10 @@ const sleep = async (timeout = 0) => {
|
|
|
1243
1370
|
};
|
|
1244
1371
|
const defaultApis = {
|
|
1245
1372
|
"uiSchemas:patch": { data: { result: "ok" } },
|
|
1373
|
+
"uiSchemas:batchPatch": { data: { result: "ok" } },
|
|
1246
1374
|
"uiSchemas:saveAsTemplate": { data: { result: "ok" } },
|
|
1375
|
+
"users:update": { data: { result: "ok" } },
|
|
1376
|
+
"roles:update": { data: { result: "ok" } },
|
|
1247
1377
|
...dataSourceMainData
|
|
1248
1378
|
};
|
|
1249
1379
|
function getProcessMockData(apis, key2) {
|
|
@@ -1253,15 +1383,27 @@ function getProcessMockData(apis, key2) {
|
|
|
1253
1383
|
return [404, { data: { message: "mock data not found" } }];
|
|
1254
1384
|
if (((_a = config == null ? void 0 : config.params) == null ? void 0 : _a.pageSize) || ((_b = config == null ? void 0 : config.params) == null ? void 0 : _b.page)) {
|
|
1255
1385
|
const { data, meta } = apis[key2];
|
|
1256
|
-
const pageSize = config.params.pageSize || (meta == null ? void 0 : meta.pageSize);
|
|
1257
|
-
const page = config.params.page || (meta == null ? void 0 : meta.page);
|
|
1258
|
-
return [
|
|
1386
|
+
const pageSize = config.params.pageSize || (meta == null ? void 0 : meta.pageSize) || 20;
|
|
1387
|
+
const page = config.params.page || (meta == null ? void 0 : meta.page) || 1;
|
|
1388
|
+
return [
|
|
1389
|
+
200,
|
|
1390
|
+
{
|
|
1391
|
+
data: data.slice(pageSize * (page - 1), pageSize * page),
|
|
1392
|
+
meta: {
|
|
1393
|
+
...meta,
|
|
1394
|
+
page,
|
|
1395
|
+
pageSize,
|
|
1396
|
+
count: data.length,
|
|
1397
|
+
totalPage: Math.ceil(data.length / pageSize)
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
];
|
|
1259
1401
|
}
|
|
1260
1402
|
return [200, apis[key2]];
|
|
1261
1403
|
};
|
|
1262
1404
|
}
|
|
1263
|
-
const mockApi = (axiosInstance, apis = {}) => {
|
|
1264
|
-
const mock = new MockAdapter(axiosInstance);
|
|
1405
|
+
const mockApi = (axiosInstance, apis = {}, delayResponse) => {
|
|
1406
|
+
const mock = new MockAdapter(axiosInstance, { delayResponse });
|
|
1265
1407
|
Object.keys(apis).forEach((key2) => {
|
|
1266
1408
|
mock.onAny(key2).reply(getProcessMockData(apis, key2));
|
|
1267
1409
|
});
|
|
@@ -1271,10 +1413,14 @@ const mockApi = (axiosInstance, apis = {}) => {
|
|
|
1271
1413
|
});
|
|
1272
1414
|
};
|
|
1273
1415
|
};
|
|
1274
|
-
const mockAppApi = (app, apis = {}) => {
|
|
1275
|
-
const mock = mockApi(app.apiClient.axios, apis);
|
|
1416
|
+
const mockAppApi = (app, apis = {}, delayResponse) => {
|
|
1417
|
+
const mock = mockApi(app.apiClient.axios, apis, delayResponse);
|
|
1276
1418
|
return mock;
|
|
1277
1419
|
};
|
|
1420
|
+
const ShowFormData = observer(({ children }) => {
|
|
1421
|
+
const form = useForm();
|
|
1422
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("pre", { style: { marginBottom: 20 }, "data-testid": "form-data" }, JSON.stringify(form.values, null, 2)), children);
|
|
1423
|
+
});
|
|
1278
1424
|
const getApp = (options) => {
|
|
1279
1425
|
const {
|
|
1280
1426
|
appOptions = {},
|
|
@@ -1283,7 +1429,8 @@ const getApp = (options) => {
|
|
|
1283
1429
|
disableAcl = true,
|
|
1284
1430
|
apis: optionsApis = {},
|
|
1285
1431
|
enableMultipleDataSource,
|
|
1286
|
-
designable
|
|
1432
|
+
designable,
|
|
1433
|
+
delayResponse
|
|
1287
1434
|
} = options;
|
|
1288
1435
|
const app = appOptions instanceof Application ? appOptions : new Application({
|
|
1289
1436
|
...appOptions,
|
|
@@ -1296,7 +1443,7 @@ const getApp = (options) => {
|
|
|
1296
1443
|
if (schemaSettings) {
|
|
1297
1444
|
app.schemaSettingsManager.add(schemaSettings);
|
|
1298
1445
|
}
|
|
1299
|
-
app.addComponents({ CommonSchemaComponent });
|
|
1446
|
+
app.addComponents({ CommonSchemaComponent, ShowFormData });
|
|
1300
1447
|
app.pluginManager.add(AntdSchemaComponentPlugin);
|
|
1301
1448
|
app.pluginManager.add(SchemaSettingsPlugin);
|
|
1302
1449
|
app.pluginManager.add(CollectionPlugin, { config: { enableRemoteDataSource: false } });
|
|
@@ -1305,7 +1452,7 @@ const getApp = (options) => {
|
|
|
1305
1452
|
if (enableMultipleDataSource) {
|
|
1306
1453
|
app.dataSourceManager.addDataSource(LocalDataSource, dataSource2);
|
|
1307
1454
|
}
|
|
1308
|
-
mockAppApi(app, apis);
|
|
1455
|
+
mockAppApi(app, apis, delayResponse);
|
|
1309
1456
|
const App = app.getRootComponent();
|
|
1310
1457
|
return {
|
|
1311
1458
|
App,
|
|
@@ -38,9 +38,9 @@ const WaitApp = /* @__PURE__ */ __name(async () => {
|
|
|
38
38
|
await (0, import_react.waitFor)(() => {
|
|
39
39
|
expectNoTsError(import_react.screen.queryByText("Loading...")).not.toBeInTheDocument();
|
|
40
40
|
});
|
|
41
|
-
const loadError = import_react.screen.queryByText("
|
|
41
|
+
const loadError = import_react.screen.queryByText("App Error");
|
|
42
42
|
if (loadError) {
|
|
43
|
-
expectNoTsError(import_react.screen.queryByText("
|
|
43
|
+
expectNoTsError(import_react.screen.queryByText("App Error")).not.toBeInTheDocument();
|
|
44
44
|
}
|
|
45
45
|
const renderError = import_react.screen.queryByText("Render Failed");
|
|
46
46
|
if (renderError) {
|
|
@@ -97,6 +97,91 @@
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
},
|
|
100
|
+
"users:get": {
|
|
101
|
+
"data": {
|
|
102
|
+
"createdAt": "2024-04-07T06:50:37.797Z",
|
|
103
|
+
"updatedAt": "2024-04-07T06:50:37.797Z",
|
|
104
|
+
"appLang": null,
|
|
105
|
+
"createdById": null,
|
|
106
|
+
"email": "admin@nocobase.com",
|
|
107
|
+
"f_1gx8uyn3wva": 1,
|
|
108
|
+
"id": 1,
|
|
109
|
+
"nickname": "Super Admin",
|
|
110
|
+
"phone": null,
|
|
111
|
+
"systemSettings": {},
|
|
112
|
+
"updatedById": null,
|
|
113
|
+
"username": "nocobase",
|
|
114
|
+
"roles": [
|
|
115
|
+
{
|
|
116
|
+
"createdAt": "2024-04-07T06:50:37.700Z",
|
|
117
|
+
"updatedAt": "2024-04-07T06:50:37.700Z",
|
|
118
|
+
"allowConfigure": null,
|
|
119
|
+
"allowNewMenu": true,
|
|
120
|
+
"default": true,
|
|
121
|
+
"description": null,
|
|
122
|
+
"hidden": false,
|
|
123
|
+
"color": "#1677FF",
|
|
124
|
+
"name": "member",
|
|
125
|
+
"snippets": ["!pm", "!pm.*", "!ui.*"],
|
|
126
|
+
"strategy": {
|
|
127
|
+
"actions": ["view", "update:own", "destroy:own", "create"]
|
|
128
|
+
},
|
|
129
|
+
"title": "{{t(\"Member\")}}",
|
|
130
|
+
"rolesUsers": {
|
|
131
|
+
"createdAt": "2024-04-07T06:50:37.854Z",
|
|
132
|
+
"updatedAt": "2024-04-07T06:50:37.854Z",
|
|
133
|
+
"default": null,
|
|
134
|
+
"roleName": "member",
|
|
135
|
+
"userId": 1
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"createdAt": "2024-04-07T06:50:37.622Z",
|
|
140
|
+
"updatedAt": "2024-04-07T06:50:37.622Z",
|
|
141
|
+
"allowConfigure": null,
|
|
142
|
+
"allowNewMenu": null,
|
|
143
|
+
"default": false,
|
|
144
|
+
"description": null,
|
|
145
|
+
"hidden": true,
|
|
146
|
+
"color": "#1677FF",
|
|
147
|
+
"name": "root",
|
|
148
|
+
"snippets": ["pm", "pm.*", "ui.*"],
|
|
149
|
+
"strategy": null,
|
|
150
|
+
"title": "{{t(\"Root\")}}",
|
|
151
|
+
"rolesUsers": {
|
|
152
|
+
"createdAt": "2024-04-07T06:50:38.152Z",
|
|
153
|
+
"updatedAt": "2024-04-07T06:50:38.186Z",
|
|
154
|
+
"default": true,
|
|
155
|
+
"roleName": "root",
|
|
156
|
+
"userId": 1
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
"createdAt": "2024-04-07T06:50:37.657Z",
|
|
161
|
+
"updatedAt": "2024-04-07T06:50:37.657Z",
|
|
162
|
+
"allowConfigure": true,
|
|
163
|
+
"allowNewMenu": true,
|
|
164
|
+
"default": false,
|
|
165
|
+
"description": null,
|
|
166
|
+
"hidden": false,
|
|
167
|
+
"name": "admin",
|
|
168
|
+
"color": "#1677FF",
|
|
169
|
+
"snippets": ["pm", "pm.*", "ui.*"],
|
|
170
|
+
"strategy": {
|
|
171
|
+
"actions": ["create", "view", "update", "destroy"]
|
|
172
|
+
},
|
|
173
|
+
"title": "{{t(\"Admin\")}}",
|
|
174
|
+
"rolesUsers": {
|
|
175
|
+
"createdAt": "2024-04-07T06:50:38.152Z",
|
|
176
|
+
"updatedAt": "2024-04-07T06:50:38.152Z",
|
|
177
|
+
"default": null,
|
|
178
|
+
"roleName": "admin",
|
|
179
|
+
"userId": 1
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
]
|
|
183
|
+
}
|
|
184
|
+
},
|
|
100
185
|
"roles:list": {
|
|
101
186
|
"data": [
|
|
102
187
|
{
|
|
@@ -158,6 +243,22 @@
|
|
|
158
243
|
}
|
|
159
244
|
}
|
|
160
245
|
},
|
|
246
|
+
"roles:get": {
|
|
247
|
+
"data": {
|
|
248
|
+
"createdAt": "2024-04-07T06:50:37.622Z",
|
|
249
|
+
"updatedAt": "2024-04-07T06:50:37.622Z",
|
|
250
|
+
"allowConfigure": null,
|
|
251
|
+
"allowNewMenu": null,
|
|
252
|
+
"default": false,
|
|
253
|
+
"description": null,
|
|
254
|
+
"hidden": true,
|
|
255
|
+
"name": "root",
|
|
256
|
+
"color": "#1677FF",
|
|
257
|
+
"snippets": ["pm", "pm.*", "ui.*"],
|
|
258
|
+
"strategy": null,
|
|
259
|
+
"title": "{{t(\"Root\")}}"
|
|
260
|
+
}
|
|
261
|
+
},
|
|
161
262
|
"tree:list": {
|
|
162
263
|
"data": [
|
|
163
264
|
{
|
package/lib/web/index.d.ts
CHANGED
|
@@ -14,12 +14,13 @@ type URL = string;
|
|
|
14
14
|
type ResponseData = any;
|
|
15
15
|
type MockApis = Record<URL, ResponseData>;
|
|
16
16
|
type AppOrOptions = Application | ApplicationOptions;
|
|
17
|
-
export declare const mockApi: (axiosInstance: AxiosInstance, apis?: MockApis) => (apis?: MockApis) => void;
|
|
18
|
-
export declare const mockAppApi: (app: Application, apis?: MockApis) => (apis?: MockApis) => void;
|
|
17
|
+
export declare const mockApi: (axiosInstance: AxiosInstance, apis?: MockApis, delayResponse?: number) => (apis?: MockApis) => void;
|
|
18
|
+
export declare const mockAppApi: (app: Application, apis?: MockApis, delayResponse?: number) => (apis?: MockApis) => void;
|
|
19
19
|
export interface GetAppOptions {
|
|
20
20
|
appOptions?: AppOrOptions;
|
|
21
21
|
providers?: (ComponentType | [ComponentType, any])[];
|
|
22
22
|
apis?: MockApis;
|
|
23
|
+
delayResponse?: number;
|
|
23
24
|
designable?: boolean;
|
|
24
25
|
schemaSettings?: SchemaSettings;
|
|
25
26
|
disableAcl?: boolean;
|
package/lib/web/index.js
CHANGED
|
@@ -63,7 +63,10 @@ var import_lodash2 = __toESM(require("lodash"));
|
|
|
63
63
|
__reExport(web_exports, require("./utils"), module.exports);
|
|
64
64
|
const defaultApis = {
|
|
65
65
|
"uiSchemas:patch": { data: { result: "ok" } },
|
|
66
|
+
"uiSchemas:batchPatch": { data: { result: "ok" } },
|
|
66
67
|
"uiSchemas:saveAsTemplate": { data: { result: "ok" } },
|
|
68
|
+
"users:update": { data: { result: "ok" } },
|
|
69
|
+
"roles:update": { data: { result: "ok" } },
|
|
67
70
|
...import_dataSourceMainData.default
|
|
68
71
|
};
|
|
69
72
|
function getProcessMockData(apis, key) {
|
|
@@ -73,16 +76,28 @@ function getProcessMockData(apis, key) {
|
|
|
73
76
|
return [404, { data: { message: "mock data not found" } }];
|
|
74
77
|
if (((_a = config == null ? void 0 : config.params) == null ? void 0 : _a.pageSize) || ((_b = config == null ? void 0 : config.params) == null ? void 0 : _b.page)) {
|
|
75
78
|
const { data, meta } = apis[key];
|
|
76
|
-
const pageSize = config.params.pageSize || (meta == null ? void 0 : meta.pageSize);
|
|
77
|
-
const page = config.params.page || (meta == null ? void 0 : meta.page);
|
|
78
|
-
return [
|
|
79
|
+
const pageSize = config.params.pageSize || (meta == null ? void 0 : meta.pageSize) || 20;
|
|
80
|
+
const page = config.params.page || (meta == null ? void 0 : meta.page) || 1;
|
|
81
|
+
return [
|
|
82
|
+
200,
|
|
83
|
+
{
|
|
84
|
+
data: data.slice(pageSize * (page - 1), pageSize * page),
|
|
85
|
+
meta: {
|
|
86
|
+
...meta,
|
|
87
|
+
page,
|
|
88
|
+
pageSize,
|
|
89
|
+
count: data.length,
|
|
90
|
+
totalPage: Math.ceil(data.length / pageSize)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
];
|
|
79
94
|
}
|
|
80
95
|
return [200, apis[key]];
|
|
81
96
|
};
|
|
82
97
|
}
|
|
83
98
|
__name(getProcessMockData, "getProcessMockData");
|
|
84
|
-
const mockApi = /* @__PURE__ */ __name((axiosInstance, apis = {}) => {
|
|
85
|
-
const mock = new import_axios_mock_adapter.default(axiosInstance);
|
|
99
|
+
const mockApi = /* @__PURE__ */ __name((axiosInstance, apis = {}, delayResponse) => {
|
|
100
|
+
const mock = new import_axios_mock_adapter.default(axiosInstance, { delayResponse });
|
|
86
101
|
Object.keys(apis).forEach((key) => {
|
|
87
102
|
mock.onAny(key).reply(getProcessMockData(apis, key));
|
|
88
103
|
});
|
|
@@ -92,10 +107,14 @@ const mockApi = /* @__PURE__ */ __name((axiosInstance, apis = {}) => {
|
|
|
92
107
|
});
|
|
93
108
|
};
|
|
94
109
|
}, "mockApi");
|
|
95
|
-
const mockAppApi = /* @__PURE__ */ __name((app, apis = {}) => {
|
|
96
|
-
const mock = mockApi(app.apiClient.axios, apis);
|
|
110
|
+
const mockAppApi = /* @__PURE__ */ __name((app, apis = {}, delayResponse) => {
|
|
111
|
+
const mock = mockApi(app.apiClient.axios, apis, delayResponse);
|
|
97
112
|
return mock;
|
|
98
113
|
}, "mockAppApi");
|
|
114
|
+
const ShowFormData = (0, import_react2.observer)(({ children }) => {
|
|
115
|
+
const form = (0, import_react2.useForm)();
|
|
116
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("pre", { style: { marginBottom: 20 }, "data-testid": "form-data" }, JSON.stringify(form.values, null, 2)), children);
|
|
117
|
+
});
|
|
99
118
|
const getApp = /* @__PURE__ */ __name((options) => {
|
|
100
119
|
const {
|
|
101
120
|
appOptions = {},
|
|
@@ -104,7 +123,8 @@ const getApp = /* @__PURE__ */ __name((options) => {
|
|
|
104
123
|
disableAcl = true,
|
|
105
124
|
apis: optionsApis = {},
|
|
106
125
|
enableMultipleDataSource,
|
|
107
|
-
designable
|
|
126
|
+
designable,
|
|
127
|
+
delayResponse
|
|
108
128
|
} = options;
|
|
109
129
|
const app = appOptions instanceof import_client.Application ? appOptions : new import_client.Application({
|
|
110
130
|
...appOptions,
|
|
@@ -117,7 +137,7 @@ const getApp = /* @__PURE__ */ __name((options) => {
|
|
|
117
137
|
if (schemaSettings) {
|
|
118
138
|
app.schemaSettingsManager.add(schemaSettings);
|
|
119
139
|
}
|
|
120
|
-
app.addComponents({ CommonSchemaComponent });
|
|
140
|
+
app.addComponents({ CommonSchemaComponent, ShowFormData });
|
|
121
141
|
app.pluginManager.add(import_client.AntdSchemaComponentPlugin);
|
|
122
142
|
app.pluginManager.add(import_client.SchemaSettingsPlugin);
|
|
123
143
|
app.pluginManager.add(import_client.CollectionPlugin, { config: { enableRemoteDataSource: false } });
|
|
@@ -126,7 +146,7 @@ const getApp = /* @__PURE__ */ __name((options) => {
|
|
|
126
146
|
if (enableMultipleDataSource) {
|
|
127
147
|
app.dataSourceManager.addDataSource(import_client.LocalDataSource, import_dataSource2.default);
|
|
128
148
|
}
|
|
129
|
-
mockAppApi(app, apis);
|
|
149
|
+
mockAppApi(app, apis, delayResponse);
|
|
130
150
|
const App = app.getRootComponent();
|
|
131
151
|
return {
|
|
132
152
|
App,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/test",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.4",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"module": "./src/index.ts",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@faker-js/faker": "8.1.0",
|
|
54
|
-
"@nocobase/server": "1.0.0-alpha.
|
|
54
|
+
"@nocobase/server": "1.0.0-alpha.4",
|
|
55
55
|
"@playwright/test": "^1.42.1",
|
|
56
56
|
"@testing-library/jest-dom": "^6.4.2",
|
|
57
57
|
"@testing-library/react": "^14.0.0",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"vitest-dom": "^0.1.1",
|
|
77
77
|
"ws": "^8.13.0"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "7a7005ce3bddf33498580a6486c45b5d9ea64ffb"
|
|
80
80
|
}
|