check-oa-progress-person-lines.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import assert from 'node:assert/strict'
  2. import {
  3. formatProgressPersonLines,
  4. type ProgressPersonInput
  5. } from '../src/utils/oa-progress-person-lines'
  6. function run() {
  7. // 会签部分完成
  8. const andPartial: ProgressPersonInput[] = [
  9. {
  10. nickName: '甲',
  11. status: 'approved',
  12. commentText: '同意',
  13. timestamp: '2026-07-23 10:01:00'
  14. },
  15. {
  16. nickName: '乙',
  17. status: 'approved',
  18. commentText: '无异议',
  19. timestamp: '2026-07-23 10:20:00'
  20. },
  21. { nickName: '丙', status: 'pending', commentText: '', timestamp: '' }
  22. ]
  23. const andLines = formatProgressPersonLines(andPartial)
  24. assert.deepEqual(
  25. andLines.map((x) => x.text),
  26. [
  27. '甲 同意 2026-07-23 10:01:00',
  28. '乙 无异议 2026-07-23 10:20:00',
  29. '丙 待处理'
  30. ]
  31. )
  32. assert.deepEqual(
  33. andLines.map((x) => ({ body: x.body, timestamp: x.timestamp })),
  34. [
  35. { body: '甲 同意', timestamp: '2026-07-23 10:01:00' },
  36. { body: '乙 无异议', timestamp: '2026-07-23 10:20:00' },
  37. { body: '丙 待处理', timestamp: '' }
  38. ]
  39. )
  40. assert.equal(andLines[0].tone, 'ok')
  41. assert.equal(andLines[2].tone, 'pending')
  42. // 或签一人已批:操作人 + 免处理仍列出
  43. const orDone: ProgressPersonInput[] = [
  44. {
  45. nickName: '甲',
  46. status: 'approved',
  47. commentText: '同意,材料齐全',
  48. timestamp: '2026-07-23 10:05:00'
  49. },
  50. { nickName: '乙', status: 'done', commentText: '', timestamp: '2026-07-23 10:00:00' },
  51. { nickName: '丙', status: 'done', commentText: '', timestamp: '' }
  52. ]
  53. const orLines = formatProgressPersonLines(orDone)
  54. assert.deepEqual(
  55. orLines.map((x) => x.text),
  56. ['甲 同意,材料齐全 2026-07-23 10:05:00', '乙 无需处理', '丙 无需处理']
  57. )
  58. assert.equal(orLines[0].tone, 'ok')
  59. assert.equal(orLines[1].tone, 'mute')
  60. assert.equal(orLines[2].tone, 'mute')
  61. // 已同意但无意见 → 状态文案兜底
  62. const emptyComment = formatProgressPersonLines([
  63. {
  64. nickName: '甲',
  65. status: 'approved',
  66. commentText: '',
  67. timestamp: '2026-07-23 10:05:00'
  68. }
  69. ])
  70. assert.equal(emptyComment[0].text, '甲 已同意 2026-07-23 10:05:00')
  71. // 拒绝
  72. const rejected = formatProgressPersonLines([
  73. {
  74. nickName: '甲',
  75. status: 'rejected',
  76. commentText: '不同意',
  77. timestamp: '2026-07-23 11:00:00'
  78. },
  79. { nickName: '乙', status: 'done' }
  80. ])
  81. assert.equal(rejected[0].text, '甲 不同意 2026-07-23 11:00:00')
  82. assert.equal(rejected[0].tone, 'danger')
  83. assert.equal(rejected[1].text, '乙 无需处理')
  84. // 转交
  85. const xfer: ProgressPersonInput[] = [
  86. {
  87. nickName: '李四',
  88. status: 'transferred',
  89. commentText: '',
  90. timestamp: '2026-07-23 10:05:00',
  91. transferToUserName: '赵六'
  92. },
  93. { nickName: '赵六', status: 'pending', commentText: '', timestamp: '' }
  94. ]
  95. const xferLines = formatProgressPersonLines(xfer)
  96. assert.deepEqual(
  97. xferLines.map((x) => x.text),
  98. ['李四 转交给赵六 2026-07-23 10:05:00', '赵六 待处理']
  99. )
  100. assert.equal(xferLines[0].tone, 'mute')
  101. const xferComment: ProgressPersonInput[] = [
  102. {
  103. nickName: '李四',
  104. status: 'transferred',
  105. commentText: '出差代批',
  106. timestamp: '2026-07-23 10:05:00',
  107. transferToUserName: '赵六'
  108. }
  109. ]
  110. assert.equal(
  111. formatProgressPersonLines(xferComment)[0].text,
  112. '李四 转交给赵六 出差代批 2026-07-23 10:05:00'
  113. )
  114. // 转交目标缺失时回退「已转交」
  115. assert.equal(
  116. formatProgressPersonLines([
  117. {
  118. nickName: '李四',
  119. status: 'transferred',
  120. commentText: '',
  121. timestamp: '2026-07-23 10:05:00'
  122. }
  123. ])[0].text,
  124. '李四 已转交 2026-07-23 10:05:00'
  125. )
  126. // 转交目标缺失但有说明:仍用说明
  127. assert.equal(
  128. formatProgressPersonLines([
  129. {
  130. nickName: '胡圆凯',
  131. status: 'transferred',
  132. commentText: '123123',
  133. timestamp: '2026-07-23 17:35:12'
  134. }
  135. ])[0].text,
  136. '胡圆凯 123123 2026-07-23 17:35:12'
  137. )
  138. // 空 people
  139. assert.deepEqual(formatProgressPersonLines([]), [])
  140. assert.deepEqual(formatProgressPersonLines(undefined), [])
  141. console.log('oa-progress-person-lines: all assertions passed')
  142. }
  143. run()