You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
2.1 KiB
35 lines
2.1 KiB
import { shallowMount, createLocalVue } from '@vue/test-utils'
|
|
import VueRouter from 'vue-router'
|
|
import Account from '@/views/qccEnterpriseAccount/index'
|
|
import { candidates, select, selectNonOccupying } from '@/api/qccEnterpriseAccount/index'
|
|
jest.mock('@/api/qccEnterpriseAccount/index', () => ({ candidates: jest.fn(), select: jest.fn(), selectNonOccupying: jest.fn(), cancel: jest.fn(), unknownConfirm: jest.fn() }))
|
|
const flush = async() => { await Promise.resolve(); await Promise.resolve() }
|
|
const localVue = createLocalVue()
|
|
localVue.use(VueRouter)
|
|
localVue.directive('loading', {})
|
|
let wrapper
|
|
beforeEach(() => {
|
|
candidates.mockResolvedValue({ data: [], total: 0 })
|
|
selectNonOccupying.mockResolvedValue({})
|
|
wrapper = shallowMount(Account, { localVue, router: new VueRouter(), mocks: { $message: { success: jest.fn() }}, stubs: ['lx-header', 'student-filters', 'student-info', 'account-list', 'el-tabs', 'el-tab-pane', 'el-table', 'el-table-column', 'el-select', 'el-option', 'el-button', 'el-input', 'el-pagination', 'el-dialog', 'el-form', 'el-form-item', 'el-alert', 'el-radio-group', 'el-radio'] })
|
|
})
|
|
afterEach(() => { if (wrapper) wrapper.destroy(); jest.clearAllMocks() })
|
|
it('sends selected company IDs to the non-occupying action and refreshes the list', async() => {
|
|
await flush()
|
|
wrapper.setData({ selectedCompanies: [{ id: 1 }, { id: 2 }] })
|
|
await wrapper.vm.selectNonOccupyingCompanies()
|
|
expect(selectNonOccupying).toHaveBeenCalledWith({ company_ids: [1, 2] })
|
|
expect(select).not.toHaveBeenCalled()
|
|
expect(candidates).toHaveBeenCalledTimes(2)
|
|
expect(wrapper.vm.selectedCompanies).toEqual([])
|
|
expect(wrapper.vm.statusLabel('non_occupying')).toBe('不占额企业')
|
|
})
|
|
it('prevents duplicate submissions and keeps already enrolled companies unselectable', async() => {
|
|
await flush()
|
|
wrapper.setData({ selectedCompanies: [{ id: 1 }], enrolling: true })
|
|
await wrapper.vm.selectNonOccupyingCompanies()
|
|
expect(selectNonOccupying).not.toHaveBeenCalled()
|
|
expect(wrapper.vm.isSelectable({ credit_code: 'code', qcc_account: { status: 'non_occupying' }})).toBe(false)
|
|
expect(wrapper.vm.isSelectable({ credit_code: 'code' })).toBe(true)
|
|
})
|