mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 03:01:16 +00:00
test: add some test cases
This commit is contained in:
parent
c27f8019bc
commit
a9f15a7552
@ -161,6 +161,7 @@ export class NodeChildren {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const { document } = node;
|
const { document } = node;
|
||||||
|
/* istanbul ignore next */
|
||||||
if (globalContext.has('editor')) {
|
if (globalContext.has('editor')) {
|
||||||
globalContext.get('editor').emit('node.remove', { node, index: i });
|
globalContext.get('editor').emit('node.remove', { node, index: i });
|
||||||
}
|
}
|
||||||
@ -197,6 +198,7 @@ export class NodeChildren {
|
|||||||
const i = children.indexOf(node);
|
const i = children.indexOf(node);
|
||||||
|
|
||||||
if (node.parent) {
|
if (node.parent) {
|
||||||
|
/* istanbul ignore next */
|
||||||
globalContext.has('editor') &&
|
globalContext.has('editor') &&
|
||||||
globalContext.get('editor').emit('node.remove.topLevel', {
|
globalContext.get('editor').emit('node.remove.topLevel', {
|
||||||
node,
|
node,
|
||||||
@ -229,6 +231,7 @@ export class NodeChildren {
|
|||||||
node,
|
node,
|
||||||
});
|
});
|
||||||
this.emitter.emit('insert', node);
|
this.emitter.emit('insert', node);
|
||||||
|
/* istanbul ignore next */
|
||||||
if (globalContext.has('editor')) {
|
if (globalContext.has('editor')) {
|
||||||
globalContext.get('editor').emit('node.add', { node });
|
globalContext.get('editor').emit('node.add', { node });
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,6 +48,42 @@ describe('NodeChildren 方法测试', () => {
|
|||||||
expect(children.export().length).toBe(2);
|
expect(children.export().length).toBe(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('export - Leaf', () => {
|
||||||
|
const firstBtn = doc.getNode('node_k1ow3cbn')!;
|
||||||
|
firstBtn.parent!.insertAfter({ componentName: 'Leaf', children: 'haha' });
|
||||||
|
const { children } = firstBtn.parent!;
|
||||||
|
|
||||||
|
expect(children.export().length).toBe(3);
|
||||||
|
expect(children.export()[2]).toBe('haha');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('import', () => {
|
||||||
|
const firstBtn = doc.getNode('node_k1ow3cbn')!;
|
||||||
|
const { children } = firstBtn.parent!;
|
||||||
|
|
||||||
|
children.import(children.export());
|
||||||
|
|
||||||
|
expect(children.export().length).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('delete', () => {
|
||||||
|
const firstBtn = doc.getNode('node_k1ow3cbn')!;
|
||||||
|
const leafNode = doc.createNode({ componentName: 'Leaf', children: 'haha' });
|
||||||
|
firstBtn.parent!.insertAfter(leafNode);
|
||||||
|
const { children } = firstBtn.parent!;
|
||||||
|
|
||||||
|
children.delete(leafNode);
|
||||||
|
expect(children.export().length).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('delete - 插入已有的节点', () => {
|
||||||
|
const firstBtn = doc.getNode('node_k1ow3cbn')!;
|
||||||
|
firstBtn.parent!.insertBefore(firstBtn, firstBtn);
|
||||||
|
const { children } = firstBtn.parent!;
|
||||||
|
|
||||||
|
expect(children.export().length).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
it('purge / for of', () => {
|
it('purge / for of', () => {
|
||||||
const firstBtn = doc.getNode('node_k1ow3cbn')!;
|
const firstBtn = doc.getNode('node_k1ow3cbn')!;
|
||||||
const { children } = firstBtn.parent!;
|
const { children } = firstBtn.parent!;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user