Skip to content

Commit 9088573

Browse files
author
Hoang Nguyen
authored
ui: Fix UI unit test failures in master (#4719)
1 parent 7b2724a commit 9088573

1 file changed

Lines changed: 164 additions & 6 deletions

File tree

ui/tests/unit/views/compute/MigrateWizard.spec.js

Lines changed: 164 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import mockData from '../../../mockData/MigrateWizard.mock'
2222

2323
jest.mock('axios', () => mockAxios)
2424

25-
let wrapper, i18n, store, mocks
25+
let wrapper, i18n, store, mocks, router
2626

2727
const state = {}
2828
const actions = {
@@ -62,8 +62,10 @@ const factory = (opts = {}) => {
6262
i18n = opts.i18n || i18n
6363
store = opts.store || store
6464
mocks = opts.mocks || mocks
65+
router = opts.router || router
6566

6667
return common.createFactory(MigrateWizard, {
68+
router,
6769
i18n,
6870
store,
6971
mocks,
@@ -81,6 +83,9 @@ describe('Views > compute > MigrateWizard.vue', () => {
8183
if (wrapper) {
8284
wrapper.destroy()
8385
}
86+
if (router && router.currentRoute.name !== 'home') {
87+
router.replace({ name: 'home' })
88+
}
8489

8590
if (i18n.locale !== 'en') {
8691
i18n.locale = 'en'
@@ -331,7 +336,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
331336
})
332337

333338
describe('submitForm()', () => {
334-
it('check api is called when selectedHost.requiresStorageMotion is true', async (done) => {
339+
it('check api is called when selectedHost.requiresStorageMotion is true and isUserVm=true', async (done) => {
335340
const mockData = {
336341
migratevirtualmachineresponse: {
337342
jobid: 'test-job-id'
@@ -344,7 +349,15 @@ describe('Views > compute > MigrateWizard.vue', () => {
344349
}
345350
}
346351

352+
router = common.createMockRouter([{
353+
name: 'testRouter1',
354+
path: '/test-router-1',
355+
meta: {
356+
name: 'vm'
357+
}
358+
}])
347359
wrapper = factory({
360+
router: router,
348361
props: {
349362
resource: {
350363
id: 'test-resource-id',
@@ -359,6 +372,8 @@ describe('Views > compute > MigrateWizard.vue', () => {
359372
}
360373
}
361374
})
375+
router.push({ name: 'testRouter1' })
376+
362377
jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
363378
mockAxios.mockResolvedValue(mockData)
364379
await wrapper.vm.$nextTick()
@@ -382,7 +397,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
382397
})
383398
})
384399

385-
it('check api is called when selectedHost.requiresStorageMotion is false', async (done) => {
400+
it('check api is called when selectedHost.requiresStorageMotion is false and isUserVm=true', async (done) => {
386401
const mockData = {
387402
migratevirtualmachineresponse: {
388403
jobid: 'test-job-id'
@@ -394,6 +409,14 @@ describe('Views > compute > MigrateWizard.vue', () => {
394409
}
395410
}
396411
}
412+
413+
router = common.createMockRouter([{
414+
name: 'testRouter2',
415+
path: '/test-router-2',
416+
meta: {
417+
name: 'vm'
418+
}
419+
}])
397420
wrapper = factory({
398421
props: {
399422
resource: {
@@ -409,6 +432,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
409432
}
410433
}
411434
})
435+
router.push({ name: 'testRouter2' })
412436
jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
413437

414438
mockAxios.mockResolvedValue(mockData)
@@ -434,6 +458,67 @@ describe('Views > compute > MigrateWizard.vue', () => {
434458
})
435459
})
436460

461+
it('check api is called when isUserVm=false', async (done) => {
462+
const mockData = {
463+
migratesystemvmresponse: {
464+
jobid: 'test-job-id'
465+
},
466+
queryasyncjobresultresponse: {
467+
jobstatus: 1,
468+
jobresult: {
469+
name: 'test-name-value'
470+
}
471+
}
472+
}
473+
474+
router = common.createMockRouter([{
475+
name: 'testRouter3',
476+
path: '/test-router-3',
477+
meta: {
478+
name: 'test'
479+
}
480+
}])
481+
wrapper = factory({
482+
router: router,
483+
props: {
484+
resource: {
485+
id: 'test-resource-id',
486+
name: 'test-resource-name'
487+
}
488+
},
489+
data: {
490+
selectedHost: {
491+
requiresStorageMotion: true,
492+
id: 'test-host-id',
493+
name: 'test-host-name'
494+
}
495+
}
496+
})
497+
router.push({ name: 'testRouter3' })
498+
499+
jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
500+
mockAxios.mockResolvedValue(mockData)
501+
await wrapper.vm.$nextTick()
502+
await wrapper.vm.submitForm()
503+
504+
setTimeout(() => {
505+
expect(mockAxios).toHaveBeenCalled()
506+
expect(mockAxios).toHaveBeenCalledWith({
507+
url: '/',
508+
method: 'GET',
509+
data: new URLSearchParams(),
510+
params: {
511+
command: 'migrateSystemVm',
512+
hostid: 'test-host-id',
513+
virtualmachineid: 'test-resource-id',
514+
response: 'json'
515+
}
516+
})
517+
518+
done()
519+
})
520+
})
521+
437522
it('check store dispatch `AddAsyncJob` and $pollJob have successMethod() is called with requiresStorageMotion is true', async (done) => {
438523
const mockData = {
439524
migratevirtualmachinewithvolumeresponse: {
@@ -446,7 +531,16 @@ describe('Views > compute > MigrateWizard.vue', () => {
446531
}
447532
}
448533
}
534+
535+
router = common.createMockRouter([{
536+
name: 'testRouter4',
537+
path: '/test-router-4',
538+
meta: {
539+
name: 'vm'
540+
}
541+
}])
449542
wrapper = factory({
543+
router: router,
450544
props: {
451545
resource: {
452546
id: 'test-resource-id',
@@ -461,8 +555,9 @@ describe('Views > compute > MigrateWizard.vue', () => {
461555
}
462556
}
463557
})
464-
jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
558+
router.push({ name: 'testRouter4' })
465559

560+
jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
466561
mockAxios.mockResolvedValue(mockData)
467562

468563
await wrapper.vm.$nextTick()
@@ -489,7 +584,16 @@ describe('Views > compute > MigrateWizard.vue', () => {
489584
}
490585
}
491586
}
587+
588+
router = common.createMockRouter([{
589+
name: 'testRouter5',
590+
path: '/test-router-5',
591+
meta: {
592+
name: 'vm'
593+
}
594+
}])
492595
wrapper = factory({
596+
router: router,
493597
props: {
494598
resource: {
495599
id: 'test-resource-id',
@@ -504,8 +608,62 @@ describe('Views > compute > MigrateWizard.vue', () => {
504608
}
505609
}
506610
})
611+
router.push({ name: 'testRouter5' })
612+
507613
jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
614+
mockAxios.mockResolvedValue(mockData)
508615

616+
await wrapper.vm.$nextTick()
617+
await wrapper.vm.submitForm()
618+
619+
setTimeout(() => {
620+
expect(actions.AddAsyncJob).toHaveBeenCalled()
621+
expect(mocks.$pollJob).toHaveBeenCalled()
622+
expect(wrapper.emitted()['close-action'][0]).toEqual([])
623+
624+
done()
625+
})
626+
})
627+
628+
it('check store dispatch `AddAsyncJob` and $pollJob have successMethod() is called with isUserVm is false', async (done) => {
629+
const mockData = {
630+
migratesystemvmresponse: {
631+
jobid: 'test-job-id-case-2'
632+
},
633+
queryasyncjobresultresponse: {
634+
jobstatus: 1,
635+
jobresult: {
636+
name: 'test-name-value'
637+
}
638+
}
639+
}
640+
641+
router = common.createMockRouter([{
642+
name: 'testRouter6',
643+
path: '/test-router-6',
644+
meta: {
645+
name: 'test'
646+
}
647+
}])
648+
wrapper = factory({
649+
router: router,
650+
props: {
651+
resource: {
652+
id: 'test-resource-id',
653+
name: 'test-resource-name'
654+
}
655+
},
656+
data: {
657+
selectedHost: {
658+
requiresStorageMotion: false,
659+
id: 'test-host-id',
660+
name: 'test-host-name'
661+
}
662+
}
663+
})
664+
router.push({ name: 'testRouter6' })
665+
666+
jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
509667
mockAxios.mockResolvedValue(mockData)
510668

511669
await wrapper.vm.$nextTick()
@@ -522,7 +680,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
522680

523681
it('check store dispatch `AddAsyncJob` and $pollJob have errorMethod() is called', async (done) => {
524682
const mockData = {
525-
migratevirtualmachinewithvolumeresponse: {
683+
migratesystemvmresponse: {
526684
jobid: 'test-job-id-case-3'
527685
},
528686
queryasyncjobresultresponse: {
@@ -565,7 +723,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
565723

566724
it('check store dispatch `AddAsyncJob` and $pollJob have catchMethod() is called', async (done) => {
567725
const mockData = {
568-
migratevirtualmachinewithvolumeresponse: {
726+
migratesystemvmresponse: {
569727
jobid: 'test-job-id-case-4'
570728
}
571729
}

0 commit comments

Comments
 (0)