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('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), ['知情同意书', '传染病检测报告', '其他附件'] ) }) })