@nocobase/test 0.16.0-alpha.5 → 0.17.0-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.
@@ -1,6 +1,6 @@
1
1
  import { Page } from '@playwright/test';
2
2
  export * from '@playwright/test';
3
- interface CollectionSetting {
3
+ export interface CollectionSetting {
4
4
  name: string;
5
5
  title?: string;
6
6
  /**
@@ -81,6 +81,15 @@ interface CollectionSetting {
81
81
  }>;
82
82
  }
83
83
  export interface PageConfig {
84
+ /**
85
+ * 页面类型
86
+ * @default 'page'
87
+ */
88
+ type?: 'group' | 'page' | 'link';
89
+ /**
90
+ * type 为 link 时,表示跳转的链接
91
+ */
92
+ url?: string;
84
93
  /**
85
94
  * 用户可见的页面名称
86
95
  * @default uid()
@@ -116,39 +125,59 @@ declare class NocoPage {
116
125
  destroy(): Promise<void>;
117
126
  }
118
127
  export declare const test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & {
128
+ page: Page;
119
129
  mockPage: (config?: PageConfig) => NocoPage;
120
130
  mockCollections: <T = any>(collectionSettings: CollectionSetting[]) => Promise<T>;
121
131
  mockCollection: <T_1 = any>(collectionSetting: CollectionSetting) => Promise<T_1>;
122
132
  mockRecord: <T_2 = any>(collectionName: string, data?: any) => Promise<T_2>;
123
- mockRecords: <T_3 = any>(collectionName: string, count?: number, data?: any) => Promise<T_3[]>;
133
+ mockRecords: {
134
+ <T_3 = any>(collectionName: string, count?: number): Promise<T_3[]>;
135
+ <T_4 = any>(collectionName: string, data?: any[]): Promise<T_4[]>;
136
+ };
124
137
  createCollections: (collectionSettings: CollectionSetting | CollectionSetting[]) => Promise<void>;
138
+ deletePage: (pageName: string) => Promise<void>;
125
139
  }, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions> & {
126
140
  /** 只运行在 postgres 数据库中 */
127
141
  pgOnly: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & {
142
+ page: Page;
128
143
  mockPage: (config?: PageConfig) => NocoPage;
129
144
  mockCollections: <T = any>(collectionSettings: CollectionSetting[]) => Promise<T>;
130
145
  mockCollection: <T_1 = any>(collectionSetting: CollectionSetting) => Promise<T_1>;
131
146
  mockRecord: <T_2 = any>(collectionName: string, data?: any) => Promise<T_2>;
132
- mockRecords: <T_3 = any>(collectionName: string, count?: number, data?: any) => Promise<T_3[]>;
147
+ mockRecords: {
148
+ <T_3 = any>(collectionName: string, count?: number): Promise<T_3[]>;
149
+ <T_4 = any>(collectionName: string, data?: any[]): Promise<T_4[]>;
150
+ };
133
151
  createCollections: (collectionSettings: CollectionSetting | CollectionSetting[]) => Promise<void>;
152
+ deletePage: (pageName: string) => Promise<void>;
134
153
  }, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions> | {
135
154
  (title: string, testFunction: (args: import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & {
155
+ page: Page;
136
156
  mockPage: (config?: PageConfig) => NocoPage;
137
157
  mockCollections: <T = any>(collectionSettings: CollectionSetting[]) => Promise<T>;
138
158
  mockCollection: <T_1 = any>(collectionSetting: CollectionSetting) => Promise<T_1>;
139
159
  mockRecord: <T_2 = any>(collectionName: string, data?: any) => Promise<T_2>;
140
- mockRecords: <T_3 = any>(collectionName: string, count?: number, data?: any) => Promise<T_3[]>;
160
+ mockRecords: {
161
+ <T_3 = any>(collectionName: string, count?: number): Promise<T_3[]>;
162
+ <T_4 = any>(collectionName: string, data?: any[]): Promise<T_4[]>;
163
+ };
141
164
  createCollections: (collectionSettings: CollectionSetting | CollectionSetting[]) => Promise<void>;
165
+ deletePage: (pageName: string) => Promise<void>;
142
166
  } & import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions, testInfo: import("@playwright/test").TestInfo) => void | Promise<void>): void;
143
167
  (): void;
144
168
  (condition: boolean, description?: string): void;
145
169
  (callback: (args: import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & {
170
+ page: Page;
146
171
  mockPage: (config?: PageConfig) => NocoPage;
147
172
  mockCollections: <T = any>(collectionSettings: CollectionSetting[]) => Promise<T>;
148
173
  mockCollection: <T_1 = any>(collectionSetting: CollectionSetting) => Promise<T_1>;
149
174
  mockRecord: <T_2 = any>(collectionName: string, data?: any) => Promise<T_2>;
150
- mockRecords: <T_3 = any>(collectionName: string, count?: number, data?: any) => Promise<T_3[]>;
175
+ mockRecords: {
176
+ <T_3 = any>(collectionName: string, count?: number): Promise<T_3[]>;
177
+ <T_4 = any>(collectionName: string, data?: any[]): Promise<T_4[]>;
178
+ };
151
179
  createCollections: (collectionSettings: CollectionSetting | CollectionSetting[]) => Promise<void>;
180
+ deletePage: (pageName: string) => Promise<void>;
152
181
  } & import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions) => boolean, description?: string): void;
153
182
  };
154
183
  };
@@ -52,22 +52,23 @@ const _NocoPage = class _NocoPage {
52
52
  collectionsName;
53
53
  _waitForInit;
54
54
  async init() {
55
- var _a, _b, _c, _d, _e;
55
+ var _a, _b, _c, _d, _e, _f, _g;
56
56
  if ((_b = (_a = this.options) == null ? void 0 : _a.collections) == null ? void 0 : _b.length) {
57
57
  const collections = omitSomeFields(this.options.collections);
58
58
  this.collectionsName = collections.map((item) => item.name);
59
59
  await createCollections(collections);
60
60
  }
61
61
  this.uid = await createPage(this.page, {
62
- name: (_c = this.options) == null ? void 0 : _c.name,
63
- pageSchema: (_d = this.options) == null ? void 0 : _d.pageSchema
62
+ type: (_c = this.options) == null ? void 0 : _c.type,
63
+ name: (_d = this.options) == null ? void 0 : _d.name,
64
+ pageSchema: (_e = this.options) == null ? void 0 : _e.pageSchema,
65
+ url: (_f = this.options) == null ? void 0 : _f.url
64
66
  });
65
- this.url = `${((_e = this.options) == null ? void 0 : _e.basePath) || "/admin/"}${this.uid}`;
67
+ this.url = `${((_g = this.options) == null ? void 0 : _g.basePath) || "/admin/"}${this.uid}`;
66
68
  }
67
69
  async goto() {
68
70
  await this._waitForInit;
69
71
  await this.page.goto(this.url);
70
- await enableToConfig(this.page);
71
72
  }
72
73
  async waitForInit() {
73
74
  await this._waitForInit;
@@ -88,6 +89,15 @@ const _NocoPage = class _NocoPage {
88
89
  __name(_NocoPage, "NocoPage");
89
90
  let NocoPage = _NocoPage;
90
91
  const _test = import_test.test.extend({
92
+ page: async ({ page: _page }, use) => {
93
+ const page = Object.create(_page);
94
+ page.goto = /* @__PURE__ */ __name(async function goto(url, options) {
95
+ const result = await _page.goto(url, options);
96
+ await enableToConfig(_page);
97
+ return result;
98
+ }, "goto");
99
+ await use(page);
100
+ },
91
101
  mockPage: async ({ page }, use) => {
92
102
  import_faker.faker.seed(1);
93
103
  const nocoPages = [];
@@ -141,6 +151,10 @@ const _test = import_test.test.extend({
141
151
  },
142
152
  mockRecords: async ({ page }, use) => {
143
153
  const mockRecords = /* @__PURE__ */ __name(async (collectionName, count = 3, data) => {
154
+ if (import_lodash.default.isArray(count)) {
155
+ data = count;
156
+ count = data.length;
157
+ }
144
158
  return createRandomData(collectionName, count, data);
145
159
  }, "mockRecords");
146
160
  await use(mockRecords);
@@ -151,6 +165,15 @@ const _test = import_test.test.extend({
151
165
  return result[0];
152
166
  }, "mockRecord");
153
167
  await use(mockRecord);
168
+ },
169
+ deletePage: async ({ page }, use) => {
170
+ const deletePage2 = /* @__PURE__ */ __name(async (pageName) => {
171
+ await page.getByText(pageName, { exact: true }).hover();
172
+ await page.getByRole("button", { name: "designer-schema-settings-" }).hover();
173
+ await page.getByRole("menuitem", { name: "Delete", exact: true }).click();
174
+ await page.getByRole("button", { name: "OK", exact: true }).click();
175
+ }, "deletePage");
176
+ await use(deletePage2);
154
177
  }
155
178
  });
156
179
  const test = Object.assign(_test, {
@@ -176,10 +199,26 @@ const updateUidOfPageSchema = /* @__PURE__ */ __name((uiSchema) => {
176
199
  return uiSchema;
177
200
  }, "updateUidOfPageSchema");
178
201
  const createPage = /* @__PURE__ */ __name(async (page, options) => {
179
- const { name, pageSchema } = options || {};
202
+ const { type = "page", url, name, pageSchema } = options || {};
180
203
  const api = await import_test.request.newContext({
181
204
  storageState: require.resolve("../../../../../playwright/.auth/admin.json")
182
205
  });
206
+ const typeToSchema = {
207
+ group: {
208
+ "x-component": "Menu.SubMenu",
209
+ "x-component-props": {}
210
+ },
211
+ page: {
212
+ "x-component": "Menu.Item",
213
+ "x-component-props": {}
214
+ },
215
+ link: {
216
+ "x-component": "Menu.URL",
217
+ "x-component-props": {
218
+ href: url
219
+ }
220
+ }
221
+ };
183
222
  const state = await api.storageState();
184
223
  const headers = getHeaders(state);
185
224
  const systemSettings = await api.get(`/api/systemSettings:get/1`, {
@@ -197,9 +236,8 @@ const createPage = /* @__PURE__ */ __name(async (page, options) => {
197
236
  version: "2.0",
198
237
  type: "void",
199
238
  title: name || pageUid,
200
- "x-component": "Menu.Item",
239
+ ...typeToSchema[type],
201
240
  "x-decorator": "ACLMenuItemProvider",
202
- "x-component-props": {},
203
241
  "x-server-hooks": [
204
242
  { type: "onSelfCreate", method: "bindMenuToRole" },
205
243
  { type: "onSelfSave", method: "extractTextToLocale" }
@@ -270,9 +308,10 @@ const deleteCollections = /* @__PURE__ */ __name(async (collectionNames) => {
270
308
  }, "deleteCollections");
271
309
  const omitSomeFields = /* @__PURE__ */ __name((collectionSettings) => {
272
310
  return collectionSettings.map((collection) => {
311
+ var _a;
273
312
  return {
274
313
  ...import_lodash.default.omit(collection, ["key"]),
275
- fields: collection.fields.map((field) => import_lodash.default.omit(field, ["key", "collectionName"]))
314
+ fields: (_a = collection.fields) == null ? void 0 : _a.map((field) => import_lodash.default.omit(field, ["key", "collectionName"]))
276
315
  };
277
316
  });
278
317
  }, "omitSomeFields");
@@ -1,2 +1,4 @@
1
1
  export * from './e2eUtils';
2
2
  export * from './templatesOfBug';
3
+ export * from './templatesOfCollection';
4
+ export * from './templatesOfPage';
@@ -16,8 +16,12 @@ var client_exports = {};
16
16
  module.exports = __toCommonJS(client_exports);
17
17
  __reExport(client_exports, require("./e2eUtils"), module.exports);
18
18
  __reExport(client_exports, require("./templatesOfBug"), module.exports);
19
+ __reExport(client_exports, require("./templatesOfCollection"), module.exports);
20
+ __reExport(client_exports, require("./templatesOfPage"), module.exports);
19
21
  // Annotate the CommonJS export names for ESM import in node:
20
22
  0 && (module.exports = {
21
23
  ...require("./e2eUtils"),
22
- ...require("./templatesOfBug")
24
+ ...require("./templatesOfBug"),
25
+ ...require("./templatesOfCollection"),
26
+ ...require("./templatesOfPage")
23
27
  });
@@ -0,0 +1,40 @@
1
+ import { CollectionSetting } from './e2eUtils';
2
+ /**
3
+ * 创建一个名为 general 的 collection,其包含所有类型的字段
4
+ */
5
+ export declare const general: CollectionSetting[];
6
+ /**
7
+ * 创建一个名为 general 的 collection,其包含所有 basic 类型的字段
8
+ */
9
+ export declare const generalWithBasic: CollectionSetting[];
10
+ /**
11
+ * 创建一个名为 general 的 collection,其包含所有 choices 类型的字段
12
+ */
13
+ export declare const generalWithChoices: CollectionSetting[];
14
+ /**
15
+ * 创建一个名为 general 的 collection,其包含所有 media 类型的字段
16
+ */
17
+ export declare const generalWithMedia: CollectionSetting[];
18
+ /**
19
+ * 创建一个名为 general 的 collection,其包含所有 datetime 类型的字段
20
+ */
21
+ export declare const generalWithDatetime: CollectionSetting[];
22
+ /**
23
+ * 创建一个名为 general 的 collection,其包含所有 relation 类型的字段
24
+ */
25
+ export declare const generalWithRelation: CollectionSetting[];
26
+ /**
27
+ * 创建一个名为 general 的 collection,其包含所有 advanced 类型的字段
28
+ */
29
+ export declare const generalWithAdvanced: CollectionSetting[];
30
+ /**
31
+ * 创建一个名为 general 的 collection,其包含所有 systemInfo 类型的字段
32
+ */
33
+ export declare const generalWithSystemInfo: CollectionSetting[];
34
+ export declare const generalWithSingleLineText: CollectionSetting[];
35
+ /**
36
+ * 1. 创建一个名为 general 的 collection,其包含 m2o / o2m / single select 类型的字段
37
+ */
38
+ export declare const generalWithM2oSingleSelect: CollectionSetting[];
39
+ export declare const tree: CollectionSetting[];
40
+ export declare const generalWithMultiLevelRelationshipFields: CollectionSetting[];