fix: 修复 prop.remove 在只有一个属性时无法删除的 bug

refactor(test): 补充 project 部分的单测
This commit is contained in:
力皓 2020-12-14 09:39:28 +08:00
parent b647ebc461
commit 037ecfd114
19 changed files with 339 additions and 76 deletions

View File

@ -14,8 +14,8 @@
"clean": "rm -rf ./packages/*/lib ./packages/*/es ./packages/*/dist ./packages/*/build",
"lint": "eslint --ext .ts,.tsx,.js,.jsx ./ --quiet",
"lint:fix": "eslint --ext .ts,.tsx,.js,.jsx ./ --quiet --fix",
"pub": "lerna publish --force-publish --cd-version patch",
"pubbeta": "lerna publish --force-publish --cd-version prerelease --npm-tag beta --preid beta",
"pub": "lerna publish --force-publish --cd-version patch --message \"chore(release): publish %v\"",
"pubbeta": "lerna publish --force-publish --cd-version prerelease --npm-tag beta --preid beta --message \"chore(release): publish %v\"",
"setup": "./scripts/setup.sh",
"start": "./scripts/start.sh",
"start:server": "./scripts/start-server.sh",

View File

@ -15,7 +15,7 @@ module.exports = {
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
collectCoverage: false,
collectCoverageFrom: [
'src/**/*.{ts,tsx}',
'src/**/*.ts',
'!src/**/*.d.ts',
'!src/icons/**',
'!src/locale/**',

View File

@ -102,7 +102,7 @@ export class SettingPropEntry implements SettingEntry {
}
const propName = this.path.join('.');
let l = this.nodes.length;
while (l-- > 1) {
while (l-- > 0) {
this.nodes[l].getProp(propName)?.remove();
}
}

View File

@ -198,9 +198,7 @@ export class Project {
}
return null;
}
if (isDocumentModel(doc)) {
} else if (isDocumentModel(doc)) {
return doc.open();
} else if (isPageSchema(doc)) {
// 暂时注释掉,影响了 diff 功能

View File

@ -36,7 +36,7 @@ describe('host 测试', () => {
expect(host.currentDocument).toBe(designer.project.currentDocument);
expect(host.renderEnv).toBe('default');
expect(host.device).toBe('default');
expect(host.deviceClassName).toBeUndefined;
expect(host.deviceClassName).toBeUndefined();
host.setProps({
renderEnv: 'rax',
device: 'mobile',

View File

@ -11,13 +11,13 @@ import {
describe('builtin-simulator/utils/path 测试', () => {
it('isPackagePath', () => {
expect(isPackagePath('a')).toBeTruthy;
expect(isPackagePath('@ali/a')).toBeTruthy;
expect(isPackagePath('@alife/a')).toBeTruthy;
expect(isPackagePath('a.b')).toBeTruthy;
expect(isPackagePath('./a')).toBeFalsy;
expect(isPackagePath('../a')).toBeFalsy;
expect(isPackagePath('/a')).toBeFalsy;
expect(isPackagePath('a')).toBeTruthy();
expect(isPackagePath('@ali/a')).toBeTruthy();
expect(isPackagePath('@alife/a')).toBeTruthy();
expect(isPackagePath('a.b')).toBeTruthy();
expect(isPackagePath('./a')).toBeFalsy();
expect(isPackagePath('../a')).toBeFalsy();
expect(isPackagePath('/a')).toBeFalsy();
});
it('toTitleCase', () => {

View File

@ -16,6 +16,6 @@ import { isSimulatorRenderer } from '../../src/builtin-simulator/renderer';
describe('renderer 测试', () => {
it('renderer', () => {
expect(isSimulatorRenderer(getMockRenderer())).toBeTruthy;
expect(isSimulatorRenderer(getMockRenderer())).toBeTruthy();
})
});

View File

@ -31,7 +31,7 @@ describe('快捷键测试', () => {
let event = new KeyboardEvent('keydown', { keyCode: 39 });
document.dispatchEvent(event);
expect(designer.currentSelection?.selected.includes('node_k1ow3cbl')).toBeTruthy;
expect(designer.currentSelection?.selected.includes('node_k1ow3cbl')).toBeTruthy();
});
it('left', () => {
@ -41,7 +41,7 @@ describe('快捷键测试', () => {
let event = new KeyboardEvent('keydown', { keyCode: 37 });
document.dispatchEvent(event);
expect(designer.currentSelection?.selected.includes('node_k1ow3cbj')).toBeTruthy;
expect(designer.currentSelection?.selected.includes('node_k1ow3cbj')).toBeTruthy();
});
it('down', () => {
@ -51,7 +51,7 @@ describe('快捷键测试', () => {
let event = new KeyboardEvent('keydown', { keyCode: 40 });
document.dispatchEvent(event);
expect(designer.currentSelection?.selected.includes('node_k1ow3cbm')).toBeTruthy;
expect(designer.currentSelection?.selected.includes('node_k1ow3cbo')).toBeTruthy();
});
it('up', () => {
@ -61,7 +61,7 @@ describe('快捷键测试', () => {
let event = new KeyboardEvent('keydown', { keyCode: 38 });
document.dispatchEvent(event);
expect(designer.currentSelection?.selected.includes('node_k1ow3cbl')).toBeTruthy;
expect(designer.currentSelection?.selected.includes('node_k1ow3cbl')).toBeTruthy();
});
// 跟右侧节点调换位置
@ -178,7 +178,7 @@ describe('快捷键测试', () => {
const firstCardNode = designer.currentDocument?.getNode('node_k1ow3cbp')!;
firstCardNode.select();
expect(designer.currentSelection!.selected.includes('node_k1ow3cbp')).toBeTruthy;
expect(designer.currentSelection!.selected.includes('node_k1ow3cbp')).toBeTruthy();
let event = new KeyboardEvent('keydown', { keyCode: 27 });
document.dispatchEvent(event);
@ -197,6 +197,6 @@ describe('快捷键测试', () => {
let event = new KeyboardEvent('keydown', { keyCode: 46 });
document.dispatchEvent(event);
expect(secondButtonNode.prevSibling).toBeNull;
expect(secondButtonNode.prevSibling).toBeNull();
});
});

View File

@ -9,25 +9,28 @@ import formSchema from '../../../fixtures/schema/form';
import settingSchema from '../../fixtures/schema/setting';
import divMeta from '../../fixtures/component-metadata/div';
import { getIdsFromSchema, getNodeFromSchemaById } from '../../utils';
import { DocumentModel } from 'designer/src/document';
const editor = new Editor();
describe('setting-prop-entry 测试', () => {
let designer: Designer;
let doc: DocumentModel;
beforeEach(() => {
designer = new Designer({ editor });
designer.createComponentMeta(divMeta);
doc = designer.project.open(settingSchema);
});
afterEach(() => {
designer._componentMetasMap.clear();
designer = null;
doc.purge();
doc = null;
});
describe('node 构造函数生成 settingEntry', () => {
it('常规方法测试', () => {
designer.createComponentMeta(divMeta);
designer.project.open(settingSchema);
const { currentDocument } = designer.project;
const divNode = currentDocument?.getNode('div');
const divNode = doc?.getNode('div');
const { settingEntry } = divNode!;
const behaviorProp = settingEntry.getProp('behavior');
@ -35,10 +38,30 @@ describe('setting-prop-entry 测试', () => {
expect(behaviorProp.props).toBe(settingEntry);
expect(behaviorProp.getName()).toBe('behavior');
expect(behaviorProp.getKey()).toBe('behavior');
expect(behaviorProp.isIgnore()).toBeFalsy;
expect(behaviorProp.isIgnore()).toBeFalsy();
behaviorProp.setKey('behavior2');
expect(behaviorProp.getKey()).toBe('behavior2');
behaviorProp.setKey('behavior');
expect(behaviorProp.getNode()).toBe(divNode);
expect(behaviorProp.getId().startsWith('entry')).toBeTruthy();
expect(behaviorProp.designer).toBe(designer);
expect(behaviorProp.isSingle).toBeTruthy();
expect(behaviorProp.isMultiple).toBeFalsy();
expect(behaviorProp.isGroup).toBeFalsy();
expect(behaviorProp.isSameComponent).toBeTruthy();
expect(typeof settingEntry.getValue).toBe('function');
settingEntry.getValue();
behaviorProp.setExtraPropValue('extraPropA', 'heihei');
expect(behaviorProp.getExtraPropValue('extraPropA', 'heihei'));
});
it('setValue / getValue', () => {
const divNode = doc?.getNode('div');
const { settingEntry } = divNode!;
const behaviorProp = settingEntry.getProp('behavior');
expect(behaviorProp.getValue()).toBe('NORMAL');
expect(behaviorProp.getMockOrValue()).toBe('NORMAL');
@ -50,25 +73,12 @@ describe('setting-prop-entry 测试', () => {
expect(behaviorProp.getValue()).toBe('NORMAL');
behaviorProp.clearValue();
behaviorProp.clearPropValue();
expect(settingEntry.getProp('behavior').getValue()).toBeUndefined;
expect(behaviorProp.getValue()).toBeUndefined();
behaviorProp.setValue('LARGE');
expect(behaviorProp.getValue()).toBe('LARGE');
behaviorProp.remove();
expect(settingEntry.getProp('behavior').getValue()).toBeUndefined;
expect(behaviorProp.getNode()).toBe(divNode);
expect(behaviorProp.getId().startsWith('entry')).toBeTruthy;
expect(behaviorProp.designer).toBe(designer);
expect(behaviorProp.isSingle).toBeTruthy;
expect(behaviorProp.isMultiple).toBeFalsy;
expect(behaviorProp.isGroup).toBeFalsy;
expect(behaviorProp.isSameComponent).toBeTruthy;
expect(typeof settingEntry.getValue).toBe('function');
settingEntry.getValue();
behaviorProp.setExtraPropValue('extraPropA', 'heihei');
expect(behaviorProp.getExtraPropValue('extraPropA', 'heihei'));
expect(divNode?.getProp('behavior').getValue()).toBeUndefined();
});
it.skip('type: group 场景测试', () => {
@ -83,14 +93,14 @@ describe('setting-prop-entry 测试', () => {
const { settingEntry } = divNode!;
const customClassNameProp = settingEntry.getProp('customClassName');
expect(customClassNameProp.isUseVariable()).toBeTruthy;
expect(customClassNameProp.useVariable).toBeTruthy;
expect(customClassNameProp.isUseVariable()).toBeTruthy();
expect(customClassNameProp.useVariable).toBeTruthy();
expect(customClassNameProp.getValue()).toEqual({
type: 'JSExpression',
value: 'getFromSomewhere()'
});
expect(customClassNameProp.getMockOrValue()).toBeUndefined;
expect(customClassNameProp.getMockOrValue()).toBeUndefined();
expect(customClassNameProp.getVariableValue()).toBe('getFromSomewhere()');
customClassNameProp.setVariableValue('xxx');
expect(customClassNameProp.getVariableValue()).toBe('xxx');

View File

@ -38,7 +38,7 @@ describe('setting-top-entry 测试', () => {
settingEntry.getProp('behavior').setValue('SMALL');
expect(settingEntry.getPropValue('behavior')).toBe('SMALL');
settingEntry.clearPropValue('behavior');
expect(settingEntry.getPropValue('behavior')).toBeUndefined;
expect(settingEntry.getPropValue('behavior')).toBeUndefined();
expect(settingEntry.getPropValue('fieldId')).toBe('div_k1ow3h1o');
settingEntry.setPropValue('fieldId', 'div_k1ow3h1o_new');
@ -67,9 +67,9 @@ describe('setting-top-entry 测试', () => {
expect(settingEntry.getId()).toBe('div');
expect(settingEntry.first).toBe(divNode);
expect(settingEntry.designer).toBe(designer);
expect(settingEntry.isSingle).toBeTruthy;
expect(settingEntry.isMultiple).toBeFalsy;
expect(settingEntry.isSameComponent).toBeTruthy;
expect(settingEntry.isSingle).toBeTruthy();
expect(settingEntry.isMultiple).toBeFalsy();
expect(settingEntry.isSameComponent).toBeTruthy();
expect(typeof settingEntry.getValue).toBe('function');
settingEntry.getValue();
@ -122,9 +122,9 @@ describe('setting-top-entry 测试', () => {
const divNode2 = currentDocument?.getNode('div2');
const settingEntry = designer.createSettingEntry([divNode, divNode2]);
expect(settingEntry.isMultiple).toBeTruthy;
expect(settingEntry.isSameComponent).toBeTruthy;
expect(settingEntry.isSingle).toBeFalsy;
expect(settingEntry.isMultiple).toBeTruthy();
expect(settingEntry.isSameComponent).toBeTruthy();
expect(settingEntry.isSingle).toBeFalsy();
expect(settingEntry.getPropValue('behavior')).toBe('NORMAL');
expect(settingEntry.getProp('behavior').getValue()).toBe('NORMAL');
@ -142,10 +142,10 @@ describe('setting-top-entry 测试', () => {
expect(divNode2?.getPropValue('behavior')).toBe('SMALL');
settingEntry.clearPropValue('behavior');
expect(settingEntry.getPropValue('behavior')).toBeUndefined;
expect(settingEntry.getPropValue('behavior')).toBeUndefined();
// 多个 node 都被成功设值
expect(divNode?.getPropValue('behavior')).toBeUndefined;
expect(divNode2?.getPropValue('behavior')).toBeUndefined;
expect(divNode?.getPropValue('behavior')).toBeUndefined();
expect(divNode2?.getPropValue('behavior')).toBeUndefined();
expect(settingEntry.getPropValue('fieldId')).toBe('div_k1ow3h1o');
settingEntry.setPropValue('fieldId', 'div_k1ow3h1o_new');
@ -163,9 +163,9 @@ describe('setting-top-entry 测试', () => {
const testNode = currentDocument?.getNode('test');
const settingEntry = designer.createSettingEntry([divNode, testNode]);
expect(settingEntry.isMultiple).toBeTruthy;
expect(settingEntry.isSameComponent).toBeFalsy;
expect(settingEntry.isSingle).toBeFalsy;
expect(settingEntry.isMultiple).toBeTruthy();
expect(settingEntry.isSameComponent).toBeFalsy();
expect(settingEntry.isSingle).toBeFalsy();
// 不同类型的 node 场景下,理论上从页面上已没有修改属性的方法调用,所以此处不再断言各设值方法
// 思考:假如以后面向其他场景,比如用户用 API 强行调用,是否需要做健壮性保护?

View File

@ -28,8 +28,8 @@ describe('document-model 测试', () => {
expect(doc.rootNode.id).toBe('root');
expect(doc.currentRoot).toBe(doc.rootNode);
expect(doc.root).toBe(doc.rootNode);
expect(doc.modalNode).toBeUndefined;
expect(doc.isBlank()).toBeTruthy;
expect(doc.modalNode).toBeUndefined();
expect(doc.isBlank()).toBeFalsy();
expect(doc.schema).toEqual({
componentName: 'Page',
id: 'root',
@ -65,10 +65,10 @@ describe('document-model 测试', () => {
doc.selection.select('form');
doc.wrapWith({ componentName: 'Wrap' });
expect(doc.getNode('form').parent.componentName).toBe('Wrap');
expect(doc.wrapWith({ componentName: 'Leaf' })).toBeNull;
expect(doc.wrapWith({ componentName: 'Leaf' })).toBeNull();
// fileName
expect(doc.fileName).toBeUndefined;
expect(doc.fileName).toBeTruthy();
doc.fileName = 'fileName';
expect(doc.fileName).toBe('fileName');

View File

@ -60,7 +60,7 @@ describe('schema 生成节点模型测试', () => {
const pageNode = currentDocument?.getNode('page');
expect(pageNode?.getComponentName()).toBe('Page');
expect(pageNode?.getIcon()).toBeUndefined;
expect(pageNode?.getIcon()).toBeUndefined();
const exportSchema = currentDocument?.export(1);
expect(getIdsFromSchema(exportSchema).length).toBe(expectedNodeCnt);
@ -104,8 +104,8 @@ describe('schema 生成节点模型测试', () => {
expect(textFieldNode?.getZLevelTop(0)).toEqual(pageNode);
// 异常情况
expect(textFieldNode?.getZLevelTop(8)).toBeNull;
expect(textFieldNode?.getZLevelTop(-1)).toBeNull;
expect(textFieldNode?.getZLevelTop(8)).toBeNull();
expect(textFieldNode?.getZLevelTop(-1)).toBeNull();
});
it('基本的节点模型初始化,节点父子、兄弟相关方法', () => {

View File

@ -363,7 +363,7 @@ describe('Node 方法测试', () => {
firstBtn.hover(true);
expect(doc.designer.detecting.current).toBe(firstBtn);
firstBtn.hover(false);
expect(doc.designer.detecting.current).toBeNull;
expect(doc.designer.detecting.current).toBeNull();
});
it('getRect', () => {

View File

@ -0,0 +1,37 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`valueToSource 1`] = `"1"`;
exports[`valueToSource 2`] = `"true"`;
exports[`valueToSource 3`] = `"[]"`;
exports[`valueToSource 4`] = `
"[{
\\"a\\": 1
}]"
`;
exports[`valueToSource 5`] = `
"{
\\"a\\": 1
}"
`;
exports[`valueToSource 6`] = `"null"`;
exports[`valueToSource 7`] = `"function haha() {}"`;
exports[`valueToSource 8`] = `"new Map()"`;
exports[`valueToSource 9`] = `"new Set()"`;
exports[`valueToSource 10`] = `"/haha/"`;
exports[`valueToSource 11`] = `"\\"hahah\\""`;
exports[`valueToSource 12`] = `"Symbol(\\"haha\\")"`;
exports[`valueToSource 13`] = `"undefined"`;
exports[`valueToSource 14`] = `"new Date(\\"2020-12-11T10:03:18.520Z\\")"`;

View File

@ -0,0 +1,28 @@
import '../../../fixtures/silent-console';
import { getSource, valueToSource } from '../../../../src/document/node/props/value-to-source';
it('valueToSource', () => {
expect(valueToSource(1)).toMatchSnapshot();
expect(valueToSource(true)).toMatchSnapshot();
expect(valueToSource([])).toMatchSnapshot();
expect(valueToSource([{ a: 1 }])).toMatchSnapshot();
expect(valueToSource({ a: 1 })).toMatchSnapshot();
expect(valueToSource(null)).toMatchSnapshot();
expect(valueToSource(function haha() {})).toMatchSnapshot();
expect(valueToSource(new Map())).toMatchSnapshot();
expect(valueToSource(new Set())).toMatchSnapshot();
expect(valueToSource(/haha/)).toMatchSnapshot();
expect(valueToSource('hahah')).toMatchSnapshot();
expect(valueToSource(Symbol('haha'))).toMatchSnapshot();
expect(valueToSource()).toMatchSnapshot();
expect(valueToSource(new Date(1607680998520))).toMatchSnapshot();
});
it('getSource', () => {
expect(getSource({ __source: { a: 1 }})).toEqual({ a: 1 });
expect(getSource()).toBe('');
const value = { abc: 1 };
getSource(value);
expect(value).toHaveProperty('__source');
expect(getSource(1)).toBe('1');
});

View File

@ -0,0 +1,6 @@
export const mockConsoleError = jest.fn();
export const mockConsoleWarn = jest.fn();
// const mockConsoleInfo = jest.fn();
console.error = mockConsoleError;
console.warn = mockConsoleWarn;

View File

@ -25,15 +25,15 @@ beforeAll(() => {
describe('组件元数据处理', () => {
it('构造函数', () => {
const meta = new ComponentMeta(designer, divMeta);
expect(meta.isContainer).toBeTruthy;
expect(isComponentMeta(meta)).toBeTruthy;
expect(meta.acceptable).toBeTruthy;
expect(meta.isRootComponent()).toBeTruthy;
expect(meta.isModal).toBeFalsy;
expect(meta.rootSelector).toBeUndefined;
expect(meta.liveTextEditing).toBeUndefined;
expect(meta.descriptor).toBeUndefined;
expect(meta.icon).toBeUndefined;
expect(meta.isContainer).toBeTruthy();
expect(isComponentMeta(meta)).toBeTruthy();
expect(meta.acceptable).toBeFalsy();
expect(meta.isRootComponent()).toBeFalsy();
expect(meta.isModal).toBeFalsy();
expect(meta.rootSelector).toBeUndefined();
expect(meta.liveTextEditing).toBeUndefined();
expect(meta.descriptor).toBeUndefined();
expect(typeof meta.icon).toBe('function');
expect(meta.getMetadata().title).toBe('容器');
expect(meta.title).toEqual({ type: 'i18n', 'en-US': 'Div', 'zh-CN': '容器' });

View File

@ -0,0 +1,182 @@
import set from 'lodash/set';
import cloneDeep from 'lodash/cloneDeep';
import '../fixtures/window';
import { Editor } from '@ali/lowcode-editor-core';
import { Project } from '../../src/project/project';
import { DocumentModel } from '../../src/document/document-model';
import { Node } from '../../src/document/node/node';
import { Designer } from '../../src/designer/designer';
import formSchema from '../fixtures/schema/form';
import { getIdsFromSchema, getNodeFromSchemaById } from '../utils';
describe.only('Project 方法测试', () => {
let editor: Editor;
let designer: Designer;
let project: Project;
let doc: DocumentModel;
beforeEach(() => {
editor = new Editor();
designer = new Designer({ editor });
project = designer.project;
doc = new DocumentModel(project, formSchema);
});
afterEach(() => {
project.unload();
designer.purge();
editor = null;
designer = null;
project = null;
});
it('simulator', () => {
const mockedSimulator = { isSimulator: true, a: 1 };
project.mountSimulator(mockedSimulator);
expect(project.simulator).toEqual(mockedSimulator);
});
it('config / get / set', () => {
const mockedConfig = { version: '1.0.0', componentsTree: [] };
project.config = mockedConfig;
expect(project.config).toEqual(mockedConfig);
const mockedConfig2 = { version: '2.0.0', componentsTree: [] };
project.set('config', mockedConfig2);
expect(project.get('config')).toEqual(mockedConfig2);
project.set('version', '2.0.0');
expect(project.get('version')).toBe('2.0.0');
});
it('load', () => {
project.load({
componentsTree: [{
componentName: 'Page',
fileName: 'f1',
}]
}, 'f1');
expect(project.currentDocument?.fileName).toBe('f1');
});
it('setSchema', () => {
project.load({
componentsTree: [{
componentName: 'Page',
fileName: 'f1',
}]
}, true);
project.setSchema({
componentsTree: [{
componentName: 'Page',
props: { a: 1 },
}]
});
expect(project.currentDocument?.rootNode?.propsData).toEqual({ a: 1 });
});
it('open / getDocument / checkExclusive', () => {
project.load({
componentsTree: [{
componentName: 'Page',
fileName: 'f1',
}]
});
const doc1 = project.createDocument({
componentName: 'Page',
fileName: 'f2',
});
const doc2 = project.createDocument({
componentName: 'Page',
fileName: 'f3',
});
project.open();
project.open('f2');
expect(project.currentDocument).toBe(doc1);
project.open('f3');
expect(project.currentDocument).toBe(doc2);
project.open('f1');
expect(project.currentDocument?.fileName).toBe('f1');
expect(project.open('not-existing')).toBeNull();
project.open(doc2);
expect(project.currentDocument).toBe(doc2);
const doc3 = project.open({
componentName: 'Page',
fileName: 'f4',
});
expect(project.currentDocument).toBe(doc3);
expect(project.documents.length).toBe(4);
expect(project.getDocument(project.currentDocument?.id)).toBe(doc3);
expect(project.checkExclusive(project.currentDocument));
expect(project.documents[0].opened).toBeTruthy();
expect(project.documents[1].opened).toBeTruthy();
expect(project.documents[2].opened).toBeTruthy();
expect(project.documents[3].opened).toBeTruthy();
expect(project.documents[0].suspensed).toBeTruthy();
expect(project.documents[1].suspensed).toBeTruthy();
expect(project.documents[2].suspensed).toBeTruthy();
expect(project.documents[3].suspensed).toBeFalsy();
project.closeOthers(project.currentDocument);
expect(project.documents[0].opened).toBeFalsy();
expect(project.documents[1].opened).toBeFalsy();
expect(project.documents[2].opened).toBeFalsy();
expect(project.documents[3].opened).toBeTruthy();
expect(project.documents[0].suspensed).toBeTruthy();
expect(project.documents[1].suspensed).toBeTruthy();
expect(project.documents[2].suspensed).toBeTruthy();
expect(project.documents[3].suspensed).toBeFalsy();
});
it('removeDocument', () => {
const doc1 = project.createDocument({
componentName: 'Page',
fileName: 'f1',
});
project.removeDocument({});
expect(project.documents.length).toBe(1);
});
it('simulatorProps', () => {
designer._simulatorProps = { a: 1 };
expect(project.simulatorProps.a).toBe(1);
designer._simulatorProps = () => ({ a: 1 });
expect(project.simulatorProps.a).toBe(1);
});
it('onCurrentDocumentChange', () => {
const mockedFn = jest.fn();
const off = project.onCurrentDocumentChange(mockedFn);
project.open({
componentName: 'Page',
});
expect(mockedFn).toHaveBeenCalled();
off();
mockedFn.mockClear();
project.open({
componentName: 'Page',
});
expect(mockedFn).not.toHaveBeenCalled();
});
it('setRendererReady / onRendererReady', () => {
const mockedFn = jest.fn();
const off = project.onRendererReady(mockedFn);
project.setRendererReady({ a: 1 });
expect(mockedFn).toHaveBeenCalledWith({ a: 1 });
off();
mockedFn.mockClear();
project.setRendererReady({ a: 1 });
expect(mockedFn).not.toHaveBeenCalled();
});
});

View File

@ -1,7 +1,9 @@
import set from 'lodash/set';
import cloneDeep from 'lodash/cloneDeep';
import '../fixtures/window';
import { Editor } from '@ali/lowcode-editor-core';
import { Project } from '../../src/project/project';
import { DocumentModel } from '../../src/document/document-model';
import { Node } from '../../src/document/node/node';
import { Designer } from '../../src/designer/designer';
import formSchema from '../fixtures/schema/form';
@ -131,4 +133,4 @@ describe('schema 生成节点模型测试', () => {
describe.skip('多 document 测试', () => {
});
});
});