/* @vitest-environment happy-dom */
|
|
import { flushPromises, mount } from '@vue/test-utils';
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import ReportElnRecordsPane from '../ReportElnRecordsPane.vue';
|
|
const apiMocks = vi.hoisted(() => ({
|
getOnlyOfficeConfig: vi.fn(),
|
getRecordByTestWorkItem: vi.fn(),
|
postInspectionProgressDetail: vi.fn(),
|
}));
|
|
vi.mock('#/api/x/onlyoffice', () => ({ getOnlyOfficeConfig: apiMocks.getOnlyOfficeConfig }));
|
vi.mock('#/api/x/eln/records', () => ({ getRecordByTestWorkItem: apiMocks.getRecordByTestWorkItem }));
|
vi.mock('#/api/x/lims/jianyanguanli/jianyan_jindu', () => ({
|
postInspectionProgressDetail: apiMocks.postInspectionProgressDetail,
|
}));
|
vi.mock('#/components/OnlyOfficeEditor/src/Editor.vue', async () => {
|
const { defineComponent, h } = await import('vue');
|
return {
|
default: defineComponent({
|
name: 'OnlyOfficeEditor',
|
props: { config: { required: true, type: Object } },
|
setup() {
|
return () => h('div', { 'data-test': 'eln-onlyoffice-editor' });
|
},
|
}),
|
};
|
});
|
|
const record = (id: string) => ({
|
data: {
|
document: { fileExtension: 'docx', fileId: `file-${id}`, name: `${id}.docx` },
|
existing: true,
|
recordId: `record-${id}`,
|
revisionId: `revision-${id}`,
|
},
|
});
|
|
describe('report ELN records pane', () => {
|
beforeEach(() => {
|
vi.clearAllMocks();
|
apiMocks.postInspectionProgressDetail.mockResolvedValue({
|
data: {
|
project_detail: [
|
{ id: 'item-1', name: '性状', stages: [] },
|
{ id: 'item-2', name: '鉴别', stages: [] },
|
],
|
},
|
});
|
apiMocks.getRecordByTestWorkItem.mockImplementation((id: string) => Promise.resolve(record(id)));
|
apiMocks.getOnlyOfficeConfig.mockResolvedValue({
|
data: { document: { key: 'key-1' }, editorConfig: { mode: 'view' }, token: 'token-1' },
|
});
|
});
|
|
it('loads inspection items and opens the selected current ELN revision readonly', async () => {
|
const wrapper = mount(ReportElnRecordsPane, {
|
props: { tab: { key: 'elnRecords', qingyandanId: 'request-1' } },
|
});
|
await flushPromises();
|
|
expect(apiMocks.postInspectionProgressDetail).toHaveBeenCalledWith({ qingyandan_id: 'request-1' });
|
expect(apiMocks.getRecordByTestWorkItem).toHaveBeenCalledWith('item-1');
|
expect(apiMocks.getOnlyOfficeConfig).toHaveBeenCalledWith(expect.objectContaining({ bizDataId: 'record-item-1', mode: 'view' }));
|
expect(wrapper.find('[data-test="eln-onlyoffice-editor"]').exists()).toBe(true);
|
|
await wrapper.get('[data-test="eln-project-item-2"]').trigger('click');
|
await flushPromises();
|
|
expect(apiMocks.getRecordByTestWorkItem).toHaveBeenCalledWith('item-2');
|
});
|
|
it('shows a non-mutating empty state when the selected item has no ELN record', async () => {
|
apiMocks.getRecordByTestWorkItem.mockRejectedValue(new Error('检验项电子记录不存在'));
|
const wrapper = mount(ReportElnRecordsPane, {
|
props: { tab: { key: 'elnRecords', qingyandanId: 'request-1' } },
|
});
|
await flushPromises();
|
|
expect(wrapper.get('[data-test="eln-record-error"]').text()).toContain('检验项电子记录不存在');
|
expect(apiMocks.getOnlyOfficeConfig).not.toHaveBeenCalled();
|
});
|
});
|