ActivityAudit.spec.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { shallowMount, createLocalVue } from '@vue/test-utils'
  2. import ActivityAudit from '../ActivityAudit.vue'
  3. import { auditActivity } from '@/api/activity'
  4. import { getDimensionWeights } from '@/api/dimension-weight'
  5. jest.mock('@/api/activity', () => ({
  6. getActivityList: jest.fn(() => Promise.resolve({ data: { records: [] } })),
  7. auditActivity: jest.fn(() => Promise.resolve({ code: 200 }))
  8. }))
  9. jest.mock('@/api/dimension-weight', () => ({
  10. getDimensionWeights: jest.fn(() => Promise.resolve({ data: [] }))
  11. }))
  12. const localVue = createLocalVue()
  13. localVue.directive('loading', {})
  14. const stubs = [
  15. 'el-drawer', 'el-button', 'el-input', 'el-tag', 'el-form', 'el-form-item',
  16. 'el-select', 'el-option', 'el-table', 'el-table-column'
  17. ]
  18. function mount() {
  19. return shallowMount(ActivityAudit, {
  20. localVue,
  21. stubs,
  22. mocks: { $message: { warning: jest.fn(), error: jest.fn(), success: jest.fn() } }
  23. })
  24. }
  25. const validWeights = () => [
  26. { dimension: 'body', weight: 20, enabled: true },
  27. { dimension: 'mind', weight: 20, enabled: true },
  28. { dimension: 'wisdom', weight: 20, enabled: true },
  29. { dimension: 'action', weight: 20, enabled: true },
  30. { dimension: 'wealth', weight: 20, enabled: true }
  31. ]
  32. const flush = () => new Promise(resolve => setTimeout(resolve, 0))
  33. describe('ActivityAudit 审核提交', () => {
  34. beforeEach(() => {
  35. jest.clearAllMocks()
  36. })
  37. it('五维权重合计不为 100% 时不提交', () => {
  38. const wrapper = mount()
  39. wrapper.vm.currentRow = { id: 9, auditStatus: 'pending' }
  40. wrapper.vm.auditWeights = validWeights().map((w, i) => ({ ...w, weight: i === 0 ? 19 : 20 }))
  41. wrapper.vm.handleApprove()
  42. expect(wrapper.vm.$message.warning).toHaveBeenCalledWith('五维权重需填写完整且合计为 100%')
  43. expect(auditActivity).not.toHaveBeenCalled()
  44. })
  45. it('只需五维权重,不再提交所属维度', async () => {
  46. const wrapper = mount()
  47. wrapper.vm.currentRow = { id: 9, auditStatus: 'pending' }
  48. wrapper.vm.auditWeights = validWeights()
  49. wrapper.vm.handleApprove()
  50. await flush()
  51. expect(auditActivity).toHaveBeenCalledWith({
  52. id: 9,
  53. action: 'approved',
  54. rejectReason: '',
  55. dimensionWeights: validWeights()
  56. })
  57. expect(auditActivity.mock.calls[0][0].dimensionCode).toBeUndefined()
  58. })
  59. it('驳回时以 rejected 提交并携带原因', async () => {
  60. const wrapper = mount()
  61. wrapper.vm.currentRow = { id: 9, auditStatus: 'pending' }
  62. wrapper.vm.handleReject('材料不全')
  63. await flush()
  64. expect(auditActivity).toHaveBeenCalledWith({
  65. id: 9,
  66. action: 'rejected',
  67. rejectReason: '材料不全'
  68. })
  69. })
  70. it('打开详情时回填已保存的五维权重', async () => {
  71. getDimensionWeights.mockResolvedValueOnce({
  72. data: [
  73. { dimension: 'body', weight: 40, enabled: true },
  74. { dimension: 'mind', weight: 15, enabled: true },
  75. { dimension: 'wisdom', weight: 15, enabled: true },
  76. { dimension: 'action', weight: 15, enabled: true },
  77. { dimension: 'wealth', weight: 15, enabled: true }
  78. ]
  79. })
  80. const wrapper = mount()
  81. wrapper.vm.showDetail({ id: 9, auditStatus: 'pending' })
  82. await flush()
  83. expect(getDimensionWeights).toHaveBeenCalledWith('activity', 9)
  84. expect(wrapper.vm.auditWeights.find(w => w.dimension === 'body').weight).toBe(40)
  85. })
  86. })