Skip to content

Commit c5ffbd5

Browse files
LeoYuanJackLian
authored andcommitted
test: add some unit tests for ComponentMeta
1 parent 058a842 commit c5ffbd5

File tree

21 files changed

+3376
-69
lines changed

21 files changed

+3376
-69
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ lib-cov
3636

3737
# Coverage directory used by tools like istanbul
3838
coverage
39+
coverage-all
3940

4041
# nyc test coverage
4142
.nyc_output

packages/designer/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const jestConfig = {
1010
// // '^.+\\.(js|jsx)$': 'babel-jest',
1111
// },
1212
// testMatch: ['**/document/node/node.test.ts'],
13-
// testMatch: ['**/designer/builtin-hotkey.test.ts'],
13+
// testMatch: ['**/component-meta.test.ts'],
1414
// testMatch: ['**/plugin/plugin-manager.test.ts'],
1515
// testMatch: ['(/tests?/.*(test))\\.[jt]s$'],
1616
transformIgnorePatterns: [

packages/designer/src/component-meta.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
LiveTextEditingConfig,
1414
FieldConfig,
1515
} from '@alilc/lowcode-types';
16-
import { deprecate } from '@alilc/lowcode-utils';
16+
import { deprecate, isRegExp } from '@alilc/lowcode-utils';
1717
import { computed, engineConfig } from '@alilc/lowcode-editor-core';
1818
import EventEmitter from 'events';
1919
import { componentDefaults, legacyIssues } from './transducers';
@@ -31,7 +31,7 @@ import {
3131
IconHidden,
3232
} from './icons';
3333

34-
function ensureAList(list?: string | string[]): string[] | null {
34+
export function ensureAList(list?: string | string[]): string[] | null {
3535
if (!list) {
3636
return null;
3737
}
@@ -47,11 +47,7 @@ function ensureAList(list?: string | string[]): string[] | null {
4747
return list;
4848
}
4949

50-
function isRegExp(obj: any): obj is RegExp {
51-
return obj && obj.test && obj.exec && obj.compile;
52-
}
53-
54-
function buildFilter(rule?: string | string[] | RegExp | NestingFilter) {
50+
export function buildFilter(rule?: string | string[] | RegExp | NestingFilter) {
5551
if (!rule) {
5652
return null;
5753
}
@@ -145,9 +141,8 @@ export class ComponentMeta {
145141
private _isMinimalRenderUnit?: boolean;
146142

147143
get title(): string | I18nData | ReactElement {
148-
// TODO: 标记下。这块需要康师傅加一下API,页面正常渲染。
149144
// string | i18nData | ReactElement
150-
// TitleConfig title.label
145+
// TitleConfig title.label
151146
if (isTitleConfig(this._title)) {
152147
return (this._title.label as any) || this.componentName;
153148
}
@@ -220,10 +215,10 @@ export class ComponentMeta {
220215
collectLiveTextEditing(this.configure);
221216
this._liveTextEditing = liveTextEditing.length > 0 ? liveTextEditing : undefined;
222217

223-
const isTopFiexd = this._transformedMetadata.configure.advanced?.isTopFixed;
218+
const isTopFixed = this._transformedMetadata.configure.advanced?.isTopFixed;
224219

225-
if (isTopFiexd) {
226-
this._isTopFixed = isTopFiexd;
220+
if (isTopFixed) {
221+
this._isTopFixed = isTopFixed;
227222
}
228223

229224
const { configure = {} } = this._transformedMetadata;
@@ -403,6 +398,7 @@ const builtinComponentActions: ComponentAction[] = [
403398
content: {
404399
icon: IconRemove,
405400
title: intlNode('remove'),
401+
/* istanbul ignore next */
406402
action(node: Node) {
407403
node.remove();
408404
},
@@ -414,10 +410,12 @@ const builtinComponentActions: ComponentAction[] = [
414410
content: {
415411
icon: IconHidden,
416412
title: intlNode('hide'),
413+
/* istanbul ignore next */
417414
action(node: Node) {
418415
node.setVisible(false);
419416
},
420417
},
418+
/* istanbul ignore next */
421419
condition: (node: Node) => {
422420
return node.componentMeta.isModal;
423421
},
@@ -428,6 +426,7 @@ const builtinComponentActions: ComponentAction[] = [
428426
content: {
429427
icon: IconClone,
430428
title: intlNode('copy'),
429+
/* istanbul ignore next */
431430
action(node: Node) {
432431
// node.remove();
433432
const { document: doc, parent, index } = node;
@@ -459,10 +458,12 @@ const builtinComponentActions: ComponentAction[] = [
459458
content: {
460459
icon: IconLock, // 锁定 icon
461460
title: intlNode('lock'),
461+
/* istanbul ignore next */
462462
action(node: Node) {
463463
node.lock();
464464
},
465465
},
466+
/* istanbul ignore next */
466467
condition: (node: Node) => {
467468
return engineConfig.get('enableCanvasLock', false) && node.isContainer() && !node.isLocked;
468469
},
@@ -473,10 +474,12 @@ const builtinComponentActions: ComponentAction[] = [
473474
content: {
474475
icon: IconUnlock, // 解锁 icon
475476
title: intlNode('unlock'),
477+
/* istanbul ignore next */
476478
action(node: Node) {
477479
node.lock(false);
478480
},
479481
},
482+
/* istanbul ignore next */
480483
condition: (node: Node) => {
481484
return engineConfig.get('enableCanvasLock', false) && node.isContainer() && node.isLocked;
482485
},

0 commit comments

Comments
 (0)