| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- import { shallowMount, createLocalVue } from '@vue/test-utils'
- import ActivityAudit from '../ActivityAudit.vue'
- import { auditActivity } from '@/api/activity'
- import { getDimensionWeights } from '@/api/dimension-weight'
- jest.mock('@/api/activity', () => ({
- getActivityList: jest.fn(() => Promise.resolve({ data: { records: [] } })),
- auditActivity: jest.fn(() => Promise.resolve({ code: 200 }))
- }))
- jest.mock('@/api/dimension-weight', () => ({
- getDimensionWeights: jest.fn(() => Promise.resolve({ data: [] }))
- }))
- const localVue = createLocalVue()
- localVue.directive('loading', {})
- const stubs = [
- 'el-drawer', 'el-button', 'el-input', 'el-tag', 'el-form', 'el-form-item',
- 'el-select', 'el-option', 'el-table', 'el-table-column'
- ]
- function mount() {
- return shallowMount(ActivityAudit, {
- localVue,
- stubs,
- mocks: { $message: { warning: jest.fn(), error: jest.fn(), success: jest.fn() } }
- })
- }
- const validWeights = () => [
- { dimension: 'body', weight: 20, enabled: true },
- { dimension: 'mind', weight: 20, enabled: true },
- { dimension: 'wisdom', weight: 20, enabled: true },
- { dimension: 'action', weight: 20, enabled: true },
- { dimension: 'wealth', weight: 20, enabled: true }
- ]
- const flush = () => new Promise(resolve => setTimeout(resolve, 0))
- describe('ActivityAudit 审核提交', () => {
- beforeEach(() => {
- jest.clearAllMocks()
- })
- it('五维权重合计不为 100% 时不提交', () => {
- const wrapper = mount()
- wrapper.vm.currentRow = { id: 9, auditStatus: 'pending' }
- wrapper.vm.auditWeights = validWeights().map((w, i) => ({ ...w, weight: i === 0 ? 19 : 20 }))
- wrapper.vm.handleApprove()
- expect(wrapper.vm.$message.warning).toHaveBeenCalledWith('五维权重需填写完整且合计为 100%')
- expect(auditActivity).not.toHaveBeenCalled()
- })
- it('只需五维权重,不再提交所属维度', async () => {
- const wrapper = mount()
- wrapper.vm.currentRow = { id: 9, auditStatus: 'pending' }
- wrapper.vm.auditWeights = validWeights()
- wrapper.vm.handleApprove()
- await flush()
- expect(auditActivity).toHaveBeenCalledWith({
- id: 9,
- action: 'approved',
- rejectReason: '',
- dimensionWeights: validWeights()
- })
- expect(auditActivity.mock.calls[0][0].dimensionCode).toBeUndefined()
- })
- it('驳回时以 rejected 提交并携带原因', async () => {
- const wrapper = mount()
- wrapper.vm.currentRow = { id: 9, auditStatus: 'pending' }
- wrapper.vm.handleReject('材料不全')
- await flush()
- expect(auditActivity).toHaveBeenCalledWith({
- id: 9,
- action: 'rejected',
- rejectReason: '材料不全'
- })
- })
- it('打开详情时回填已保存的五维权重', async () => {
- getDimensionWeights.mockResolvedValueOnce({
- data: [
- { dimension: 'body', weight: 40, enabled: true },
- { dimension: 'mind', weight: 15, enabled: true },
- { dimension: 'wisdom', weight: 15, enabled: true },
- { dimension: 'action', weight: 15, enabled: true },
- { dimension: 'wealth', weight: 15, enabled: true }
- ]
- })
- const wrapper = mount()
- wrapper.vm.showDetail({ id: 9, auditStatus: 'pending' })
- await flush()
- expect(getDimensionWeights).toHaveBeenCalledWith('activity', 9)
- expect(wrapper.vm.auditWeights.find(w => w.dimension === 'body').weight).toBe(40)
- })
- })
|