| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- import assert from 'node:assert/strict'
- import {
- formatProgressPersonLines,
- type ProgressPersonInput
- } from '../src/utils/oa-progress-person-lines'
- function run() {
- // 会签部分完成
- const andPartial: ProgressPersonInput[] = [
- {
- nickName: '甲',
- status: 'approved',
- commentText: '同意',
- timestamp: '2026-07-23 10:01:00'
- },
- {
- nickName: '乙',
- status: 'approved',
- commentText: '无异议',
- timestamp: '2026-07-23 10:20:00'
- },
- { nickName: '丙', status: 'pending', commentText: '', timestamp: '' }
- ]
- const andLines = formatProgressPersonLines(andPartial)
- assert.deepEqual(
- andLines.map((x) => x.text),
- [
- '甲 同意 2026-07-23 10:01:00',
- '乙 无异议 2026-07-23 10:20:00',
- '丙 待处理'
- ]
- )
- assert.deepEqual(
- andLines.map((x) => ({ body: x.body, timestamp: x.timestamp })),
- [
- { body: '甲 同意', timestamp: '2026-07-23 10:01:00' },
- { body: '乙 无异议', timestamp: '2026-07-23 10:20:00' },
- { body: '丙 待处理', timestamp: '' }
- ]
- )
- assert.equal(andLines[0].tone, 'ok')
- assert.equal(andLines[2].tone, 'pending')
- // 或签一人已批:操作人 + 免处理仍列出
- const orDone: ProgressPersonInput[] = [
- {
- nickName: '甲',
- status: 'approved',
- commentText: '同意,材料齐全',
- timestamp: '2026-07-23 10:05:00'
- },
- { nickName: '乙', status: 'done', commentText: '', timestamp: '2026-07-23 10:00:00' },
- { nickName: '丙', status: 'done', commentText: '', timestamp: '' }
- ]
- const orLines = formatProgressPersonLines(orDone)
- assert.deepEqual(
- orLines.map((x) => x.text),
- ['甲 同意,材料齐全 2026-07-23 10:05:00', '乙 无需处理', '丙 无需处理']
- )
- assert.equal(orLines[0].tone, 'ok')
- assert.equal(orLines[1].tone, 'mute')
- assert.equal(orLines[2].tone, 'mute')
- // 已同意但无意见 → 状态文案兜底
- const emptyComment = formatProgressPersonLines([
- {
- nickName: '甲',
- status: 'approved',
- commentText: '',
- timestamp: '2026-07-23 10:05:00'
- }
- ])
- assert.equal(emptyComment[0].text, '甲 已同意 2026-07-23 10:05:00')
- // 拒绝
- const rejected = formatProgressPersonLines([
- {
- nickName: '甲',
- status: 'rejected',
- commentText: '不同意',
- timestamp: '2026-07-23 11:00:00'
- },
- { nickName: '乙', status: 'done' }
- ])
- assert.equal(rejected[0].text, '甲 不同意 2026-07-23 11:00:00')
- assert.equal(rejected[0].tone, 'danger')
- assert.equal(rejected[1].text, '乙 无需处理')
- // 转交
- const xfer: ProgressPersonInput[] = [
- {
- nickName: '李四',
- status: 'transferred',
- commentText: '',
- timestamp: '2026-07-23 10:05:00',
- transferToUserName: '赵六'
- },
- { nickName: '赵六', status: 'pending', commentText: '', timestamp: '' }
- ]
- const xferLines = formatProgressPersonLines(xfer)
- assert.deepEqual(
- xferLines.map((x) => x.text),
- ['李四 转交给赵六 2026-07-23 10:05:00', '赵六 待处理']
- )
- assert.equal(xferLines[0].tone, 'mute')
- const xferComment: ProgressPersonInput[] = [
- {
- nickName: '李四',
- status: 'transferred',
- commentText: '出差代批',
- timestamp: '2026-07-23 10:05:00',
- transferToUserName: '赵六'
- }
- ]
- assert.equal(
- formatProgressPersonLines(xferComment)[0].text,
- '李四 转交给赵六 出差代批 2026-07-23 10:05:00'
- )
- // 转交目标缺失时回退「已转交」
- assert.equal(
- formatProgressPersonLines([
- {
- nickName: '李四',
- status: 'transferred',
- commentText: '',
- timestamp: '2026-07-23 10:05:00'
- }
- ])[0].text,
- '李四 已转交 2026-07-23 10:05:00'
- )
- // 转交目标缺失但有说明:仍用说明
- assert.equal(
- formatProgressPersonLines([
- {
- nickName: '胡圆凯',
- status: 'transferred',
- commentText: '123123',
- timestamp: '2026-07-23 17:35:12'
- }
- ])[0].text,
- '胡圆凯 123123 2026-07-23 17:35:12'
- )
- // 空 people
- assert.deepEqual(formatProgressPersonLines([]), [])
- assert.deepEqual(formatProgressPersonLines(undefined), [])
- console.log('oa-progress-person-lines: all assertions passed')
- }
- run()
|