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

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