92 lines
2.9 KiB
JavaScript
92 lines
2.9 KiB
JavaScript
import { flushPromises, mount } from '@vue/test-utils'
|
|
import ElementPlus from 'element-plus'
|
|
import { beforeEach, describe, expect, test, vi } from 'vitest'
|
|
import Approval from './Approval.vue'
|
|
|
|
const approvalStore = vi.hoisted(() => ({
|
|
applications: [],
|
|
loading: false,
|
|
page: { currentPage: 1, pageSize: 20, total: 0 },
|
|
fetchPendingApplications: vi.fn(),
|
|
approveApplication: vi.fn(),
|
|
rejectApplication: vi.fn()
|
|
}))
|
|
|
|
vi.mock('../stores/approval', () => ({ useApprovalStore: () => approvalStore }))
|
|
|
|
function findButton(wrapper, text) {
|
|
return wrapper.findAll('button').find(button => button.text().includes(text))
|
|
}
|
|
|
|
function mountApproval() {
|
|
return mount(Approval, {
|
|
global: { plugins: [ElementPlus], stubs: { teleport: true } }
|
|
})
|
|
}
|
|
|
|
describe('审批自动出库默认值', () => {
|
|
beforeEach(() => {
|
|
approvalStore.fetchPendingApplications.mockReset()
|
|
approvalStore.approveApplication.mockReset().mockResolvedValue({ data: {} })
|
|
approvalStore.rejectApplication.mockReset().mockResolvedValue({ data: {} })
|
|
})
|
|
|
|
// el-table 的行内容在 jsdom 下渲染不出来(列宽依赖真实布局计算),
|
|
// 于是跳过表格这一层,直接触发组件的打开逻辑。
|
|
async function openApproveDialog(wrapper) {
|
|
wrapper.vm.$.setupState.showApproveModal({ id: 9, status: 'pending' })
|
|
await flushPromises()
|
|
}
|
|
|
|
test('打开审批弹窗时自动出库默认已勾选', async () => {
|
|
const wrapper = mountApproval()
|
|
await flushPromises()
|
|
await openApproveDialog(wrapper)
|
|
|
|
expect(wrapper.find('.el-switch').classes()).toContain('is-checked')
|
|
wrapper.unmount()
|
|
})
|
|
|
|
test('默认提交时 auto_outbound 为 true', async () => {
|
|
const wrapper = mountApproval()
|
|
await flushPromises()
|
|
await openApproveDialog(wrapper)
|
|
|
|
await findButton(wrapper, '确认通过').trigger('click')
|
|
await flushPromises()
|
|
|
|
expect(approvalStore.approveApplication).toHaveBeenCalledWith(9, { auto_outbound: true })
|
|
wrapper.unmount()
|
|
})
|
|
|
|
test('手动关掉开关后可以只审批不出库', async () => {
|
|
const wrapper = mountApproval()
|
|
await flushPromises()
|
|
await openApproveDialog(wrapper)
|
|
|
|
await wrapper.find('.el-switch').trigger('click')
|
|
await flushPromises()
|
|
|
|
await findButton(wrapper, '确认通过').trigger('click')
|
|
await flushPromises()
|
|
|
|
expect(approvalStore.approveApplication).toHaveBeenCalledWith(9, { auto_outbound: false })
|
|
wrapper.unmount()
|
|
})
|
|
|
|
test('关掉后重新打开会回到默认勾选', async () => {
|
|
const wrapper = mountApproval()
|
|
await flushPromises()
|
|
await openApproveDialog(wrapper)
|
|
|
|
await wrapper.find('.el-switch').trigger('click')
|
|
await flushPromises()
|
|
expect(wrapper.find('.el-switch').classes()).not.toContain('is-checked')
|
|
|
|
await openApproveDialog(wrapper)
|
|
|
|
expect(wrapper.find('.el-switch').classes()).toContain('is-checked')
|
|
wrapper.unmount()
|
|
})
|
|
})
|