import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
const requestMocks = vi.hoisted(() => ({
|
get: vi.fn(),
|
post: vi.fn(),
|
}));
|
|
vi.mock('#/api/request', () => ({
|
defHttp: {
|
delete: vi.fn(),
|
get: requestMocks.get,
|
post: requestMocks.post,
|
put: vi.fn(),
|
},
|
}));
|
|
// eslint-disable-next-line import/first -- request module must be mocked before loading the API wrapper.
|
import { confirmRemoveMissing, getTemplateCategoryTree, getTemplateDirectory, switchCurrentTemplate } from './templates';
|
|
describe('eln template API', () => {
|
beforeEach(() => vi.clearAllMocks());
|
|
it('通过数据接口以空 currentId 加载分类树', () => {
|
getTemplateCategoryTree();
|
|
expect(requestMocks.post).toHaveBeenCalledWith({
|
data: { paramList: [{ field: 'currentId', sourceType: 3 }] },
|
url: '/api/system/DataInterface/855428577502430981/Actions/Preview',
|
});
|
});
|
|
it('按模板编号加载目录和可空生效版本摘要', () => {
|
const query = { currentPage: 2, keyword: '无菌', pageSize: 50 };
|
|
getTemplateDirectory(query);
|
|
expect(requestMocks.get).toHaveBeenCalledWith({
|
data: query,
|
url: '/api/eln/templateCatalog/directory',
|
});
|
});
|
|
it('uses lowerCamelCase lifecycle paths', () => {
|
switchCurrentTemplate('TPL-1', 'template-1', 'switch');
|
confirmRemoveMissing('binding-1', {
|
clientReportedMissing: true,
|
expectedVersion: 1,
|
operationCode: 'remove-1',
|
reason: 'missing',
|
});
|
|
expect(requestMocks.post.mock.calls.map(([request]) => request.url)).toEqual([
|
'/api/eln/templateCatalog/currentVersion',
|
'/api/eln/templateCatalog/bindings/binding-1/confirmRemoveMissing',
|
]);
|
});
|
});
|