mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
ui: Fix UI unit test failures in master (#4719)
This commit is contained in:
parent
7b2724a0e3
commit
90885730ad
@ -22,7 +22,7 @@ import mockData from '../../../mockData/MigrateWizard.mock'
|
||||
|
||||
jest.mock('axios', () => mockAxios)
|
||||
|
||||
let wrapper, i18n, store, mocks
|
||||
let wrapper, i18n, store, mocks, router
|
||||
|
||||
const state = {}
|
||||
const actions = {
|
||||
@ -62,8 +62,10 @@ const factory = (opts = {}) => {
|
||||
i18n = opts.i18n || i18n
|
||||
store = opts.store || store
|
||||
mocks = opts.mocks || mocks
|
||||
router = opts.router || router
|
||||
|
||||
return common.createFactory(MigrateWizard, {
|
||||
router,
|
||||
i18n,
|
||||
store,
|
||||
mocks,
|
||||
@ -81,6 +83,9 @@ describe('Views > compute > MigrateWizard.vue', () => {
|
||||
if (wrapper) {
|
||||
wrapper.destroy()
|
||||
}
|
||||
if (router && router.currentRoute.name !== 'home') {
|
||||
router.replace({ name: 'home' })
|
||||
}
|
||||
|
||||
if (i18n.locale !== 'en') {
|
||||
i18n.locale = 'en'
|
||||
@ -331,7 +336,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
|
||||
})
|
||||
|
||||
describe('submitForm()', () => {
|
||||
it('check api is called when selectedHost.requiresStorageMotion is true', async (done) => {
|
||||
it('check api is called when selectedHost.requiresStorageMotion is true and isUserVm=true', async (done) => {
|
||||
const mockData = {
|
||||
migratevirtualmachineresponse: {
|
||||
jobid: 'test-job-id'
|
||||
@ -344,7 +349,15 @@ describe('Views > compute > MigrateWizard.vue', () => {
|
||||
}
|
||||
}
|
||||
|
||||
router = common.createMockRouter([{
|
||||
name: 'testRouter1',
|
||||
path: '/test-router-1',
|
||||
meta: {
|
||||
name: 'vm'
|
||||
}
|
||||
}])
|
||||
wrapper = factory({
|
||||
router: router,
|
||||
props: {
|
||||
resource: {
|
||||
id: 'test-resource-id',
|
||||
@ -359,6 +372,8 @@ describe('Views > compute > MigrateWizard.vue', () => {
|
||||
}
|
||||
}
|
||||
})
|
||||
router.push({ name: 'testRouter1' })
|
||||
|
||||
jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
|
||||
mockAxios.mockResolvedValue(mockData)
|
||||
await wrapper.vm.$nextTick()
|
||||
@ -382,7 +397,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('check api is called when selectedHost.requiresStorageMotion is false', async (done) => {
|
||||
it('check api is called when selectedHost.requiresStorageMotion is false and isUserVm=true', async (done) => {
|
||||
const mockData = {
|
||||
migratevirtualmachineresponse: {
|
||||
jobid: 'test-job-id'
|
||||
@ -394,6 +409,14 @@ describe('Views > compute > MigrateWizard.vue', () => {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
router = common.createMockRouter([{
|
||||
name: 'testRouter2',
|
||||
path: '/test-router-2',
|
||||
meta: {
|
||||
name: 'vm'
|
||||
}
|
||||
}])
|
||||
wrapper = factory({
|
||||
props: {
|
||||
resource: {
|
||||
@ -409,6 +432,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
|
||||
}
|
||||
}
|
||||
})
|
||||
router.push({ name: 'testRouter2' })
|
||||
jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
|
||||
|
||||
mockAxios.mockResolvedValue(mockData)
|
||||
@ -434,10 +458,10 @@ describe('Views > compute > MigrateWizard.vue', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('check store dispatch `AddAsyncJob` and $pollJob have successMethod() is called with requiresStorageMotion is true', async (done) => {
|
||||
it('check api is called when isUserVm=false', async (done) => {
|
||||
const mockData = {
|
||||
migratevirtualmachinewithvolumeresponse: {
|
||||
jobid: 'test-job-id-case-1'
|
||||
migratesystemvmresponse: {
|
||||
jobid: 'test-job-id'
|
||||
},
|
||||
queryasyncjobresultresponse: {
|
||||
jobstatus: 1,
|
||||
@ -446,7 +470,16 @@ describe('Views > compute > MigrateWizard.vue', () => {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
router = common.createMockRouter([{
|
||||
name: 'testRouter3',
|
||||
path: '/test-router-3',
|
||||
meta: {
|
||||
name: 'test'
|
||||
}
|
||||
}])
|
||||
wrapper = factory({
|
||||
router: router,
|
||||
props: {
|
||||
resource: {
|
||||
id: 'test-resource-id',
|
||||
@ -461,8 +494,70 @@ describe('Views > compute > MigrateWizard.vue', () => {
|
||||
}
|
||||
}
|
||||
})
|
||||
jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
|
||||
router.push({ name: 'testRouter3' })
|
||||
|
||||
jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
|
||||
mockAxios.mockResolvedValue(mockData)
|
||||
await wrapper.vm.$nextTick()
|
||||
await wrapper.vm.submitForm()
|
||||
|
||||
setTimeout(() => {
|
||||
expect(mockAxios).toHaveBeenCalled()
|
||||
expect(mockAxios).toHaveBeenCalledWith({
|
||||
url: '/',
|
||||
method: 'GET',
|
||||
data: new URLSearchParams(),
|
||||
params: {
|
||||
command: 'migrateSystemVm',
|
||||
hostid: 'test-host-id',
|
||||
virtualmachineid: 'test-resource-id',
|
||||
response: 'json'
|
||||
}
|
||||
})
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('check store dispatch `AddAsyncJob` and $pollJob have successMethod() is called with requiresStorageMotion is true', async (done) => {
|
||||
const mockData = {
|
||||
migratevirtualmachinewithvolumeresponse: {
|
||||
jobid: 'test-job-id-case-1'
|
||||
},
|
||||
queryasyncjobresultresponse: {
|
||||
jobstatus: 1,
|
||||
jobresult: {
|
||||
name: 'test-name-value'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
router = common.createMockRouter([{
|
||||
name: 'testRouter4',
|
||||
path: '/test-router-4',
|
||||
meta: {
|
||||
name: 'vm'
|
||||
}
|
||||
}])
|
||||
wrapper = factory({
|
||||
router: router,
|
||||
props: {
|
||||
resource: {
|
||||
id: 'test-resource-id',
|
||||
name: 'test-resource-name'
|
||||
}
|
||||
},
|
||||
data: {
|
||||
selectedHost: {
|
||||
requiresStorageMotion: true,
|
||||
id: 'test-host-id',
|
||||
name: 'test-host-name'
|
||||
}
|
||||
}
|
||||
})
|
||||
router.push({ name: 'testRouter4' })
|
||||
|
||||
jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
|
||||
mockAxios.mockResolvedValue(mockData)
|
||||
|
||||
await wrapper.vm.$nextTick()
|
||||
@ -489,7 +584,16 @@ describe('Views > compute > MigrateWizard.vue', () => {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
router = common.createMockRouter([{
|
||||
name: 'testRouter5',
|
||||
path: '/test-router-5',
|
||||
meta: {
|
||||
name: 'vm'
|
||||
}
|
||||
}])
|
||||
wrapper = factory({
|
||||
router: router,
|
||||
props: {
|
||||
resource: {
|
||||
id: 'test-resource-id',
|
||||
@ -504,8 +608,62 @@ describe('Views > compute > MigrateWizard.vue', () => {
|
||||
}
|
||||
}
|
||||
})
|
||||
jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
|
||||
router.push({ name: 'testRouter5' })
|
||||
|
||||
jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
|
||||
mockAxios.mockResolvedValue(mockData)
|
||||
|
||||
await wrapper.vm.$nextTick()
|
||||
await wrapper.vm.submitForm()
|
||||
|
||||
setTimeout(() => {
|
||||
expect(actions.AddAsyncJob).toHaveBeenCalled()
|
||||
expect(mocks.$pollJob).toHaveBeenCalled()
|
||||
expect(wrapper.emitted()['close-action'][0]).toEqual([])
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('check store dispatch `AddAsyncJob` and $pollJob have successMethod() is called with isUserVm is false', async (done) => {
|
||||
const mockData = {
|
||||
migratesystemvmresponse: {
|
||||
jobid: 'test-job-id-case-2'
|
||||
},
|
||||
queryasyncjobresultresponse: {
|
||||
jobstatus: 1,
|
||||
jobresult: {
|
||||
name: 'test-name-value'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
router = common.createMockRouter([{
|
||||
name: 'testRouter6',
|
||||
path: '/test-router-6',
|
||||
meta: {
|
||||
name: 'test'
|
||||
}
|
||||
}])
|
||||
wrapper = factory({
|
||||
router: router,
|
||||
props: {
|
||||
resource: {
|
||||
id: 'test-resource-id',
|
||||
name: 'test-resource-name'
|
||||
}
|
||||
},
|
||||
data: {
|
||||
selectedHost: {
|
||||
requiresStorageMotion: false,
|
||||
id: 'test-host-id',
|
||||
name: 'test-host-name'
|
||||
}
|
||||
}
|
||||
})
|
||||
router.push({ name: 'testRouter6' })
|
||||
|
||||
jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
|
||||
mockAxios.mockResolvedValue(mockData)
|
||||
|
||||
await wrapper.vm.$nextTick()
|
||||
@ -522,7 +680,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
|
||||
|
||||
it('check store dispatch `AddAsyncJob` and $pollJob have errorMethod() is called', async (done) => {
|
||||
const mockData = {
|
||||
migratevirtualmachinewithvolumeresponse: {
|
||||
migratesystemvmresponse: {
|
||||
jobid: 'test-job-id-case-3'
|
||||
},
|
||||
queryasyncjobresultresponse: {
|
||||
@ -565,7 +723,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
|
||||
|
||||
it('check store dispatch `AddAsyncJob` and $pollJob have catchMethod() is called', async (done) => {
|
||||
const mockData = {
|
||||
migratevirtualmachinewithvolumeresponse: {
|
||||
migratesystemvmresponse: {
|
||||
jobid: 'test-job-id-case-4'
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user