@nocobase/test 1.0.0-alpha.8 → 1.0.1-alpha.1

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.
@@ -11,10 +11,12 @@ import { sleep } from '../web';
11
11
  export * from './utils';
12
12
  export { renderHook } from '@testing-library/react-hooks';
13
13
  declare function customRender(ui: React.ReactElement, options?: {}): import("@testing-library/react").RenderResult<typeof import("@testing-library/dom/types/queries"), HTMLElement, HTMLElement>;
14
+ export declare function waitForApp(): Promise<void>;
15
+ export declare function renderApp(element: React.JSX.Element): Promise<import("@testing-library/react").RenderResult<typeof import("@testing-library/dom/types/queries"), HTMLElement, HTMLElement>>;
14
16
  export * from '@testing-library/react';
15
17
  export { default as userEvent } from '@testing-library/user-event';
16
18
  export { customRender as render, sleep };
17
- export * from './renderApp';
19
+ export * from './renderAppOptions';
18
20
  export * from './renderHookWithApp';
19
21
  export * from './renderSettings';
20
22
  export * from './renderSingleSettings';
@@ -1,15 +1,174 @@
1
1
  import { waitFor, screen, render } from "@testing-library/react";
2
2
  export * from "@testing-library/react";
3
- import React, { Fragment } from "react";
3
+ import { observer, useForm, useFieldSchema } from "@formily/react";
4
4
  import MockAdapter from "axios-mock-adapter";
5
5
  import _, { pick, get } from "lodash";
6
- import { observer, useForm, useFieldSchema } from "@formily/react";
6
+ import React, { Fragment } from "react";
7
7
  import { Application, AntdSchemaComponentPlugin, SchemaSettingsPlugin, CollectionPlugin, LocalDataSource, SchemaSettings, SchemaComponent, DataBlockProvider } from "@nocobase/client";
8
- import { expect } from "vitest";
8
+ import { expect as expect$1 } from "vitest";
9
9
  import userEvent from "@testing-library/user-event";
10
10
  import { default as default2 } from "@testing-library/user-event";
11
11
  import { renderHook } from "@testing-library/react-hooks";
12
12
  import { renderHook as renderHook2 } from "@testing-library/react-hooks";
