test: add some test cases

This commit is contained in:
LeoYuan 袁力皓 2022-08-09 20:02:04 +08:00 committed by 刘菊萍(絮黎)
parent c27f8019bc
commit a9f15a7552
2 changed files with 39 additions and 0 deletions

View File

@ -161,6 +161,7 @@ export class NodeChildren {
}
}
const { document } = node;
/* istanbul ignore next */
if (globalContext.has('editor')) {
globalContext.get('editor').emit('node.remove', { node, index: i });
}
@ -197,6 +198,7 @@ export class NodeChildren {
const i = children.indexOf(node);
if (node.parent) {
/* istanbul ignore next */
globalContext.has('editor') &&
globalContext.get('editor').emit('node.remove.topLevel', {
node,
@ -229,6 +231,7 @@ export class NodeChildren {
node,
});
this.emitter.emit('insert', node);
/* istanbul ignore next */
if (globalContext.has('editor')) {
globalContext.get('editor').emit('node.add', { node });
}

View File

@ -48,6 +48,42 @@ describe('NodeChildren 方法测试', () => {
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', () => {
const firstBtn = doc.getNode('node_k1ow3cbn')!;
const { children } = firstBtn.parent!;