Skip to content

Commit 229e5d1

Browse files
authored
client unit test (nocobase#4150)
* fix: add more unit test
1 parent b65ee6a commit 229e5d1

File tree

98 files changed

+6467
-508
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+6467
-508
lines changed

.vscode/launch.json

+26
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@
2121
"skipFiles": ["<node_internals>/**"],
2222
"type": "node"
2323
},
24+
{
25+
"type": "node",
26+
"request": "launch",
27+
"name": "Debug Tests watch mode",
28+
"runtimeExecutable": "yarn",
29+
"runtimeArgs": ["run", "test", "-w", "${file}"],
30+
"skipFiles": ["<node_internals>/**", "**/node_modules/**", "**/dist/**", "**/lib/**", "**/es/**"],
31+
"console": "integratedTerminal",
32+
"internalConsoleOptions": "neverOpen",
33+
"windows": {
34+
"runtimeArgs": ["run", "test", "${relativeFile}"]
35+
}
36+
},
2437
{
2538
"type": "node",
2639
"request": "launch",
@@ -34,6 +47,19 @@
3447
"runtimeArgs": ["run", "test", "${relativeFile}"]
3548
}
3649
},
50+
{
51+
"type": "node",
52+
"request": "launch",
53+
"name": "Debug E2E Tests UI",
54+
"runtimeExecutable": "yarn",
55+
"runtimeArgs": ["e2e", "test", "${file}", "--ui"],
56+
"skipFiles": ["<node_internals>/**", "**/node_modules/**", "**/dist/**", "**/lib/**", "**/es/**"],
57+
"console": "integratedTerminal",
58+
"internalConsoleOptions": "neverOpen",
59+
"windows": {
60+
"runtimeArgs": ["e2e", "test", "${fileBasename}", "--ui"]
61+
}
62+
},
3763
{
3864
"type": "node",
3965
"request": "launch",

packages/core/cli/src/util.js

+1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ exports.genTsConfigPaths = function genTsConfigPaths() {
217217
if (packageJsonName === '@nocobase/test') {
218218
paths[`${packageJsonName}/server`] = [`${relativePath}/src/server`];
219219
paths[`${packageJsonName}/e2e`] = [`${relativePath}/src/e2e`];
220+
paths[`${packageJsonName}/web`] = [`${relativePath}/src/web`];
220221
}
221222
if (packageJsonName === '@nocobase/plugin-workflow-test') {
222223
paths[`${packageJsonName}/e2e`] = [`${relativePath}/src/e2e`];

packages/core/client/.dumirc.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import path from 'path';
2+
import glob from 'glob';
3+
import _ from 'lodash'
14
import { getUmiConfig } from '@nocobase/devtools/umiConfig';
25
import { defineConfig } from 'dumi';
36
import { defineThemeConfig } from 'dumi-theme-nocobase';
@@ -8,6 +11,19 @@ const lang = process.env.DOC_LANG;
811

912
console.log('process.env.DOC_LANG', lang);
1013

14+
const componentsDir = 'src/schema-component/antd';
15+
16+
function getComponentsMenu() {
17+
const cwd = path.join(__dirname, componentsDir);
18+
const ignores = ['table/index.md', 'form/index.md']; // 老版本,不需要展示
19+
const files = glob.sync('*/index.md', { cwd, ignore: ignores });
20+
21+
return files.map((file) => ({
22+
title: _.upperFirst(_.camelCase(file.replace('/index.md', ''))),
23+
link: `/components/${file.replace('/index.md', '')}`,
24+
}));
25+
}
26+
1127
export default defineConfig({
1228
hash: true,
1329
alias: {
@@ -21,7 +37,10 @@ export default defineConfig({
2137
cacheDirectoryPath: `node_modules/.docs-client-${lang}-cache`,
2238
outputPath: `./dist/${lang}`,
2339
resolve: {
24-
docDirs: [`./docs/${lang}`]
40+
docDirs: [`./docs/${lang}`],
41+
atomDirs: [
42+
{ type: 'component', dir: componentsDir },
43+
],
2544
},
2645
locales: [
2746
{ id: 'en-US', name: 'English' },
@@ -38,6 +57,10 @@ export default defineConfig({
3857
title: 'API',
3958
link: '/core/application/application',
4059
},
60+
{
61+
title: 'Components',
62+
link: '/components/action',
63+
}
4164
// {
4265
// title: 'UI Schema',
4366
// link: '/ui-schema',
@@ -202,6 +225,7 @@ export default defineConfig({
202225
]
203226
}
204227
],
228+
'/components': getComponentsMenu(),
205229
// '/ui-schema': [
206230
// {
207231
// title: 'Overview',
+212
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
import {
2+
getApp,
3+
getAppComponent,
4+
getAppComponentWithSchemaSettings,
5+
getReadPrettyAppComponent,
6+
withSchema,
7+
} from '@nocobase/test/web';
8+
import {
9+
ACLMenuItemProvider,
10+
AdminLayout,
11+
BlockSchemaComponentPlugin,
12+
CurrentUserProvider,
13+
DocumentTitleProvider,
14+
EditComponent,
15+
EditDefaultValue,
16+
EditOperator,
17+
EditPattern,
18+
EditTitle,
19+
EditTitleField,
20+
EditValidationRules,
21+
FilterFormBlockProvider,
22+
FixedBlock,
23+
Form,
24+
FormBlockProvider,
25+
FormItem,
26+
FormV2,
27+
Grid,
28+
IconPicker,
29+
Input,
30+
InternalAdminLayout,
31+
NanoIDInput,
32+
Page,
33+
RouteSchemaComponent,
34+
SchemaInitializerPlugin,
35+
TableBlockProvider,
36+
TableV2,
37+
VariablesProvider,
38+
fieldSettingsFormItem,
39+
tableActionColumnInitializers,
40+
tableActionInitializers,
41+
tableColumnInitializers,
42+
useTableBlockDecoratorProps,
43+
} from '@nocobase/client';
44+
import { observer } from '@formily/reactive-react';
45+
import React, { ComponentType } from 'react';
46+
import { useField, useFieldSchema } from '@formily/react';
47+
import axios from 'axios';
48+
import { pick } from 'lodash';
49+
50+
const App = getAppComponent({
51+
designable: true,
52+
schema: {
53+
_isJSONSchemaObject: true,
54+
version: '2.0',
55+
type: 'void',
56+
'x-acl-action-props': {
57+
skipScopeCheck: true,
58+
},
59+
'x-acl-action': 'users:create',
60+
'x-decorator': 'FormBlockProvider',
61+
'x-use-decorator-props': 'useCreateFormBlockDecoratorProps',
62+
'x-decorator-props': {
63+
dataSource: 'main',
64+
collection: 'users',
65+
},
66+
'x-component': 'div',
67+
'x-app-version': '0.21.0-alpha.10',
68+
properties: {
69+
'0s3tm262rre': {
70+
_isJSONSchemaObject: true,
71+
version: '2.0',
72+
type: 'void',
73+
'x-component': 'FormV2',
74+
'x-use-component-props': 'useCreateFormBlockProps',
75+
'x-app-version': '0.21.0-alpha.10',
76+
properties: {
77+
grid: {
78+
'x-uid': 'h38s9pa4ik5',
79+
_isJSONSchemaObject: true,
80+
version: '2.0',
81+
type: 'void',
82+
'x-component': 'Grid',
83+
'x-app-version': '0.21.0-alpha.10',
84+
'x-linkage-rules': [
85+
{
86+
condition: {
87+
$and: [
88+
{
89+
username: {
90+
$eq: 'test',
91+
},
92+
},
93+
],
94+
},
95+
actions: [
96+
{
97+
targetFields: ['nickname'],
98+
operator: 'none',
99+
},
100+
],
101+
},
102+
],
103+
properties: {
104+
udpf3e45i3d: {
105+
_isJSONSchemaObject: true,
106+
version: '2.0',
107+
type: 'void',
108+
'x-component': 'Grid.Row',
109+
'x-app-version': '0.21.0-alpha.10',
110+
properties: {
111+
hhc0bsk1roi: {
112+
_isJSONSchemaObject: true,
113+
version: '2.0',
114+
type: 'void',
115+
'x-component': 'Grid.Col',
116+
'x-app-version': '0.21.0-alpha.10',
117+
properties: {
118+
username: {
119+
_isJSONSchemaObject: true,
120+
version: '2.0',
121+
type: 'string',
122+
'x-component': 'CollectionField',
123+
'x-decorator': 'FormItem',
124+
'x-collection-field': 'users.username',
125+
'x-component-props': {},
126+
'x-app-version': '0.21.0-alpha.10',
127+
'x-uid': '71x74r4t4g0',
128+
'x-async': false,
129+
'x-index': 1,
130+
},
131+
},
132+
'x-uid': 'ophjdttgmo5',
133+
'x-async': false,
134+
'x-index': 1,
135+
},
136+
},
137+
'x-uid': 'ta1vq3qr1sd',
138+
'x-async': false,
139+
'x-index': 3,
140+
},
141+
row_rpkxgfonud3: {
142+
_isJSONSchemaObject: true,
143+
version: '2.0',
144+
type: 'void',
145+
'x-component': 'Grid.Row',
146+
'x-index': 4,
147+
properties: {
148+
mmo2k17b0q1: {
149+
_isJSONSchemaObject: true,
150+
version: '2.0',
151+
type: 'void',
152+
'x-component': 'Grid.Col',
153+
properties: {
154+
nickname: {
155+
_isJSONSchemaObject: true,
156+
version: '2.0',
157+
type: 'string',
158+
'x-component': 'CollectionField',
159+
'x-decorator': 'FormItem',
160+
'x-collection-field': 'users.nickname',
161+
'x-component-props': {},
162+
'x-app-version': '0.21.0-alpha.10',
163+
'x-uid': 'bcowga6nzzy',
164+
'x-async': false,
165+
'x-index': 1,
166+
},
167+
},
168+
'x-uid': 'l1awt5at07z',
169+
'x-async': false,
170+
'x-index': 1,
171+
},
172+
},
173+
'x-uid': 'y1tdyhcwhhi',
174+
'x-async': false,
175+
},
176+
},
177+
'x-async': false,
178+
'x-index': 1,
179+
},
180+
'0m1r08p58e9': {
181+
_isJSONSchemaObject: true,
182+
version: '2.0',
183+
type: 'void',
184+
'x-component': 'ActionBar',
185+
'x-component-props': {
186+
layout: 'one-column',
187+
style: {
188+
marginTop: 24,
189+
},
190+
},
191+
'x-app-version': '0.21.0-alpha.10',
192+
'x-uid': 't4gxf0xxaxc',
193+
'x-async': false,
194+
'x-index': 2,
195+
},
196+
},
197+
'x-uid': 'yk2fivh9hgb',
198+
'x-async': false,
199+
'x-index': 1,
200+
},
201+
},
202+
'x-uid': 'aqbi3avt3kb',
203+
'x-async': false,
204+
'x-index': 1,
205+
},
206+
appOptions: {
207+
plugins: [BlockSchemaComponentPlugin],
208+
providers: [VariablesProvider],
209+
},
210+
});
211+
212+
export default App;
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
<code src="./Demo.tsx"></code>

0 commit comments

Comments
 (0)