mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-06-27 04:39:23 +08:00
test(editor): 修改测试用例
This commit is contained in:
parent
8390ba75be
commit
8676e02f2f
@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="m-editor-page-bar" ref="pageBar">
|
||||
<div class="m-editor-page-bar-item m-editor-page-bar-item-icon" @click="addPage">
|
||||
<div id="m-editor-page-bar-add-icon" class="m-editor-page-bar-item m-editor-page-bar-item-icon" @click="addPage">
|
||||
<el-icon><plus></plus></el-icon>
|
||||
</div>
|
||||
<div v-if="canScroll" class="m-editor-page-bar-item m-editor-page-bar-item-icon" @click="scroll('left')">
|
||||
|
@ -236,7 +236,7 @@ class Editor extends BaseService {
|
||||
|
||||
parentNode?.items?.push(newNode);
|
||||
|
||||
const stage = this.get<StageCore>('stage');
|
||||
const stage = this.get<StageCore | null>('stage');
|
||||
|
||||
await stage?.add({ config: cloneDeep(newNode), root: cloneDeep(this.get('root')) });
|
||||
|
||||
@ -273,17 +273,17 @@ class Editor extends BaseService {
|
||||
if (typeof index !== 'number' || index === -1) throw new Error('找不要删除的节点');
|
||||
|
||||
parent.items?.splice(index, 1);
|
||||
const stage = this.get<StageCore>('stage');
|
||||
const stage = this.get<StageCore | null>('stage');
|
||||
stage?.remove({ id: node.id, root: this.get('root') });
|
||||
|
||||
if (node.type === NodeType.PAGE) {
|
||||
if (root.items[0]) {
|
||||
await this.select(root.items[0]);
|
||||
stage.select(root.items[0].id);
|
||||
stage?.select(root.items[0].id);
|
||||
}
|
||||
} else {
|
||||
await this.select(parent);
|
||||
stage.select(parent.id);
|
||||
stage?.select(parent.id);
|
||||
}
|
||||
|
||||
this.addModifiedNodeId(parent.id);
|
||||
@ -339,7 +339,7 @@ class Editor extends BaseService {
|
||||
|
||||
if (`${newConfig.id}` === `${this.get('node').id}`) {
|
||||
this.set('node', newConfig);
|
||||
this.get<StageCore>('stage')?.update({ config: cloneDeep(newConfig), root: this.get('root') });
|
||||
this.get<StageCore | null>('stage')?.update({ config: cloneDeep(newConfig), root: this.get('root') });
|
||||
}
|
||||
|
||||
if (newConfig.type === NodeType.PAGE) {
|
||||
@ -371,7 +371,7 @@ class Editor extends BaseService {
|
||||
await this.update(parent);
|
||||
await this.select(node);
|
||||
|
||||
this.get<StageCore>('stage')?.update({ config: cloneDeep(node), root: this.get('root') });
|
||||
this.get<StageCore | null>('stage')?.update({ config: cloneDeep(node), root: this.get('root') });
|
||||
|
||||
this.addModifiedNodeId(parent.id);
|
||||
this.pushHistoryState();
|
||||
@ -436,7 +436,7 @@ class Editor extends BaseService {
|
||||
}
|
||||
|
||||
await this.update(node);
|
||||
this.get<StageCore>('stage')?.update({ config: cloneDeep(toRaw(node)), root: this.get('root') });
|
||||
this.get<StageCore | null>('stage')?.update({ config: cloneDeep(toRaw(node)), root: this.get('root') });
|
||||
this.addModifiedNodeId(config.id);
|
||||
this.pushHistoryState();
|
||||
|
||||
@ -461,7 +461,7 @@ class Editor extends BaseService {
|
||||
brothers.splice(index + parseInt(`${offset}`, 10), 0, brothers.splice(index, 1)[0]);
|
||||
}
|
||||
|
||||
this.get<StageCore>('stage')?.update({ config: cloneDeep(toRaw(parent)), root: this.get('root') });
|
||||
this.get<StageCore | null>('stage')?.update({ config: cloneDeep(toRaw(parent)), root: this.get('root') });
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,6 +37,10 @@ const storeState: any = {
|
||||
},
|
||||
};
|
||||
|
||||
const componentListService = {
|
||||
getList: jest.fn(),
|
||||
};
|
||||
|
||||
const editorService = {
|
||||
get: jest.fn((key: string) => storeState[key]),
|
||||
add: jest.fn(),
|
||||
@ -51,6 +55,7 @@ const getWrapper = () =>
|
||||
provide: {
|
||||
services: {
|
||||
editorService,
|
||||
componentListService,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -23,6 +23,14 @@ import { NodeType } from '@tmagic/schema';
|
||||
|
||||
import PageBar from '@editor/layouts/workspace/PageBar.vue';
|
||||
|
||||
globalThis.ResizeObserver =
|
||||
globalThis.ResizeObserver ||
|
||||
jest.fn().mockImplementation(() => ({
|
||||
disconnect: jest.fn(),
|
||||
observe: jest.fn(),
|
||||
unobserve: jest.fn(),
|
||||
}));
|
||||
|
||||
const editorState: Record<string, any> = {
|
||||
root: {
|
||||
items: [{ key: 0, id: 1, name: 'testName', type: NodeType.PAGE }],
|
||||
@ -53,7 +61,7 @@ describe('PageBar', () => {
|
||||
it('新增page', (done) => {
|
||||
const wrapper = getWrapper();
|
||||
setTimeout(async () => {
|
||||
await wrapper.find('i[class="el-icon m-editor-page-bar-menu-add-icon"]').trigger('click');
|
||||
await wrapper.find('#m-editor-page-bar-add-icon').trigger('click');
|
||||
|
||||
expect(editorService.add.mock.calls[0][0]).toEqual({
|
||||
type: NodeType.PAGE,
|
||||
|
Loading…
x
Reference in New Issue
Block a user