refactor(test): 移除 editor 单元测试中冗余的 vi.mock 覆盖

依赖 importActual 保留真实实现即可,无需再 mock SideItemKey、NodeType 等常量。
This commit is contained in:
roymondchen 2026-07-30 14:58:36 +08:00
parent b85eaa9452
commit c4b98e3257
14 changed files with 0 additions and 94 deletions

View File

@ -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 {

View File

@ -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;

View File

@ -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__' };

View File

@ -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 {

View File

@ -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));
},
};
});

View File

@ -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' }] });

View File

@ -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',

View File

@ -144,7 +144,6 @@ vi.mock('@tmagic/utils', async () => {
...actual,
getDepNodeIds: vi.fn(() => []),
getNodes: vi.fn(() => []),
isValueIncludeDataSource: vi.fn((v: any) => /\$\{/.test(String(v))),
};
});

View File

@ -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(),

View File

@ -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) {

View File

@ -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);

View File

@ -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(),

View File

@ -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',

View File

@ -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(() => []),