Files
zkxw/web-admin/src/utils/protocol-source-attachment.test.ts
T
zlwuandCursor 67a209298c fix(web-admin): 样本接收弹窗恢复展示协议附件
验收反馈要求协议附件可见;细胞存储分组恢复为知情同意书、孕妇健康调查表、协议附件三项。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-09 13:57:26 +08:00

73 lines
2.5 KiB
TypeScript

import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
getConsentProtocolAttachment,
getSourceProtocolAttachment,
getSourceProtocolAttachmentGroups
} from './protocol-source-attachment'
describe('protocol-source-attachment', () => {
it('returns health survey as primary for cell storage', () => {
const meta = getSourceProtocolAttachment({
sourceType: 'cell_storage',
healthSurveyAttachmentFiles: [{ id: '1', fileUrl: '/a.png' }]
})
assert.equal(meta.label, '孕妇健康调查表')
assert.equal(meta.files.length, 1)
})
it('returns infectious disease report as primary for research donation', () => {
const meta = getSourceProtocolAttachment({
sourceType: 'research_donation',
infectiousDiseaseReportAttachmentFiles: [{ id: '2', fileUrl: '/b.png' }]
})
assert.equal(meta.label, '传染病检测报告')
assert.equal(meta.files.length, 1)
})
it('returns consent attachment from shared field', () => {
const meta = getConsentProtocolAttachment({
consentAttachmentFiles: [{ id: '3', fileUrl: '/c.png' }]
})
assert.equal(meta.label, '知情同意书')
assert.equal(meta.files.length, 1)
})
it('groups cell storage attachments for reception dialog', () => {
const groups = getSourceProtocolAttachmentGroups({
sourceType: 'cell_storage',
protocolAttachmentFiles: [{ id: 'p' }],
consentAttachmentFiles: [{ id: 'c' }],
healthSurveyAttachmentFiles: [{ id: 'h' }]
})
assert.deepEqual(
groups.map((g) => g.label),
['知情同意书', '孕妇健康调查表', '协议附件']
)
assert.ok(groups.every((g) => g.files.length === 1))
})
it('accepts attachments alias for cell storage protocol files', () => {
const groups = getSourceProtocolAttachmentGroups({
sourceType: 'cell_storage',
attachments: [{ id: 'alias' }]
})
const protocol = groups.find((g) => g.label === '协议附件')
assert.ok(protocol)
assert.equal(protocol.files.length, 1)
})
it('groups research donation attachments for reception dialog', () => {
const groups = getSourceProtocolAttachmentGroups({
sourceType: 'research_donation',
consentAttachmentFiles: [{ id: 'c' }],
infectiousDiseaseReportAttachmentFiles: [{ id: 'i' }],
attachmentFiles: [{ id: 'o' }]
})
assert.deepEqual(
groups.map((g) => g.label),
['知情同意书', '传染病检测报告', '其他附件']
)
})
})