mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2026-07-31 18:35:47 +00:00
refactor(test): 移除 editor 单元测试中冗余的 vi.mock 覆盖
依赖 importActual 保留真实实现即可,无需再 mock SideItemKey、NodeType 等常量。
This commit is contained in:
parent
b85eaa9452
commit
c4b98e3257
@ -24,11 +24,6 @@ vi.mock('@editor/hooks/use-services', () => ({
|
||||
useServices: () => ({ codeBlockService, uiService }),
|
||||
}));
|
||||
|
||||
vi.mock('@editor/type', async () => {
|
||||
const actual = await vi.importActual<any>('@editor/type');
|
||||
return { ...actual, SideItemKey: { CODE_BLOCK: 'code-block' } };
|
||||
});
|
||||
|
||||
vi.mock('@tmagic/form', async (importOriginal) => {
|
||||
const actual = await importOriginal<any>();
|
||||
return {
|
||||
|
||||
@ -115,15 +115,6 @@ vi.mock('@tmagic/design', async () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('@tmagic/utils', async () => {
|
||||
const actual = await vi.importActual<any>('@tmagic/utils');
|
||||
return {
|
||||
...actual,
|
||||
getKeysArray: vi.fn((s: string) => s.split('.').filter(Boolean)),
|
||||
isNumber: (v: any) => /^\d+$/.test(String(v)),
|
||||
};
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
inputRef.input = null;
|
||||
|
||||
@ -33,11 +33,6 @@ vi.mock('@editor/utils', async () => {
|
||||
return { ...actual, getFieldType: vi.fn(() => 'string') };
|
||||
});
|
||||
|
||||
vi.mock('@editor/type', async () => {
|
||||
const actual = await vi.importActual<any>('@editor/type');
|
||||
return { ...actual, SideItemKey: { DATA_SOURCE: 'data-source' } };
|
||||
});
|
||||
|
||||
vi.mock('@tmagic/utils', async () => {
|
||||
const actual = await vi.importActual<any>('@tmagic/utils');
|
||||
return { ...actual, DATA_SOURCE_SET_DATA_METHOD_NAME: '__set_data__' };
|
||||
|
||||
@ -21,11 +21,6 @@ vi.mock('@editor/hooks/use-services', () => ({
|
||||
useServices: () => ({ dataSourceService, uiService }),
|
||||
}));
|
||||
|
||||
vi.mock('@editor/type', async () => {
|
||||
const actual = await vi.importActual<any>('@editor/type');
|
||||
return { ...actual, SideItemKey: { DATA_SOURCE: 'data-source' } };
|
||||
});
|
||||
|
||||
vi.mock('@tmagic/form', async (importOriginal) => {
|
||||
const actual = await importOriginal<any>();
|
||||
return {
|
||||
|
||||
@ -96,10 +96,6 @@ vi.mock('@tmagic/utils', async () => {
|
||||
return {
|
||||
...actual,
|
||||
DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX: 'ds_change_',
|
||||
traverseNode: (node: any, fn: any) => {
|
||||
fn(node);
|
||||
node.items?.forEach((c: any) => fn(c));
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@ -44,11 +44,6 @@ vi.mock('@editor/components/Icon.vue', () => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock('@tmagic/core', async () => {
|
||||
const actual = await vi.importActual<any>('@tmagic/core');
|
||||
return { ...actual, NodeType: { PAGE: 'page', PAGE_FRAGMENT: 'page-fragment' } };
|
||||
});
|
||||
|
||||
describe('PageFragmentSelect', () => {
|
||||
test('model[name] 不为空时显示编辑图标', () => {
|
||||
editorService.get.mockReturnValue({ items: [{ id: 'p1', type: 'page-fragment', name: 'A' }] });
|
||||
|
||||
@ -27,11 +27,6 @@ vi.mock('@editor/hooks/use-services', () => ({
|
||||
useServices: () => ({ editorService, uiService, stageOverlayService }),
|
||||
}));
|
||||
|
||||
vi.mock('@tmagic/utils', async () => {
|
||||
const actual = await vi.importActual<any>('@tmagic/utils');
|
||||
return { ...actual, getIdFromEl: () => (el: any) => el?.dataset?.tmagicId };
|
||||
});
|
||||
|
||||
vi.mock('@tmagic/design', () => ({
|
||||
TMagicButton: defineComponent({
|
||||
name: 'TMagicButton',
|
||||
|
||||
@ -144,7 +144,6 @@ vi.mock('@tmagic/utils', async () => {
|
||||
...actual,
|
||||
getDepNodeIds: vi.fn(() => []),
|
||||
getNodes: vi.fn(() => []),
|
||||
isValueIncludeDataSource: vi.fn((v: any) => /\$\{/.test(String(v))),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@ -8,14 +8,6 @@ import { mount } from '@vue/test-utils';
|
||||
|
||||
import AddPageBox from '@editor/layouts/AddPageBox.vue';
|
||||
|
||||
vi.mock('@tmagic/core', async () => {
|
||||
const actual = await vi.importActual<any>('@tmagic/core');
|
||||
return {
|
||||
...actual,
|
||||
NodeType: { PAGE: 'page', PAGE_FRAGMENT: 'page-fragment' },
|
||||
};
|
||||
});
|
||||
|
||||
const editorService = {
|
||||
get: vi.fn((key: string) => (key === 'root' ? { items: [] } : undefined)),
|
||||
add: vi.fn(),
|
||||
|
||||
@ -48,11 +48,6 @@ vi.mock('@editor/components/ToolButton.vue', () => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock('@editor/type', async () => {
|
||||
const actual = await vi.importActual<any>('@editor/type');
|
||||
return { ...actual, ColumnLayout: { LEFT: 'left', CENTER: 'center', RIGHT: 'right' } };
|
||||
});
|
||||
|
||||
class FakeResizeObserver {
|
||||
cb: any;
|
||||
constructor(cb: any) {
|
||||
|
||||
@ -82,20 +82,6 @@ vi.mock('@editor/components/FloatingBox.vue', () => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock('@editor/type', async () => {
|
||||
const actual = await vi.importActual<any>('@editor/type');
|
||||
return {
|
||||
...actual,
|
||||
SideItemKey: {
|
||||
COMPONENT_LIST: 'component-list',
|
||||
LAYER: 'layer',
|
||||
CODE_BLOCK: 'code-block',
|
||||
DATA_SOURCE: 'data-source',
|
||||
},
|
||||
ColumnLayout: { LEFT: 'left', CENTER: 'center', RIGHT: 'right' },
|
||||
};
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
propsService.getDisabledDataSource.mockReturnValue(false);
|
||||
|
||||
@ -35,11 +35,6 @@ vi.mock('@editor/hooks/use-filter', () => ({
|
||||
useFilter: () => ({ filterTextChangeHandler: vi.fn() }),
|
||||
}));
|
||||
|
||||
vi.mock('@tmagic/core', async () => {
|
||||
const actual = await vi.importActual<any>('@tmagic/core');
|
||||
return { ...actual, DepTargetType: { CODE_BLOCK: 'code-block' } };
|
||||
});
|
||||
|
||||
const { messageBoxConfirm, messageError } = vi.hoisted(() => ({
|
||||
messageBoxConfirm: vi.fn(async () => 'confirm'),
|
||||
messageError: vi.fn(),
|
||||
|
||||
@ -32,18 +32,6 @@ vi.mock('@editor/hooks/use-filter', () => ({
|
||||
useFilter: () => ({ filterTextChangeHandler: vi.fn() }),
|
||||
}));
|
||||
|
||||
vi.mock('@tmagic/core', async () => {
|
||||
const actual = await vi.importActual<any>('@tmagic/core');
|
||||
return {
|
||||
...actual,
|
||||
DepTargetType: {
|
||||
DATA_SOURCE: 'data-source',
|
||||
DATA_SOURCE_METHOD: 'data-source-method',
|
||||
DATA_SOURCE_COND: 'data-source-cond',
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('@editor/components/Tree.vue', () => ({
|
||||
default: defineComponent({
|
||||
name: 'TreeStub',
|
||||
|
||||
@ -15,17 +15,6 @@ vi.mock('@editor/utils', async () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('@tmagic/utils', async () => {
|
||||
const actual = await vi.importActual<any>('@tmagic/utils');
|
||||
return {
|
||||
...actual,
|
||||
addClassName: (el: any, _doc: any, className: string) => el?.classList?.add(className),
|
||||
removeClassName: (el: any, ...classNames: string[]) => {
|
||||
classNames.forEach((c) => el?.classList?.remove(c));
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
const makeEditorService = () => ({
|
||||
getNodeInfo: vi.fn(),
|
||||
get: vi.fn(() => []),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user