fix: 支持关闭自动导入状态提示
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { flushPromises, mount } from '@vue/test-utils';
|
||||
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import DocumentImportBatchStatus from './DocumentImportBatchStatus.vue';
|
||||
|
||||
@@ -31,6 +31,10 @@ function createBatch(status: 'COMPLETED' | 'RUNNING', completedCount: number) {
|
||||
}
|
||||
|
||||
describe('documentImportBatchStatus', () => {
|
||||
beforeEach(() => {
|
||||
localStorage.clear();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
vi.useRealTimers();
|
||||
@@ -77,6 +81,65 @@ describe('documentImportBatchStatus', () => {
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it('关闭当前批次提示后停止轮询且不影响导入接口', async () => {
|
||||
vi.useFakeTimers();
|
||||
apiMocks.get.mockResolvedValue({
|
||||
data: createBatch('RUNNING', 1),
|
||||
errorCode: 0,
|
||||
});
|
||||
|
||||
const wrapper = mount(DocumentImportBatchStatus, {
|
||||
props: { knowledgeId: 'knowledge-1' },
|
||||
});
|
||||
await flushPromises();
|
||||
|
||||
const closeButton = wrapper.find('.batch-status__close');
|
||||
expect(closeButton.attributes('aria-label')).toBe(
|
||||
'documentCollection.importDoc.dismissBatchStatus',
|
||||
);
|
||||
await closeButton.trigger('click');
|
||||
|
||||
expect(wrapper.find('.batch-status').exists()).toBe(false);
|
||||
await vi.advanceTimersByTimeAsync(30_000);
|
||||
expect(apiMocks.get).toHaveBeenCalledTimes(1);
|
||||
expect(apiMocks.post).not.toHaveBeenCalled();
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it('当前批次关闭状态在本地保留且新批次仍会展示', async () => {
|
||||
apiMocks.get
|
||||
.mockResolvedValueOnce({
|
||||
data: createBatch('RUNNING', 1),
|
||||
errorCode: 0,
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
data: createBatch('RUNNING', 1),
|
||||
errorCode: 0,
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
data: { ...createBatch('RUNNING', 0), batchId: 'batch-2' },
|
||||
errorCode: 0,
|
||||
});
|
||||
|
||||
const firstWrapper = mount(DocumentImportBatchStatus, {
|
||||
props: { knowledgeId: 'knowledge-1' },
|
||||
});
|
||||
await flushPromises();
|
||||
await firstWrapper.find('.batch-status__close').trigger('click');
|
||||
firstWrapper.unmount();
|
||||
|
||||
const secondWrapper = mount(DocumentImportBatchStatus, {
|
||||
props: { knowledgeId: 'knowledge-1' },
|
||||
});
|
||||
await flushPromises();
|
||||
expect(secondWrapper.find('.batch-status').exists()).toBe(false);
|
||||
|
||||
await secondWrapper.setProps({ refreshKey: 1 });
|
||||
await flushPromises();
|
||||
expect(secondWrapper.find('.batch-status').exists()).toBe(true);
|
||||
secondWrapper.unmount();
|
||||
});
|
||||
|
||||
it('失败批次关联任务实际完成后不再展示提示', async () => {
|
||||
apiMocks.get.mockResolvedValue({
|
||||
data: {
|
||||
|
||||
Reference in New Issue
Block a user