13
+ const key = "data-source2";
14
+ const displayName = "Data Source 2";
15
+ const status = "loaded";
16
+ const type = "postgres";
17
+ const isDBInstance = true;
18
+ const collections = [
19
+ {
20
+ name: "test",
21
+ title: "test",
22
+ tableName: "test",
23
+ timestamps: false,
24
+ autoGenId: false,
25
+ filterTargetKey: "id",
26
+ fields: [
27
+ {
28
+ name: "id",
29
+ type: "integer",
30
+ allowNull: false,
31
+ primaryKey: false,
32
+ unique: false,
33
+ autoIncrement: true,
34
+ possibleTypes: [
35
+ "integer",
36
+ "sort"
37
+ ],
38
+ rawType: "INTEGER",
39
+ "interface": "integer",
40
+ uiSchema: {
41
+ type: "number",
42
+ "x-component": "InputNumber",
43
+ "x-component-props": {
44
+ stringMode: true,
45
+ step: "1"
46
+ },
47
+ "x-validator": "integer",
48
+ title: "id"
49
+ }
50
+ },
51
+ {
52
+ name: "title",
53
+ type: "string",
54
+ allowNull: false,
55
+ primaryKey: false,
56
+ unique: false,
57
+ possibleTypes: [
58
+ "string",
59
+ "uuid",
60
+ "nanoid"
61
+ ],
62
+ rawType: "CHARACTER VARYING(255)",
63
+ "interface": "input",
64
+ uiSchema: {
65
+ "x-component": "Input",
66
+ "x-component-props": {
67
+ style: {
68
+ width: "100%"
69
+ }
70
+ },
71
+ title: "title"
72
+ }
73
+ },
74
+ {
75
+ name: "content",
76
+ type: "text",
77
+ allowNull: true,
78
+ primaryKey: false,
79
+ unique: false,
80
+ rawType: "TEXT",
81
+ "interface": "textarea",
82
+ uiSchema: {
83
+ type: "string",
84
+ "x-component": "Input.TextArea",
85
+ title: "content"
86
+ }
87
+ }
88
+ ],
89
+ introspected: true
90
+ },
91
+ {
92
+ name: "test2",
93
+ title: "test2",
94
+ tableName: "test2",
95
+ timestamps: false,
96
+ autoGenId: false,
97
+ filterTargetKey: "id",
98
+ fields: [
99
+ {
100
+ name: "id",
101
+ type: "integer",
102
+ allowNull: false,
103
+ primaryKey: true,
104
+ unique: false,
105
+ autoIncrement: true,
106
+ possibleTypes: [
107
+ "integer",
108
+ "sort"
109
+ ],
110
+ rawType: "INTEGER",
111
+ "interface": "integer",
112
+ uiSchema: {
113
+ type: "number",
114
+ "x-component": "InputNumber",
115
+ "x-component-props": {
116
+ stringMode: true,
117
+ step: "1"
118
+ },
119
+ "x-validator": "integer",
120
+ title: "id"
121
+ }
122
+ },
123
+ {
124
+ name: "title",
125
+ type: "string",
126
+ allowNull: true,
127
+ primaryKey: false,
128
+ unique: false,
129
+ possibleTypes: [
130
+ "string",
131
+ "uuid",
132
+ "nanoid"
133
+ ],
134
+ rawType: "CHARACTER VARYING(255)",
135
+ "interface": "input",
136
+ uiSchema: {
137
+ "x-component": "Input",
138
+ "x-component-props": {
139
+ style: {
140
+ width: "100%"
141
+ }
142
+ },
143
+ title: "title"
144
+ }
145
+ },
146
+ {
147
+ name: "content",
148
+ type: "text",
149
+ allowNull: true,
150
+ primaryKey: false,
151
+ unique: false,
152
+ rawType: "TEXT",
153
+ "interface": "textarea",
154
+ uiSchema: {
155
+ type: "string",
156
+ "x-component": "Input.TextArea",
157
+ title: "content"
158
+ }
159
+ }
160
+ ],
161
+ introspected: true
162
+ }
163
+ ];
164
+ const dataSource2 = {
165
+ key,
166
+ displayName,
167
+ status,
168
+ type,
169
+ isDBInstance,
170
+ collections
171
+ };
13
172
  const dataSourceMainCollections = [
14
173
  {
15
174
  key: "yzowed2vee0",
@@ -833,165 +992,6 @@ const dataSourceMainCollections = [
833
992
  filterTargetKey: "id"
834
993
  }
835
994
  ];
836
- const key = "data-source2";
837
- const displayName = "Data Source 2";
838
- const status = "loaded";
839
- const type = "postgres";
840
- const isDBInstance = true;
841
- const collections = [
842
- {
843
- name: "test",
844
- title: "test",
845
- tableName: "test",
846
- timestamps: false,
847
- autoGenId: false,
848
- filterTargetKey: "id",
849
- fields: [
850
- {
851
- name: "id",
852
- type: "integer",
853
- allowNull: false,
854
- primaryKey: false,
855
- unique: false,
856
- autoIncrement: true,
857
- possibleTypes: [
858
- "integer",
859
- "sort"
860
- ],
861
- rawType: "INTEGER",
862
- "interface": "integer",
863
- uiSchema: {
864
- type: "number",
865
- "x-component": "InputNumber",
866
- "x-component-props": {
867
- stringMode: true,
868
- step: "1"
869
- },
870
- "x-validator": "integer",
871
- title: "id"
872
- }
873
- },
874
- {
875
- name: "title",
876
- type: "string",
877
- allowNull: false,
878
- primaryKey: false,
879
- unique: false,
880
- possibleTypes: [
881
- "string",
882
- "uuid",
883
- "nanoid"
884
- ],
885
- rawType: "CHARACTER VARYING(255)",
886
- "interface": "input",
887
- uiSchema: {
888
- "x-component": "Input",
889
- "x-component-props": {
890
- style: {
891
- width: "100%"
892
- }
893
- },
894
- title: "title"
895
- }
896
- },
897
- {
898
- name: "content",
899
- type: "text",
900
- allowNull: true,
901
- primaryKey: false,
902
- unique: false,
903
- rawType: "TEXT",
904
- "interface": "textarea",
905
- uiSchema: {
906
- type: "string",
907
- "x-component": "Input.TextArea",
908
- title: "content"
909
- }
910
- }
911
- ],
912
- introspected: true
913
- },
914
- {
915
- name: "test2",
916
- title: "test2",
917
- tableName: "test2",
918
- timestamps: false,
919
- autoGenId: false,
920
- filterTargetKey: "id",
921
- fields: [
922
- {
923
- name: "id",
924
- type: "integer",
925
- allowNull: false,
926
- primaryKey: true,
927
- unique: false,
928
- autoIncrement: true,
929
- possibleTypes: [
930
- "integer",
931
- "sort"
932
- ],
933
- rawType: "INTEGER",
934
- "interface": "integer",
935
- uiSchema: {
936
- type: "number",
937
- "x-component": "InputNumber",
938
- "x-component-props": {
939
- stringMode: true,
940
- step: "1"
941
- },
942
- "x-validator": "integer",
943
- title: "id"
944
- }
945
- },
946
- {
947
- name: "title",
948
- type: "string",
949
- allowNull: true,
950
- primaryKey: false,
951
- unique: false,
952
- possibleTypes: [
953
- "string",
954
- "uuid",
955
- "nanoid"
956
- ],
957
- rawType: "CHARACTER VARYING(255)",
958
- "interface": "input",
959
- uiSchema: {
960
- "x-component": "Input",
961
- "x-component-props": {
962
- style: {
963
- width: "100%"
964
- }
965
- },
966
- title: "title"
967
- }
968
- },
969
- {
970
- name: "content",
971
- type: "text",
972
- allowNull: true,
973
- primaryKey: false,
974
- unique: false,
975
- rawType: "TEXT",
976
- "interface": "textarea",
977
- uiSchema: {
978
- type: "string",
979
- "x-component": "Input.TextArea",
980
- title: "content"
981
- }
982
- }
983
- ],
984
- introspected: true
985
- }
986
- ];
987
- const dataSource2 = {
988
- key,
989
- displayName,
990
- status,
991
- type,
992
- isDBInstance,
993
- collections
994
- };
995
995
  const dataSourceMainData = {
996
996
  "users:list": {
997
997
  data: [
@@ -1384,6 +1384,9 @@ const defaultApis = {
1384
1384
  ...dataSourceMainData
1385
1385
  };
1386
1386
  function getProcessMockData(apis, key2) {
1387
+ if (typeof apis[key2] === "function") {
1388
+ return apis[key2];
1389
+ }
1387
1390
  return (config) => {
1388
1391
  var _a, _b;
1389
1392
  if (!apis[key2])
@@ -1574,7 +1577,7 @@ function withSchema(Component, name) {
1574
1577
  const CommonSchemaComponent = withSchema(function CommonSchemaComponent2(props) {
1575
1578
  return /* @__PURE__ */ React.createElement(React.Fragment, null, props.children);
1576
1579
  });
1577
- const expectNoTsError = expect;
1580
+ const expectNoTsError = expect$1;
1578
1581
  const WaitApp = async () => {
1579
1582
  await waitFor(() => {
1580
1583
  expectNoTsError(screen.queryByText("Loading...")).not.toBeInTheDocument();
@@ -1725,17 +1728,17 @@ async function checkModal(options) {
1725
1728
  async function checkSchema(matchObj, name) {
1726
1729
  const objText = screen.queryByTestId(name ? `test-schema-${name}` : `test-schema`);
1727
1730
  await waitFor(() => {
1728
- expect(JSON.parse(objText.textContent)).toMatchObject(matchObj);
1731
+ expect$1(JSON.parse(objText.textContent)).toMatchObject(matchObj);
1729
1732
  });
1730
1733
  }
1731
- const renderApp = async (options) => {
1734
+ const renderAppOptions = async (options) => {
1732
1735
  const App = getAppComponent(options);
1733
1736
  const res = render(/* @__PURE__ */ React.createElement(App, null));
1734
1737
  await WaitApp();
1735
1738
  return res;
1736
1739
  };
1737
1740
  const renderReadPrettyApp = (options) => {
1738
- return renderApp({ ...options, schema: addXReadPrettyToEachLayer(options.schema) });
1741
+ return renderAppOptions({ ...options, schema: addXReadPrettyToEachLayer(options.schema) });
1739
1742
  };
1740
1743
  const renderHookWithApp = async (options) => {
1741
1744
  const { hook: useHook, props, Wrapper = Fragment, ...otherOptions } = options;
@@ -1756,7 +1759,7 @@ async function showSettingsMenu(container = document) {
1756
1759
  }
1757
1760
  const renderSettings = async (options = {}) => {
1758
1761
  const { container = () => document, ...appOptions } = options;
1759
- const result = await renderApp({ ...appOptions, designable: true });
1762
+ const result = await renderAppOptions({ ...appOptions, designable: true });
1760
1763
  const containerElement = container();
1761
1764
  await showSettingsMenu(containerElement);
1762
1765
  return result;
@@ -1820,7 +1823,7 @@ async function checkSwitchSetting(options) {
1820
1823
  if (formItem2) {
1821
1824
  const switchElement2 = formItem2.querySelector("button[role=switch]");
1822
1825
  const newChecked = switchElement2.getAttribute("aria-checked");
1823
- expect(newChecked).not.toBe(oldChecked);
1826
+ expect$1(newChecked).not.toBe(oldChecked);
1824
1827
  oldChecked = newChecked;
1825
1828
  } else {
1826
1829
  await showSettingsMenu();
@@ -1892,7 +1895,7 @@ const types = {
1892
1895
  async function checkSettings(list, checkLength = false) {
1893
1896
  if (checkLength) {
1894
1897
  const menuList = screen.getByTestId("schema-settings-menu");
1895
- expect(menuList.querySelectorAll('li[role="menuitem"]')).toHaveLength(list.length);
1898
+ expect$1(menuList.querySelectorAll('li[role="menuitem"]')).toHaveLength(list.length);
1896
1899
  }
1897
1900
  for (const item of list) {
1898
1901
  if (!screen.queryByTestId("schema-settings-menu")) {
@@ -1960,6 +1963,16 @@ function customRender(ui, options = {}) {
1960
1963
  ...options
1961
1964
  });
1962
1965
  }
1966
+ async function waitForApp() {
1967
+ return waitFor(() => {
1968
+ expect(screen.queryByText("Loading...")).not.toBeInTheDocument();
1969
+ });
1970
+ }
1971
+ async function renderApp(element) {
1972
+ const res = render(element);
1973
+ await waitForApp();
1974
+ return res;
1975
+ }
1963
1976
  export {
1964
1977
  WaitApp,
1965
1978
  checkBlockTitle,
@@ -1974,6 +1987,7 @@ export {
1974
1987
  expectNoTsError,
1975
1988
  customRender as render,
1976
1989
  renderApp,
1990
+ renderAppOptions,
1977
1991
  renderHook2 as renderHook,
1978
1992
  renderHookWithApp,
1979
1993
  renderReadPrettyApp,
@@ -1983,5 +1997,6 @@ export {
1983
1997
  renderSingleSettings,
1984
1998
  showSettingsMenu,
1985
1999
  sleep,
1986
- default2 as userEvent
2000
+ default2 as userEvent,
2001
+ waitForApp
1987
2002
  };
@@ -7,5 +7,5 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
  import { GetAppComponentOptions } from '../web';
10
- export declare const renderApp: (options: GetAppComponentOptions) => Promise<import("@testing-library/react").RenderResult<typeof import("@testing-library/dom/types/queries"), HTMLElement, HTMLElement>>;
10
+ export declare const renderAppOptions: (options: GetAppComponentOptions) => Promise<import("@testing-library/react").RenderResult<typeof import("@testing-library/dom/types/queries"), HTMLElement, HTMLElement>>;
11
11
  export declare const renderReadPrettyApp: (options: GetAppComponentOptions) => Promise<import("@testing-library/react").RenderResult<typeof import("@testing-library/dom/types/queries"), HTMLElement, HTMLElement>>;
@@ -169,6 +169,7 @@ export interface PageConfig {
169
169
  keepUid?: boolean;
170
170
  }
171
171
  interface ExtendUtils {
172
+ page?: Page;
172
173
  /**
173
174
  * 根据配置,生成一个 NocoBase 的页面
174
175
  * @param pageConfig 页面配置
@@ -258,9 +259,14 @@ interface ExtendUtils {
258
259
  */
259
260
  destoryExternalDataSource: <T = any>(key: string) => Promise<T>;
260
261
  /**
261
- * 清空区块模板
262
+ * 清空区块模板,该方法应该放到测试用例开始的位置(放在末尾的话,如果测试报错会导致模板不会被清空)
262
263
  */
263
- clearBlockTemplates: () => Promise<void>;
264
+ clearBlockTemplates: ({ immediate, }?: {
265
+ /**
266
+ * 是否立即清空,默认为 false。如果为 true,则会立即清空,否则会等到测试用例结束后再清空
267
+ */
268
+ immediate: boolean;
269
+ }) => Promise<void>;
264
270
  }
265
271
  export declare class NocoPage {
266
272
  private options?;