diff --git a/ui/tests/unit/views/AutogenView.spec.js b/ui/tests/unit/views/AutogenView.spec.js index fbae93c9cf0f..8823894dbcc8 100644 --- a/ui/tests/unit/views/AutogenView.spec.js +++ b/ui/tests/unit/views/AutogenView.spec.js @@ -1078,11 +1078,11 @@ describe('Views > AutogenView.vue', () => { }) expect(wrapper.vm.currentAction.params).toEqual([ - { name: 'id', type: 'string' }, - { name: 'name', type: 'string' }, { name: 'column1', type: 'string' }, { name: 'column2', type: 'string' }, - { name: 'column3', type: 'string' } + { name: 'column3', type: 'string' }, + { name: 'name', type: 'string' }, + { name: 'id', type: 'string' } ]) expect(wrapper.vm.currentAction.paramFields).toEqual([]) expect(wrapper.vm.showAction).toBeTruthy() @@ -1127,11 +1127,11 @@ describe('Views > AutogenView.vue', () => { }) expect(wrapper.vm.currentAction.params).toEqual([ - { name: 'id', type: 'string' }, - { name: 'name', type: 'string' }, { name: 'column1', type: 'string' }, { name: 'column2', type: 'string' }, - { name: 'column3', type: 'string' } + { name: 'column3', type: 'string' }, + { name: 'name', type: 'string' }, + { name: 'id', type: 'string' } ]) expect(wrapper.vm.currentAction.paramFields).toEqual([ { name: 'id', type: 'string' }, @@ -2141,7 +2141,6 @@ describe('Views > AutogenView.vue', () => { { name: 'id', type: 'uuid' } ], paramFields: [ - { name: 'id', type: 'uuid', description: '', required: false } ], mapping: {} }, @@ -2191,8 +2190,7 @@ describe('Views > AutogenView.vue', () => { { name: 'id', type: 'uuid' } ], paramFields: [ - { name: 'name', type: 'string', description: '', required: false }, - { name: 'id', type: 'uuid', description: '', required: false } + { name: 'name', type: 'string', description: '', required: false } ], mapping: {} }, @@ -2259,6 +2257,7 @@ describe('Views > AutogenView.vue', () => { spyConsole.log = jest.spyOn(console, 'log').mockImplementation(() => {}) wrapper.vm.$nextTick(() => { + wrapper.vm.form.getFieldDecorator('column1', { initialValue: null }) const event = document.createEvent('Event') wrapper.vm.execSubmit(event) diff --git a/ui/tests/unit/views/compute/MigrateWizard.spec.js b/ui/tests/unit/views/compute/MigrateWizard.spec.js index 14c8a899233b..eef8722e1b68 100644 --- a/ui/tests/unit/views/compute/MigrateWizard.spec.js +++ b/ui/tests/unit/views/compute/MigrateWizard.spec.js @@ -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,6 +458,67 @@ describe('Views > compute > MigrateWizard.vue', () => { }) }) + it('check api is called when isUserVm=false', async (done) => { + const mockData = { + migratesystemvmresponse: { + jobid: 'test-job-id' + }, + queryasyncjobresultresponse: { + jobstatus: 1, + jobresult: { + name: 'test-name-value' + } + } + } + + router = common.createMockRouter([{ + name: 'testRouter3', + path: '/test-router-3', + meta: { + name: 'test' + } + }]) + 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: '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: { @@ -446,7 +531,16 @@ describe('Views > compute > MigrateWizard.vue', () => { } } } + + router = common.createMockRouter([{ + name: 'testRouter4', + path: '/test-router-4', + meta: { + name: 'vm' + } + }]) wrapper = factory({ + router: router, props: { resource: { id: 'test-resource-id', @@ -461,8 +555,9 @@ describe('Views > compute > MigrateWizard.vue', () => { } } }) - jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {}) + 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', () => { } } }) + 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' } }