You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ro...@apache.org on 2021/02/24 09:13:06 UTC

[cloudstack] branch master updated: ui: Fix UI unit test failures in master (#4719)

This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/master by this push:
     new 9088573  ui: Fix UI unit test failures in master (#4719)
9088573 is described below

commit 90885730adb022b2c9742c002aab9b644d4f88de
Author: Hoang Nguyen <ho...@unitech.vn>
AuthorDate: Wed Feb 24 16:12:50 2021 +0700

    ui: Fix UI unit test failures in master (#4719)
---
 ui/tests/unit/views/compute/MigrateWizard.spec.js | 170 +++++++++++++++++++++-
 1 file changed, 164 insertions(+), 6 deletions(-)

diff --git a/ui/tests/unit/views/compute/MigrateWizard.spec.js b/ui/tests/unit/views/compute/MigrateWizard.spec.js
index 14c8a89..eef8722 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'
           }
         }