GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: add some test cases · terwer/lowcode-engine@f3914ed

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/designer
    • jest.config.js
    • src
      • builtin-simulator
        • create-simulator.ts
      • designer
        • designer.ts
      • document
        • document-model.ts
        • node
          • modal-nodes-manager.ts
          • props
            • prop.ts
        • selection.ts
    • tests
      • designer
        • designer.test.ts
      • document
        • document-model
          • document-model.test.ts
        • node
          • modal-nodes-manager.test.ts
          • node-children.test.ts
          • props
            • prop.test.ts
        • selection.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/designer/jest.config.js‎

Copy file name to clipboardExpand all lines: packages/designer/jest.config.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const jestConfig = {
99
// // '^.+\\.(ts|tsx)$': 'ts-jest',
1010
// // '^.+\\.(js|jsx)$': 'babel-jest',
1111
// },
12-
// testMatch: ['**/document/node/node.test.ts'],
12+
// testMatch: ['**/node-children.test.ts'],
1313
// testMatch: ['**/history/history.test.ts'],
1414
// testMatch: ['**/plugin/plugin-manager.test.ts'],
1515
// testMatch: ['(/tests?/.*(test))\\.[jt]s$'],
@@ -31,6 +31,7 @@ const jestConfig = {
3131
'!src/builtin-simulator/live-editing/live-editing.ts',
3232
'!src/designer/offset-observer.ts',
3333
'!src/designer/clipboard.ts',
34+
'!src/designer/scroller.ts',
3435
'!src/builtin-simulator/host.ts',
3536
'!**/node_modules/**',
3637
'!**/vendor/**',
Collapse file

‎packages/designer/src/builtin-simulator/create-simulator.ts‎

Copy file name to clipboardExpand all lines: packages/designer/src/builtin-simulator/create-simulator.ts
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@ export function createSimulator(
5454
const id = asset.id ? ` data-id="${asset.id}"` : '';
5555
const lv = asset.level || level || AssetLevel.Environment;
5656
if (asset.type === AssetType.JSUrl) {
57-
(scripts[lv] || scripts[AssetLevel.App]).push(
57+
scripts[lv].push(
5858
`<script src="${asset.content}"${id}></script>`,
5959
);
6060
} else if (asset.type === AssetType.JSText) {
61-
(scripts[lv] || scripts[AssetLevel.App]).push(`<script${id}>${asset.content}</script>`);
61+
scripts[lv].push(`<script${id}>${asset.content}</script>`);
6262
} else if (asset.type === AssetType.CSSUrl) {
63-
(styles[lv] || styles[AssetLevel.App]).push(
63+
styles[lv].push(
6464
`<link rel="stylesheet" href="${asset.content}"${id} />`,
6565
);
6666
} else if (asset.type === AssetType.CSSText) {
67-
(styles[lv] || styles[AssetLevel.App]).push(
67+
styles[lv].push(
6868
`<style type="text/css"${id}>${asset.content}</style>`,
6969
);
7070
}
@@ -98,8 +98,9 @@ export function createSimulator(
9898
doc.close();
9999

100100
return new Promise((resolve) => {
101-
if (win.SimulatorRenderer || host.renderer) {
102-
return resolve(win.SimulatorRenderer || host.renderer);
101+
const renderer = win.SimulatorRenderer || host.renderer;
102+
if (renderer) {
103+
return resolve(renderer);
103104
}
104105
const loaded = () => {
105106
resolve(win.SimulatorRenderer || host.renderer);
Collapse file

‎packages/designer/src/designer/designer.ts‎

Copy file name to clipboardExpand all lines: packages/designer/src/designer/designer.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ export class Designer {
420420
}
421421

422422
get(key: string): any {
423-
return this.props ? this.props[key] : null;
423+
return this.props?.[key];
424424
}
425425

426426
@obx.ref private _simulatorComponent?: ComponentType<any>;
Collapse file

‎packages/designer/src/document/document-model.ts‎

Copy file name to clipboardExpand all lines: packages/designer/src/document/document-model.ts
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,10 @@ export class DocumentModel {
220220
if (this.hasNode(schema?.id)) {
221221
schema.id = null;
222222
}
223+
/* istanbul ignore next */
223224
if (schema.id) {
224225
node = this.getNode(schema.id);
226+
// TODO: 底下这几段代码似乎永远都进不去
225227
if (node && node.componentName === schema.componentName) {
226228
if (node.parent) {
227229
node.internalSetParent(null, false);
@@ -239,12 +241,6 @@ export class DocumentModel {
239241
// todo: this.activeNodes?.push(node);
240242
}
241243

242-
const origin = this._nodesMap.get(node.id);
243-
if (origin && origin !== node) {
244-
// almost will not go here, ensure the id is unique
245-
origin.internalSetWillPurge();
246-
}
247-
248244
this._nodesMap.set(node.id, node);
249245
this.nodes.add(node);
250246

@@ -578,6 +574,7 @@ export class DocumentModel {
578574
/**
579575
* @deprecated
580576
*/
577+
/* istanbul ignore next */
581578
getAddonData(name: string) {
582579
const addon = this._addons.find((item) => item.name === name);
583580
if (addon) {
@@ -588,6 +585,7 @@ export class DocumentModel {
588585
/**
589586
* @deprecated
590587
*/
588+
/* istanbul ignore next */
591589
exportAddonData() {
592590
const addons = {};
593591
this._addons.forEach((addon) => {
@@ -604,6 +602,7 @@ export class DocumentModel {
604602
/**
605603
* @deprecated
606604
*/
605+
/* istanbul ignore next */
607606
registerAddon(name: string, exportData: any) {
608607
if (['id', 'params', 'layout'].indexOf(name) > -1) {
609608
throw new Error('addon name cannot be id, params, layout');
@@ -618,6 +617,7 @@ export class DocumentModel {
618617
});
619618
}
620619

620+
/* istanbul ignore next */
621621
acceptRootNodeVisitor(
622622
visitorName = 'default',
623623
visitorFn: (node: RootNode) => any,
@@ -637,6 +637,7 @@ export class DocumentModel {
637637
return visitorResult;
638638
}
639639

640+
/* istanbul ignore next */
640641
getRootNodeVisitor(name: string) {
641642
return this.rootNodeVisitorMap[name];
642643
}
Collapse file

‎packages/designer/src/document/node/modal-nodes-manager.ts‎

Copy file name to clipboardExpand all lines: packages/designer/src/document/node/modal-nodes-manager.ts
+13-20Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { EventEmitter } from 'events';
22
import { Node } from './node';
33
import { DocumentModel } from '../document-model';
44

5-
function getModalNodes(node: Node) {
5+
export function getModalNodes(node: Node) {
66
if (!node) return [];
77
let nodes: any = [];
88
if (node.componentMeta.isModal) {
@@ -40,44 +40,37 @@ export class ModalNodesManager {
4040
];
4141
}
4242

43-
public getModalNodes() {
43+
getModalNodes() {
4444
return this.modalNodes;
4545
}
4646

47-
public getVisibleModalNode() {
48-
const visibleNode = this.modalNodes
49-
? this.modalNodes.find((node: Node) => {
50-
return node.getVisible();
51-
})
52-
: null;
53-
return visibleNode;
47+
getVisibleModalNode() {
48+
return this.getModalNodes().find((node: Node) => node.getVisible());
5449
}
5550

56-
public hideModalNodes() {
57-
if (this.modalNodes) {
58-
this.modalNodes.forEach((node: Node) => {
59-
node.setVisible(false);
60-
});
61-
}
51+
hideModalNodes() {
52+
this.modalNodes.forEach((node: Node) => {
53+
node.setVisible(false);
54+
});
6255
}
6356

64-
public setVisible(node: Node) {
57+
setVisible(node: Node) {
6558
this.hideModalNodes();
6659
node.setVisible(true);
6760
}
6861

69-
public setInvisible(node: Node) {
62+
setInvisible(node: Node) {
7063
node.setVisible(false);
7164
}
7265

73-
public onVisibleChange(func: () => any) {
66+
onVisibleChange(func: () => any) {
7467
this.emitter.on('visibleChange', func);
7568
return () => {
7669
this.emitter.removeListener('visibleChange', func);
7770
};
7871
}
7972

80-
public onModalNodesChange(func: () => any) {
73+
onModalNodesChange(func: () => any) {
8174
this.emitter.on('modalNodesChange', func);
8275
return () => {
8376
this.emitter.removeListener('modalNodesChange', func);
@@ -122,7 +115,7 @@ export class ModalNodesManager {
122115
}
123116
}
124117

125-
public setNodes() {
118+
setNodes() {
126119
const nodes = getModalNodes(this.page.getRoot()!);
127120
this.modalNodes = nodes;
128121
this.modalNodes.forEach((node: Node) => {
Collapse file

‎packages/designer/src/document/node/props/prop.ts‎

Copy file name to clipboardExpand all lines: packages/designer/src/document/node/props/prop.ts
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export class Prop implements IPropParent {
259259
} else {
260260
this._type = 'map';
261261
}
262-
} /* istanbul ignore next */ else {
262+
} else /* istanbul ignore next */ {
263263
this._type = 'expression';
264264
this._value = {
265265
type: 'JSExpression',
@@ -502,6 +502,7 @@ export class Prop implements IPropParent {
502502
*/
503503
@action
504504
delete(prop: Prop): void {
505+
/* istanbul ignore else */
505506
if (this._items) {
506507
const i = this._items.indexOf(prop);
507508
if (i > -1) {
@@ -519,6 +520,7 @@ export class Prop implements IPropParent {
519520
*/
520521
@action
521522
deleteKey(key: string): void {
523+
/* istanbul ignore else */
522524
if (this.maps) {
523525
const prop = this.maps.get(key);
524526
if (prop) {
Collapse file

‎packages/designer/src/document/selection.ts‎

Copy file name to clipboardExpand all lines: packages/designer/src/document/selection.ts
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ export class Selection {
150150
} else if (n === PositionNO.ContainedBy) {
151151
// node contains nodes[i], delete nodes[i]
152152
nodes.splice(i, 1);
153-
} else {
154-
isTop = false;
155153
}
156154
}
157155
// node is top item, push to nodes
Collapse file

‎packages/designer/tests/designer/designer.test.ts‎

Copy file name to clipboardExpand all lines: packages/designer/tests/designer/designer.test.ts
+76Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,18 @@ describe('Designer 测试', () => {
273273
expect(designer._componentMetasMap.has('Div')).toBeTruthy();
274274
const { editor: editorFromDesigner2, ...others2 } = designer.props;
275275
expect(others2).toEqual(updatedProps);
276+
277+
// 第三次设置 props,跟第二次值一样,for 覆盖率测试
278+
const updatedProps2 = updatedProps;
279+
designer.setProps(updatedProps2);
280+
281+
expect(designer.simulatorComponent).toEqual({ isSimulatorComp2: true });
282+
expect(designer.simulatorProps).toEqual({ designMode: 'live' });
283+
expect(designer.suspensed).toBeFalsy();
284+
expect(designer._componentMetasMap.has('Button')).toBeTruthy();
285+
expect(designer._componentMetasMap.has('Div')).toBeTruthy();
286+
const { editor: editorFromDesigner3, ...others3 } = designer.props;
287+
expect(others3).toEqual(updatedProps);
276288
});
277289

278290
describe('getSuitableInsertion', () => {
@@ -313,6 +325,70 @@ describe('Designer 测试', () => {
313325
});
314326
});
315327

328+
it('getComponentMetasMap', () => {
329+
designer.createComponentMeta({
330+
componentName: 'Div',
331+
title: '容器',
332+
docUrl: 'http://gitlab.alibaba-inc.com/vision-components/vc-block/blob/master/README.md',
333+
devMode: 'procode',
334+
tags: ['布局'],
335+
});
336+
337+
expect(designer.getComponentMetasMap().get('Div')).not.toBeUndefined();
338+
});
339+
340+
it('refreshComponentMetasMap', () => {
341+
designer.createComponentMeta({
342+
componentName: 'Div',
343+
title: '容器',
344+
docUrl: 'http://gitlab.alibaba-inc.com/vision-components/vc-block/blob/master/README.md',
345+
devMode: 'procode',
346+
tags: ['布局'],
347+
});
348+
349+
const originalMetasMap = designer.getComponentMetasMap();
350+
designer.refreshComponentMetasMap();
351+
352+
expect(originalMetasMap).not.toBe(designer.getComponentMetasMap());
353+
});
354+
355+
describe('loadIncrementalAssets', () => {
356+
it('components && packages', async () => {
357+
editor.set('assets', { components: [], packages: [] });
358+
const fn = jest.fn();
359+
360+
project.mountSimulator({
361+
setupComponents: fn,
362+
});
363+
await designer.loadIncrementalAssets({
364+
components: [{
365+
componentName: 'Div2',
366+
title: '容器',
367+
docUrl: 'http://gitlab.alibaba-inc.com/vision-components/vc-block/blob/master/README.md',
368+
devMode: 'proCode',
369+
tags: ['布局'],
370+
}],
371+
packages: [],
372+
});
373+
374+
const comps = editor.get('assets').components;
375+
expect(comps).toHaveLength(1);
376+
expect(fn).toHaveBeenCalled();
377+
});
378+
379+
it('no components && packages', async () => {
380+
editor.set('assets', { components: [], packages: [] });
381+
const fn = jest.fn();
382+
383+
project.mountSimulator({
384+
setupComponents: fn,
385+
});
386+
await designer.loadIncrementalAssets({});
387+
388+
expect(fn).not.toHaveBeenCalled();
389+
});
390+
});
391+
316392
it('createLocation / clearLocation', () => {
317393
const mockTarget = {
318394
document: doc,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.