feat: 完善知识库批量导入与公共 API
- 新增批量异步导入、状态查询、失败重试与中断恢复链路 - 拆分知识库读取、导入、维护权限并完善 Public API 契约 - 补充数据库迁移、管理端交互、接口说明与相关测试
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import { flushPromises, mount } from '@vue/test-utils';
|
||||
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import DocumentImportBatchStatus from './DocumentImportBatchStatus.vue';
|
||||
|
||||
const apiMocks = vi.hoisted(() => ({
|
||||
get: vi.fn(),
|
||||
post: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('#/api/request', () => ({ api: apiMocks }));
|
||||
|
||||
vi.mock('@easyflow/locales', () => ({
|
||||
$t: (key: string) => key,
|
||||
}));
|
||||
|
||||
function createBatch(status: 'COMPLETED' | 'RUNNING', completedCount: number) {
|
||||
return {
|
||||
batchId: 'batch-1',
|
||||
completedCount,
|
||||
failedCount: 0,
|
||||
importMode: 'AUTO',
|
||||
pendingCount: status === 'RUNNING' ? 1 : 0,
|
||||
processingCount: 0,
|
||||
progressPercent: status === 'COMPLETED' ? 100 : 50,
|
||||
skippedCount: 0,
|
||||
status,
|
||||
totalCount: 2,
|
||||
};
|
||||
}
|
||||
|
||||
describe('documentImportBatchStatus', () => {
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('页面首次进入时不恢复已完成批次', async () => {
|
||||
apiMocks.get.mockResolvedValue({
|
||||
data: createBatch('COMPLETED', 2),
|
||||
errorCode: 0,
|
||||
});
|
||||
|
||||
const wrapper = mount(DocumentImportBatchStatus, {
|
||||
props: { knowledgeId: 'knowledge-1' },
|
||||
});
|
||||
await flushPromises();
|
||||
|
||||
expect(wrapper.find('.batch-status').exists()).toBe(false);
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it('当前页面跟踪的批次完成后继续展示结果', async () => {
|
||||
vi.useFakeTimers();
|
||||
apiMocks.get
|
||||
.mockResolvedValueOnce({
|
||||
data: createBatch('RUNNING', 1),
|
||||
errorCode: 0,
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
data: createBatch('COMPLETED', 2),
|
||||
errorCode: 0,
|
||||
});
|
||||
|
||||
const wrapper = mount(DocumentImportBatchStatus, {
|
||||
props: { knowledgeId: 'knowledge-1' },
|
||||
});
|
||||
await flushPromises();
|
||||
|
||||
expect(wrapper.find('.batch-status').exists()).toBe(true);
|
||||
|
||||
await vi.advanceTimersByTimeAsync(3000);
|
||||
await flushPromises();
|
||||
|
||||
expect(wrapper.find('.batch-status').exists()).toBe(true);
|
||||
expect(wrapper.text()).toContain(
|
||||
'documentCollection.importDoc.batchCompleted',
|
||||
);
|
||||
wrapper.unmount();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user