import test from 'node:test' import assert from 'node:assert/strict' import { attachmentsForDisposal, unlinkedWarningAttachments, normalizeWarningAttachment } from '../src/views/subSystem/lifeCompany/warningAttachments.js' // 仅在内存中使用的 TEST 数据;不写入数据库或对象存储。 const records = [{ disposal_id: 'TEST-HANDLE' }, { disposalId: 'TEST-SUPERVISION' }] const files = [ { attachmentId: 'TEST-PNG', disposalId: 'TEST-HANDLE', attachmentName: '[处理反馈] 现场.png', attachmentSize: 1024 }, { attachment_id: 'TEST-PDF', disposal_id: 'TEST-SUPERVISION', attachment_name: '[督办附件] 督办.pdf', attachment_type: 'application/pdf', attachment_size: 2048 }, { attachmentId: 'TEST-REPORT', attachmentName: '[预警报告] 报告.docx' }, { attachmentId: 'TEST-LEGACY', disposalId: 'TEST-MISSING', attachmentName: '历史附件.pdf' } ] test('不同处置记录只展示各自的附件,兼容下划线和驼峰字段', () => { assert.deepEqual(attachmentsForDisposal(records[0], files), [files[0]]) assert.deepEqual(attachmentsForDisposal(records[1], files), [files[1]]) }) test('无关联编号的记录不能认领所有历史附件', () => { assert.deepEqual(attachmentsForDisposal({}, files), []) assert.deepEqual(attachmentsForDisposal(records[0], null), []) assert.deepEqual(unlinkedWarningAttachments(records, files), files.slice(2)) }) test('PDF 和图片可预览,文档保留原始扩展名供下载', () => { assert.equal(normalizeWarningAttachment(files[0]).previewKind, 'image') assert.equal(normalizeWarningAttachment(files[1]).previewKind, 'pdf') assert.equal(normalizeWarningAttachment(files[1]).name, '督办.pdf') assert.equal(normalizeWarningAttachment(files[1]).sizeText, '2.0 KB') assert.equal(normalizeWarningAttachment(files[2]).previewKind, '') assert.equal(normalizeWarningAttachment(files[2]).name, '报告.docx') assert.equal(normalizeWarningAttachment({ attachmentName: '页面.html', attachmentType: 'text/html' }).previewKind, '') }) test('零字节与未知大小分别展示', () => { assert.equal(normalizeWarningAttachment({ attachmentSize: 0 }).sizeText, '0 B') assert.equal(normalizeWarningAttachment({ attachmentSize: null }).sizeText, '') })