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