@nocobase/test 0.16.0-alpha.6 → 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,6 +125,7 @@ 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>;
@@ -125,9 +135,11 @@ export declare const test: import("@playwright/test").TestType<import("@playwrig
125
135
  <T_4 = any>(collectionName: string, data?: any[]): Promise<T_4[]>;
126
136
  };
127
137
  createCollections: (collectionSettings: CollectionSetting | CollectionSetting[]) => Promise<void>;
138
+ deletePage: (pageName: string) => Promise<void>;
128
139
  }, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions> & {
129
140
  /** 只运行在 postgres 数据库中 */
130
141
  pgOnly: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & {
142
+ page: Page;
131
143
  mockPage: (config?: PageConfig) => NocoPage;
132
144
  mockCollections: <T = any>(collectionSettings: CollectionSetting[]) => Promise<T>;
133
145
  mockCollection: <T_1 = any>(collectionSetting: CollectionSetting) => Promise<T_1>;
@@ -137,8 +149,10 @@ export declare const test: import("@playwright/test").TestType<import("@playwrig
137
149
  <T_4 = any>(collectionName: string, data?: any[]): Promise<T_4[]>;
138
150
  };
139
151
  createCollections: (collectionSettings: CollectionSetting | CollectionSetting[]) => Promise<void>;
152
+ deletePage: (pageName: string) => Promise<void>;
140
153
  }, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions> | {
141
154
  (title: string, testFunction: (args: import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & {
155
+ page: Page;
142
156
  mockPage: (config?: PageConfig) => NocoPage;
143
157
  mockCollections: <T = any>(collectionSettings: CollectionSetting[]) => Promise<T>;
144
158
  mockCollection: <T_1 = any>(collectionSetting: CollectionSetting) => Promise<T_1>;
@@ -148,10 +162,12 @@ export declare const test: import("@playwright/test").TestType<import("@playwrig
148
162
  <T_4 = any>(collectionName: string, data?: any[]): Promise<T_4[]>;
149
163
  };
150
164
  createCollections: (collectionSettings: CollectionSetting | CollectionSetting[]) => Promise<void>;
165
+ deletePage: (pageName: string) => Promise<void>;
151
166
  } & import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions, testInfo: import("@playwright/test").TestInfo) => void | Promise<void>): void;
152
167
  (): void;
153
168
  (condition: boolean, description?: string): void;
154
169
  (callback: (args: import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & {
170
+ page: Page;
155
171
  mockPage: (config?: PageConfig) => NocoPage;
156
172
  mockCollections: <T = any>(collectionSettings: CollectionSetting[]) => Promise<T>;
157
173
  mockCollection: <T_1 = any>(collectionSetting: CollectionSetting) => Promise<T_1>;
@@ -161,6 +177,7 @@ export declare const test: import("@playwright/test").TestType<import("@playwrig
161
177
  <T_4 = any>(collectionName: string, data?: any[]): Promise<T_4[]>;
162
178
  };
163
179
  createCollections: (collectionSettings: CollectionSetting | CollectionSetting[]) => Promise<void>;
180
+ deletePage: (pageName: string) => Promise<void>;
164
181
  } & import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions) => boolean, description?: string): void;
165
182
  };
166
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 = [];
@@ -155,6 +165,15 @@ const _test = import_test.test.extend({
155
165
  return result[0];
156
166
  }, "mockRecord");
157
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);
158
177
  }
159
178
  });
160
179
  const test = Object.assign(_test, {
@@ -180,10 +199,26 @@ const updateUidOfPageSchema = /* @__PURE__ */ __name((uiSchema) => {
180
199
  return uiSchema;
181
200
  }, "updateUidOfPageSchema");
182
201
  const createPage = /* @__PURE__ */ __name(async (page, options) => {
183
- const { name, pageSchema } = options || {};
202
+ const { type = "page", url, name, pageSchema } = options || {};
184
203
  const api = await import_test.request.newContext({
185
204
  storageState: require.resolve("../../../../../playwright/.auth/admin.json")
186
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
+ };
187
222
  const state = await api.storageState();
188
223
  const headers = getHeaders(state);
189
224
  const systemSettings = await api.get(`/api/systemSettings:get/1`, {
@@ -201,9 +236,8 @@ const createPage = /* @__PURE__ */ __name(async (page, options) => {
201
236
  version: "2.0",
202
237
  type: "void",
203
238
  title: name || pageUid,
204
- "x-component": "Menu.Item",
239
+ ...typeToSchema[type],
205
240
  "x-decorator": "ACLMenuItemProvider",
206
- "x-component-props": {},
207
241
  "x-server-hooks": [
208
242
  { type: "onSelfCreate", method: "bindMenuToRole" },
209
243
  { type: "onSelfSave", method: "extractTextToLocale" }
@@ -274,9 +308,10 @@ const deleteCollections = /* @__PURE__ */ __name(async (collectionNames) => {
274
308
  }, "deleteCollections");
275
309
  const omitSomeFields = /* @__PURE__ */ __name((collectionSettings) => {
276
310
  return collectionSettings.map((collection) => {
311
+ var _a;
277
312
  return {
278
313
  ...import_lodash.default.omit(collection, ["key"]),
279
- 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"]))
280
315
  };
281
316
  });
282
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[];