刘光辉
3 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { shallowMount } from '@vue/test-utils';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import TemplateSelectModal from './TemplateSelectModal.vue';
 
const mocks = vi.hoisted(() => ({ list: vi.fn() }));
vi.mock('#/api/onlineDev/uploadTemplate', () => ({ listUploadTemplates: mocks.list }));
vi.mock('../../popupSelect/src/PopupSelect.vue', () => ({
  default: { name: 'PopupSelect', props: ['uploadTemplateSelection', 'columnOptions'], template: '<div />' },
}));
vi.mock('ant-design-vue', () => ({ Alert: { template: '<div />' } }));
 
const query = { context: { modelId: 'model', field: 'biz_files' }, currentPage: 1, keyword: '' };
const file = { fileId: 'source', name: 'template.docx', fileSize: 10 };
function setup(validate = () => '') {
  const select = vi.fn().mockResolvedValue(undefined);
  const wrapper = shallowMount(TemplateSelectModal, { props: { query, replacing: false, validate, select } });
  const adapter = wrapper.findComponent({ name: 'PopupSelect' }).props('uploadTemplateSelection');
  return { wrapper, adapter, select };
}
beforeEach(() => {
  mocks.list.mockResolvedValue({ data: { total: 21, list: [{ id: 'template', name: '模板', files: [file] }] } });
});
describe('native template popup adapter', () => {
  it('uses the system selector and preserves the page/search context when authorizing a selected file', async () => {
    const { wrapper, adapter, select } = setup();
    const result = await adapter.load({ currentPage: 2, keyword: '模板' });
    expect(result.total).toBe(21);
    expect(result.list[0]).toMatchObject({ templateName: '模板', fileName: 'template.docx', unavailableReason: '' });
    await adapter.confirm(result.list[0]);
    expect(select).toHaveBeenCalledWith({ ...query, currentPage: 2, keyword: '模板', templateId: 'template', fileId: 'source' });
    wrapper.unmount();
  });
  it('exposes format/size rejection as an unselectable row', async () => {
    const { wrapper, adapter } = setup(() => '文件过大');
    const result = await adapter.load({ currentPage: 1, keyword: '' });
    expect(result.list[0].unavailableReason).toBe('文件过大');
    wrapper.unmount();
  });
  it('keeps templates without a supported file visible with a reason', async () => {
    mocks.list.mockResolvedValue({ data: { total: 1, list: [{ id: 'empty', name: '无附件', files: [] }] } });
    const { wrapper, adapter } = setup();
    const result = await adapter.load({ currentPage: 1, keyword: '' });
    expect(result.list[0].unavailableReason).toContain('DOCX');
    wrapper.unmount();
  });
});