import { describe, it } from 'node:test' import assert from 'node:assert/strict' import { buildFlowItems } from './oa-approval-print-flow' describe('打印讨论评论', () => { it('按时间展示正文、提及和附件,并排在待审节点前', () => { const items = buildFlowItems({ progress: [ { kind: 'submit', title: '发起人', status: 'submitted', timestamp: '2026-11-01 10:00:00' }, { kind: 'pending_node', title: '审批人', status: 'pending', timestamp: '2026-11-01 10:00:00' } ], comments: [ { id: '2', createByName: '李四', createTime: '2026-11-01 12:00:00', content: '', attachmentRefs: [{ url: 'https://example.com/file.pdf', fileName: '附件.pdf' }] }, { id: '1', createByName: '张三', createTime: '2026-11-01 11:00:00', content: '@李四 请处理\n第二行', mentions: [{ userId: 'u2', userName: '李四' }] } ] }) assert.equal(items.length, 4) assert.equal(items[1].left, '【评论】 张三') assert.equal(items[1].right, '2026-11-01 11:00:00') assert.deepEqual(items[1].personLines, [ { left: '@李四 请处理\n第二行', right: '' }, { left: '提到:@李四', right: '' } ]) assert.deepEqual(items[2].attachmentLinks, ['https://example.com/file.pdf']) assert.match(items[3].left, /待处理/) }) it('撤回评论不泄露正文、提及和附件', () => { const [item] = buildFlowItems({ comments: [ { id: '1', createBy: 'u1', status: 'revoked', content: 'secret', mentions: [{ userName: 'secret' }], attachmentRefs: [{ url: 'https://example.com/secret' }] } ] }) assert.equal(item.left, '【评论】 u1 已撤回') assert.equal(JSON.stringify(item).includes('secret'), false) }) it('安全过滤附件协议,保留纯附件与纯提及评论', () => { const items = buildFlowItems({ comments: [ { id: '1', mentions: [{ userId: 'u1' }], attachmentRefs: [{ url: 'javascript:alert(1)' }, { url: 'https://example.com/a?x=1&y=2' }] } ] }) assert.deepEqual(items[0].attachmentLinks, ['https://example.com/a?x=1&y=2']) assert.deepEqual(items[0].personLines, [{ left: '提到:@u1', right: '' }]) }) }) it('同秒节点使用详情页的稳定排序键', () => { const progress = Array.from({ length: 12 }, (_, index) => ({ kind: 'task', nodeKey: `node-${String(11 - index).padStart(2, '0')}`, title: `节点${11 - index}`, status: 'approved', timestamp: '2026-11-01 10:00:00' })) const items = buildFlowItems({ progress, comments: [{ id: 'comment', content: '讨论', createTime: '2026-11-01 10:00:00' }] }) assert.equal(items[0].left, '【节点0】 已同意') assert.equal(items[11].left, '【节点11】 已同意') assert.equal(items[12].left, '【评论】 评论') })