This is an automated email from the ASF dual-hosted git repository.
rohit pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/main by this push:
new 450de92 ui: Fix failing UI unit test main branch (#5262)
450de92 is described below
commit 450de92e6cdc6d5611ca4ba701660826d6c70141
Author: Hoang Nguyen <[email protected]>
AuthorDate: Tue Aug 3 12:23:10 2021 +0700
ui: Fix failing UI unit test main branch (#5262)
* fix test unit & error lint main branch
* hidden warning log
* hidden warning log & remove comment
* fix test fail
* fix test sort params
* fix test fail
* fix test fail
* Remove redundant comments
---
ui/tests/common/index.js | 4 +-
ui/tests/mock/mockStore.js | 13 +-
ui/tests/mockData/AutogenView.mock.json | 96 ++++++-
ui/tests/mockData/MigrateWizard.mock.json | 46 +++-
ui/tests/unit/views/AutogenView.spec.js | 319 +++++++++-------------
ui/tests/unit/views/compute/MigrateWizard.spec.js | 72 ++---
6 files changed, 298 insertions(+), 252 deletions(-)
diff --git a/ui/tests/common/index.js b/ui/tests/common/index.js
index 628e059..9499851 100644
--- a/ui/tests/common/index.js
+++ b/ui/tests/common/index.js
@@ -43,8 +43,8 @@ function createMockI18n (locale = 'en', messages = {}) {
return mockI18n.mock(locale, messages)
}
-function createMockStore (state = {}, actions = {}) {
- return mockStore.mock(state, actions)
+function createMockStore (state = {}, actions = {}, mutation = {}) {
+ return mockStore.mock(state, actions, mutation)
}
function decodeHtml (html) {
diff --git a/ui/tests/mock/mockStore.js b/ui/tests/mock/mockStore.js
index 6d94906..4f005c3 100644
--- a/ui/tests/mock/mockStore.js
+++ b/ui/tests/mock/mockStore.js
@@ -19,7 +19,7 @@ import Vuex from 'vuex'
const mockStore = {
state: {},
- mock: (state, actions) => {
+ mock: (state, actions, mutations) => {
mockStore.state = {
app: {
device: 'desktop'
@@ -27,11 +27,16 @@ const mockStore = {
user: {},
permission: {}
}
+ mockStore.mutations = {}
if (state && Object.keys(state).length > 0) {
mockStore.state = { ...mockStore.state, ...state }
}
+ if (mutations && Object.keys(mutations).length > 0) {
+ mockStore.mutations = { ...mockStore.mutations, ...mutations }
+ }
+
if (!actions) {
actions = {}
}
@@ -40,9 +45,11 @@ const mockStore = {
state: mockStore.state,
getters: {
apis: () => mockStore.state.user.apis,
- userInfo: () => mockStore.state.user.info
+ userInfo: () => mockStore.state.user.info,
+ headerNotices: () => mockStore.state.user.headerNotices
},
- actions
+ actions,
+ mutations
})
}
}
diff --git a/ui/tests/mockData/AutogenView.mock.json
b/ui/tests/mockData/AutogenView.mock.json
index d1df58f..410391e 100644
--- a/ui/tests/mockData/AutogenView.mock.json
+++ b/ui/tests/mockData/AutogenView.mock.json
@@ -34,7 +34,26 @@
"label.view.console": "view-console-en",
"error.fetching.async.job.result": "Error encountered while fetching
async job result",
"label.cancel": "cancel",
- "label.ok": "ok"
+ "label.ok": "ok",
+ "label.close": "close",
+ "label.success": "close",
+ "state.failed": "state.failed",
+ "state.inprogress": "state.inprogress",
+ "label.state": "label.state",
+ "label.hostname": "label.hostname",
+ "label.hostid": "label.hostid",
+ "label.zonename": "label.zonename",
+ "label.zone": "label.zone",
+ "label.zoneid": "label.zoneid",
+ "label.ip": "label.ip",
+ "label.ipaddress": "label.ipaddress",
+ "label.privateip": "label.privateip",
+ "label.linklocalip": "label.linklocalip",
+ "label.size": "label.size",
+ "label.sizegb": "label.sizegb",
+ "label.current": "label.current",
+ "label.created": "label.created",
+ "label.order": "label.order"
},
"de": {
"labelname": "test-name-de",
@@ -70,7 +89,26 @@
"label.view.console": "view-console-de",
"error.fetching.async.job.result": "Error encountered while fetching
async job result",
"label.cancel": "cancel",
- "label.ok": "ok"
+ "label.ok": "ok",
+ "label.close": "close",
+ "label.success": "close",
+ "state.failed": "state.failed",
+ "state.inprogress": "state.inprogress",
+ "label.state": "label.state",
+ "label.hostname": "label.hostname",
+ "label.hostid": "label.hostid",
+ "label.zonename": "label.zonename",
+ "label.zone": "label.zone",
+ "label.zoneid": "label.zoneid",
+ "label.ip": "label.ip",
+ "label.ipaddress": "label.ipaddress",
+ "label.privateip": "label.privateip",
+ "label.linklocalip": "label.linklocalip",
+ "label.size": "label.size",
+ "label.sizegb": "label.sizegb",
+ "label.current": "label.current",
+ "label.created": "label.created",
+ "label.order": "label.order"
}
},
"apis": {
@@ -157,6 +195,56 @@
],
"response": []
},
+ "testApiNameCase7": {
+ "params": [
+ {
+ "name": "column2",
+ "type": "string"
+ },
+ {
+ "name": "column1",
+ "type": "string"
+ },
+ {
+ "name": "column3",
+ "type": "string"
+ },
+ {
+ "name": "name",
+ "type": "string"
+ },
+ {
+ "name": "id",
+ "type": "string"
+ }
+ ],
+ "response": []
+ },
+ "testApiNameCase8": {
+ "params": [
+ {
+ "name": "column2",
+ "type": "string"
+ },
+ {
+ "name": "column1",
+ "type": "string"
+ },
+ {
+ "name": "column3",
+ "type": "string"
+ },
+ {
+ "name": "name",
+ "type": "string"
+ },
+ {
+ "name": "id",
+ "type": "string"
+ }
+ ],
+ "response": []
+ },
"listTemplates": {
"params": {},
"response": []
@@ -194,5 +282,7 @@
"roletype": "Normal",
"account": "test-account",
"domainid": "test-domain-id"
- }
+ },
+ "headerNotices": [],
+ "asyncJobIds": []
}
\ No newline at end of file
diff --git a/ui/tests/mockData/MigrateWizard.mock.json
b/ui/tests/mockData/MigrateWizard.mock.json
index 0c581f17..4ff673c 100644
--- a/ui/tests/mockData/MigrateWizard.mock.json
+++ b/ui/tests/mockData/MigrateWizard.mock.json
@@ -8,7 +8,28 @@
"select": "select-en",
"ok": "ok-en",
"message.load.host.failed": "Failed to load hosts",
- "message.migrating.vm.to.host.failed": "Failed to migrate VM to host"
+ "message.migrating.vm.to.host.failed": "Failed to migrate VM to host",
+ "label.name": "label.name",
+ "label.suitability": "label.suitability",
+ "label.cpuused": "label.cpuused",
+ "label.memoryallocated": "label.memoryallocated",
+ "label.memused": "label.memused",
+ "label.cluster": "label.cluster",
+ "label.pod": "label.pod",
+ "label.storage.migration.required": "label.storage.migration.required",
+ "label.select": "label.select",
+ "label.search": "label.search",
+ "label.ok": "label.ok",
+ "label.total": "label.total",
+ "label.items": "label.items",
+ "label.page": "label.page",
+ "label.no": "label.no",
+ "label.migrating": "label.migrating",
+ "message.request.failed": "message.request.failed",
+ "message.success.migrating": "message.success.migrating",
+ "message.migrating.processing": "message.migrating.processing",
+ "message.migrating.failed": "message.migrating.failed",
+ "error.fetching.async.job.result": "error.fetching.async.job.result"
},
"de": {
"name": "name-de",
@@ -18,7 +39,28 @@
"select": "select-de",
"ok": "ok-de",
"message.load.host.failed": "Failed to load hosts",
- "message.migrating.vm.to.host.failed": "Failed to migrate VM to host"
+ "message.migrating.vm.to.host.failed": "Failed to migrate VM to host",
+ "label.name": "label.name",
+ "label.suitability": "label.suitability",
+ "label.cpuused": "label.cpuused",
+ "label.memoryallocated": "label.memoryallocated",
+ "label.memused": "label.memused",
+ "label.cluster": "label.cluster",
+ "label.pod": "label.pod",
+ "label.storage.migration.required": "label.storage.migration.required",
+ "label.select": "label.select",
+ "label.search": "label.search",
+ "label.ok": "label.ok",
+ "label.total": "label.total",
+ "label.items": "label.items",
+ "label.page": "label.page",
+ "label.no": "label.no",
+ "label.migrating": "label.migrating",
+ "message.request.failed": "message.request.failed",
+ "message.success.migrating": "message.success.migrating",
+ "message.migrating.processing": "message.migrating.processing",
+ "message.migrating.failed": "message.migrating.failed",
+ "error.fetching.async.job.result": "error.fetching.async.job.result"
}
}
}
\ No newline at end of file
diff --git a/ui/tests/unit/views/AutogenView.spec.js
b/ui/tests/unit/views/AutogenView.spec.js
index a866aae..073dede 100644
--- a/ui/tests/unit/views/AutogenView.spec.js
+++ b/ui/tests/unit/views/AutogenView.spec.js
@@ -29,13 +29,20 @@ let router, store, i18n, mocks
const state = {
user: {
apis: mockData.apis,
- info: mockData.info
+ info: mockData.info,
+ headerNotices: mockData.headerNotices,
+ asyncJobIds: mockData.asyncJobIds
}
}
-store = common.createMockStore(state)
-i18n = common.createMockI18n('en', mockData.messages)
+const mutations = {
+ SET_HEADER_NOTICES: (state, jobsJsonArray) => {
+ state.user.headerNotices = jobsJsonArray
+ }
+}
+store = common.createMockStore(state, {}, mutations)
+i18n = common.createMockI18n('en', mockData.messages)
const spyConsole = {
log: null,
warn: null
@@ -748,6 +755,11 @@ describe('Views > AutogenView.vue', () => {
})
it('check $notifyError is called when api is called with throw error',
(done) => {
+ const errorMock = {
+ response: {},
+ message: 'Error: throw exception error'
+ }
+ mockAxios.mockRejectedValue(errorMock)
router = common.createMockRouter([{
name: 'testRouter22',
path: '/test-router-22',
@@ -758,13 +770,7 @@ describe('Views > AutogenView.vue', () => {
}])
wrapper = factory({ router: router })
-
- const errorMock = {
- response: {},
- message: 'Error: throw exception error'
- }
router.push({ name: 'testRouter22' })
- mockAxios.mockRejectedValue(errorMock)
setTimeout(() => {
expect(mocks.$notifyError).toHaveBeenCalledTimes(1)
@@ -774,6 +780,13 @@ describe('Views > AutogenView.vue', () => {
})
it('check $notifyError is called and router path = /exception/404 when
api is called with throw error', (done) => {
+ const errorMock = {
+ response: {
+ status: 430
+ },
+ message: 'Error: Request Header Fields Too Large'
+ }
+ mockAxios.mockRejectedValue(errorMock)
router = common.createMockRouter([{
name: 'testRouter23',
path: '/test-router-23',
@@ -784,15 +797,7 @@ describe('Views > AutogenView.vue', () => {
}])
wrapper = factory({ router: router })
-
- const errorMock = {
- response: {
- status: 430
- },
- message: 'Error: Request Header Fields Too Large'
- }
router.push({ name: 'testRouter23' })
- mockAxios.mockRejectedValue(errorMock)
setTimeout(() => {
expect(mocks.$notifyError).toHaveBeenCalledTimes(1)
@@ -804,6 +809,13 @@ describe('Views > AutogenView.vue', () => {
})
it('check $notifyError is called and router path = /exception/500 when
api is called with throw error', (done) => {
+ const errorMock = {
+ response: {
+ status: 530
+ },
+ message: 'Error: Site is frozen'
+ }
+ mockAxios.mockRejectedValue(errorMock)
router = common.createMockRouter([{
name: 'testRouter23',
path: '/test-router-23',
@@ -814,15 +826,7 @@ describe('Views > AutogenView.vue', () => {
}])
wrapper = factory({ router: router })
-
- const errorMock = {
- response: {
- status: 530
- },
- message: 'Error: Site is frozen'
- }
router.push({ name: 'testRouter23' })
- mockAxios.mockRejectedValue(errorMock)
setTimeout(() => {
expect(mocks.$notifyError).toHaveBeenCalledTimes(1)
@@ -1068,74 +1072,64 @@ describe('Views > AutogenView.vue', () => {
it('check currentAction params and paramsField when execAction() is
called', () => {
wrapper = factory()
-
- wrapper.vm.$nextTick(() => {
- wrapper.vm.execAction({
- api: 'testApiNameCase5'
- })
-
- expect(wrapper.vm.currentAction.params).toEqual([
- { name: 'column1', type: 'string' },
- { name: 'column2', 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()
- })
+ wrapper.vm.$nextTick()
+ wrapper.vm.execAction({
+ api: 'testApiNameCase5'
+ })
+ expect(wrapper.vm.currentAction.params).toEqual([
+ { name: 'column1', type: 'string' },
+ { name: 'column2', 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()
})
it('check currentAction params and paramsField when execAction() is
called with args is exists', () => {
wrapper = factory()
-
- wrapper.vm.$nextTick(() => {
- wrapper.vm.execAction({
- api: 'testApiNameCase5',
- args: ['column1', 'column2', 'column3']
- })
-
- expect(wrapper.vm.currentAction.params).toEqual([
- { name: 'column1', type: 'string' },
- { name: 'column2', type: 'string' },
- { name: 'column3', type: 'string' },
- { name: 'name', type: 'string' },
- { name: 'id', type: 'string' }
- ])
- expect(wrapper.vm.currentAction.paramFields).toEqual([
- { name: 'column1', type: 'string' },
- { name: 'column2', type: 'string' },
- { name: 'column3', type: 'string' }
- ])
- expect(wrapper.vm.showAction).toBeTruthy()
- })
+ wrapper.vm.execAction({
+ api: 'testApiNameCase7',
+ args: ['column1', 'column2', 'column3']
+ })
+ expect(wrapper.vm.currentAction.params).toEqual([
+ { name: 'column1', type: 'string' },
+ { name: 'column2', type: 'string' },
+ { name: 'column3', type: 'string' },
+ { name: 'name', type: 'string' },
+ { name: 'id', type: 'string' }
+ ])
+ expect(wrapper.vm.currentAction.paramFields).toEqual([
+ { name: 'column1', type: 'string' },
+ { name: 'column2', type: 'string' },
+ { name: 'column3', type: 'string' }
+ ])
+ expect(wrapper.vm.showAction).toBeTruthy()
})
it('check currentAction params and paramsField when execAction() is
called with args is function', () => {
wrapper = factory()
-
- wrapper.vm.$nextTick(() => {
- wrapper.vm.execAction({
- api: 'testApiNameCase5',
- resource: { id: 'test-id-value', name: 'test-name-value' },
- args: (record, store) => {
- return ['Admin'].includes(store.userInfo.roletype) ? ['column1',
'column2', 'column3'] : ['id', 'name']
- }
- })
-
- expect(wrapper.vm.currentAction.params).toEqual([
- { name: 'column1', type: 'string' },
- { name: 'column2', type: 'string' },
- { name: 'column3', type: 'string' },
- { name: 'name', type: 'string' },
- { name: 'id', type: 'string' }
- ])
- expect(wrapper.vm.currentAction.paramFields).toEqual([
- { name: 'id', type: 'string' },
- { name: 'name', type: 'string' }
- ])
- expect(wrapper.vm.showAction).toBeTruthy()
- })
+ wrapper.vm.$nextTick()
+ wrapper.vm.execAction({
+ api: 'testApiNameCase8',
+ resource: { id: 'test-id-value', name: 'test-name-value' },
+ args: (record, store) => {
+ return ['Admin'].includes(store.userInfo.roletype) ? ['column1',
'column2', 'column3'] : ['id', 'name']
+ }
+ })
+ expect(wrapper.vm.currentAction.params).toEqual([
+ { name: 'column1', type: 'string' },
+ { name: 'column2', type: 'string' },
+ { name: 'column3', type: 'string' },
+ { name: 'name', type: 'string' },
+ { name: 'id', type: 'string' }
+ ])
+ expect(wrapper.vm.currentAction.paramFields).toEqual([
+ { name: 'id', type: 'string' },
+ { name: 'name', type: 'string' }
+ ])
+ expect(wrapper.vm.showAction).toBeTruthy()
})
it('check currentAction paramsField and listUuidOpts() is called when
execAction() is called', () => {
@@ -1546,11 +1540,10 @@ describe('Views > AutogenView.vue', () => {
response: {},
stack: 'Error: throw exception error'
}
-
+ mockAxios.mockRejectedValue(errorMock)
wrapper = factory()
spyConsole.log = jest.spyOn(console, 'log').mockImplementation(() =>
{})
- mockAxios.mockRejectedValue(errorMock)
wrapper.setData({
apiName: 'testApiNameCase1'
})
@@ -1581,7 +1574,7 @@ describe('Views > AutogenView.vue', () => {
})
describe('pollActionCompletion()', () => {
- it('check $notification, fetchData() when pollActionCompletion() is
called with action is empty', (done) => {
+ it('check $notification when pollActionCompletion() is called with
action is empty', (done) => {
const mockData = {
queryasyncjobresultresponse: {
jobstatus: 1,
@@ -1590,18 +1583,15 @@ describe('Views > AutogenView.vue', () => {
}
}
}
-
+ mockAxios.mockResolvedValue(mockData)
wrapper = factory()
const jobId = 'test-job-id'
const action = {}
- const spy = jest.spyOn(wrapper.vm, 'fetchData')
- mockAxios.mockResolvedValue(mockData)
wrapper.vm.pollActionCompletion(jobId, action)
setTimeout(() => {
- expect(spy).toHaveBeenCalled()
expect(mocks.$notification.info).not.toHaveBeenCalled()
expect(mockAxios).toHaveBeenCalled()
expect(mockAxios).toHaveBeenCalledWith({
@@ -1619,7 +1609,7 @@ describe('Views > AutogenView.vue', () => {
})
})
- it('check $notification, fetchData() when pollActionCompletion() is
called with action is not empty', (done) => {
+ it('check $notification when pollActionCompletion() is called with
action is not empty', (done) => {
const mockData = {
queryasyncjobresultresponse: {
jobstatus: 1,
@@ -1628,9 +1618,8 @@ describe('Views > AutogenView.vue', () => {
}
}
}
-
+ mockAxios.mockResolvedValue(mockData)
wrapper = factory()
-
const jobId = 'test-job-id'
const action = {
label: 'labelname',
@@ -1638,13 +1627,9 @@ describe('Views > AutogenView.vue', () => {
return jobResult.name
}
}
- const spy = jest.spyOn(wrapper.vm, 'fetchData')
-
- mockAxios.mockResolvedValue(mockData)
wrapper.vm.pollActionCompletion(jobId, action)
setTimeout(() => {
- expect(spy).toHaveBeenCalled()
expect(mocks.$notification.info).toHaveBeenCalled()
expect(mocks.$notification.info).toHaveLastReturnedWith({
message: 'test-name-en',
@@ -1666,48 +1651,6 @@ describe('Views > AutogenView.vue', () => {
done()
})
})
-
- it('check fetchData() is called when $pollJob error response', (done) =>
{
- const mockData = {
- queryasyncjobresultresponse: {
- jobstatus: 2,
- jobresult: {
- errortext: 'test-error-message'
- }
- }
- }
-
- wrapper = factory()
-
- const jobId = 'test-job-id'
- const action = {
- label: 'labelname',
- response: (jobResult) => {
- return jobResult.name
- }
- }
- const spy = jest.spyOn(wrapper.vm, 'fetchData')
-
- mockAxios.mockResolvedValue(mockData)
- wrapper.vm.pollActionCompletion(jobId, action)
-
- setTimeout(() => {
- expect(spy).toHaveBeenCalled()
- expect(mockAxios).toHaveBeenCalled()
- expect(mockAxios).toHaveBeenCalledWith({
- url: '/',
- method: 'GET',
- data: new URLSearchParams(),
- params: {
- command: 'queryAsyncJobResult',
- jobId: jobId,
- response: 'json'
- }
- })
-
- done()
- })
- })
})
describe('fillEditFormFieldValues()', () => {
@@ -2115,7 +2058,6 @@ describe('Views > AutogenView.vue', () => {
})
spyConsole.warn = jest.spyOn(console, 'warn').mockImplementation(() =>
{})
- spyConsole.log = jest.spyOn(console, 'log').mockImplementation(() =>
{})
wrapper.vm.$nextTick(() => {
const event = document.createEvent('Event')
@@ -2153,7 +2095,6 @@ describe('Views > AutogenView.vue', () => {
}
}
mockAxios.mockResolvedValue(mockData)
- spyConsole.log = jest.spyOn(console, 'log').mockImplementation(() =>
{})
wrapper.vm.$nextTick(() => {
const event = document.createEvent('Event')
@@ -2203,7 +2144,6 @@ describe('Views > AutogenView.vue', () => {
}
}
mockAxios.mockResolvedValue(mockData)
- spyConsole.log = jest.spyOn(console, 'log').mockImplementation(() =>
{})
wrapper.vm.$nextTick(() => {
const event = document.createEvent('Event')
@@ -2251,7 +2191,6 @@ describe('Views > AutogenView.vue', () => {
}
}
mockAxios.mockResolvedValue(mockData)
- spyConsole.log = jest.spyOn(console, 'log').mockImplementation(() =>
{})
wrapper.vm.$nextTick(() => {
wrapper.vm.form.getFieldDecorator('column1', { initialValue: null })
@@ -2300,7 +2239,6 @@ describe('Views > AutogenView.vue', () => {
}
}
mockAxios.mockResolvedValue(mockData)
- spyConsole.log = jest.spyOn(console, 'log').mockImplementation(() =>
{})
wrapper.vm.$nextTick(() => {
wrapper.vm.form.getFieldDecorator('column1', { initialValue: null })
@@ -2353,8 +2291,6 @@ describe('Views > AutogenView.vue', () => {
}
}
mockAxios.mockResolvedValue(mockData)
- spyConsole.log = jest.spyOn(console, 'log').mockImplementation(() =>
{})
-
wrapper.vm.$nextTick(() => {
wrapper.vm.form.getFieldDecorator('column1', { initialValue: 1 })
const event = document.createEvent('Event')
@@ -2411,8 +2347,6 @@ describe('Views > AutogenView.vue', () => {
}
}
mockAxios.mockResolvedValue(mockData)
- spyConsole.log = jest.spyOn(console, 'log').mockImplementation(() =>
{})
-
wrapper.vm.$nextTick(() => {
wrapper.vm.form.getFieldDecorator('column1', { initialValue: [1, 2]
})
const event = document.createEvent('Event')
@@ -2463,8 +2397,6 @@ describe('Views > AutogenView.vue', () => {
}
}
mockAxios.mockResolvedValue(mockData)
- spyConsole.log = jest.spyOn(console, 'log').mockImplementation(() =>
{})
-
wrapper.vm.$nextTick(() => {
wrapper.vm.form.getFieldDecorator('account', { initialValue:
'test-account-value' })
const event = document.createEvent('Event')
@@ -2515,7 +2447,6 @@ describe('Views > AutogenView.vue', () => {
}
}
mockAxios.mockResolvedValue(mockData)
- spyConsole.log = jest.spyOn(console, 'log').mockImplementation(() =>
{})
wrapper.vm.$nextTick(() => {
wrapper.vm.form.getFieldDecorator('keypair', { initialValue:
'test-keypair-value' })
@@ -2571,7 +2502,6 @@ describe('Views > AutogenView.vue', () => {
}
}
mockAxios.mockResolvedValue(mockData)
- spyConsole.log = jest.spyOn(console, 'log').mockImplementation(() =>
{})
wrapper.vm.$nextTick(() => {
wrapper.vm.form.getFieldDecorator('keypair', { initialValue: 1 })
@@ -2623,7 +2553,6 @@ describe('Views > AutogenView.vue', () => {
}
}
mockAxios.mockResolvedValue(mockData)
- spyConsole.log = jest.spyOn(console, 'log').mockImplementation(() =>
{})
wrapper.vm.$nextTick(() => {
wrapper.vm.form.getFieldDecorator('column1', { initialValue:
'test-column-value' })
@@ -2675,7 +2604,6 @@ describe('Views > AutogenView.vue', () => {
}
}
mockAxios.mockResolvedValue(mockData)
- spyConsole.log = jest.spyOn(console, 'log').mockImplementation(() =>
{})
wrapper.vm.$nextTick(() => {
wrapper.vm.form.getFieldDecorator('column1', { initialValue:
'test-column1-value' })
@@ -2734,7 +2662,6 @@ describe('Views > AutogenView.vue', () => {
}
}
mockAxios.mockResolvedValue(mockData)
- spyConsole.log = jest.spyOn(console, 'log').mockImplementation(() =>
{})
wrapper.vm.$nextTick(() => {
wrapper.vm.form.getFieldDecorator('column1', { initialValue:
'test-column1-value' })
@@ -2759,6 +2686,19 @@ describe('Views > AutogenView.vue', () => {
})
it('check router name when api is called and currentAction.icon = delete
and dataView is true', async (done) => {
+ const mockData = {
+ testapinamecase1response: {
+ jobid: 'test-job-id'
+ },
+ queryasyncjobresultresponse: {
+ jobstatus: 1,
+ jobresult: {
+ name: 'test-name-value'
+ }
+ }
+ }
+
+ mockAxios.mockResolvedValue(mockData)
router = common.createMockRouter([{
name: 'testRouter26',
path: '/test-router-26',
@@ -2766,41 +2706,26 @@ describe('Views > AutogenView.vue', () => {
icon: 'test-router-26'
}
}])
- wrapper = factory({ router: router })
- router.push({ name: 'testRouter26' })
-
- const mockData = {
- testapinamecase1response: {
- count: 1,
- testapinamecase1: [{
- id: 'test-id-value',
- name: 'test-name-value'
- }]
+ wrapper = factory({
+ router: router,
+ data: {
+ currentAction: {
+ api: 'testApiNameCase1',
+ icon: 'delete',
+ loading: false,
+ label: 'labelname',
+ params: [
+ { name: 'column1', type: 'string' }
+ ],
+ paramFields: [
+ { name: 'column1', type: 'string', description: '', required:
false }
+ ]
+ },
+ resource: {}
}
- }
-
- mockAxios.mockResolvedValue(mockData)
- spyConsole.log = jest.spyOn(console, 'log').mockImplementation(() =>
{})
- await wrapper.vm.$nextTick()
-
- expect(router.currentRoute.name).toEqual('testRouter26')
-
- wrapper.setData({
- currentAction: {
- icon: 'delete',
- api: 'testApiNameCase1',
- loading: false,
- label: 'labelname',
- params: [
- { name: 'column1', type: 'string' }
- ],
- paramFields: [
- { name: 'column1', type: 'string', description: '', required:
false }
- ]
- },
- dataView: true
})
-
+ router.push({ name: 'testRouter26', query: { dataView: true } })
+ await wrapper.vm.$nextTick()
wrapper.vm.form.getFieldDecorator('column1', { initialValue:
'test-column1-value' })
const event = document.createEvent('Event')
await wrapper.vm.execSubmit(event)
@@ -2811,7 +2736,7 @@ describe('Views > AutogenView.vue', () => {
}, 1000)
})
- it('check pollActionCompletion() is called when api is called and
response have jobId result', async (done) => {
+ it('check pollActionCompletion() and action AddAsyncJob is called when
api is called and response have jobId result', async (done) => {
store = common.createMockStore(state)
wrapper = factory({
store: store,
@@ -2836,11 +2761,16 @@ describe('Views > AutogenView.vue', () => {
const mockData = {
testapinamecase1response: {
jobid: 'test-job-id'
+ },
+ queryasyncjobresultresponse: {
+ jobstatus: 1,
+ jobresult: {
+ name: 'test-name-value'
+ }
}
}
mockAxios.mockResolvedValue(mockData)
- spyConsole.log = jest.spyOn(console, 'log').mockImplementation(() =>
{})
await wrapper.vm.$nextTick()
wrapper.vm.form.getFieldDecorator('column1', { initialValue:
'test-column1-value' })
@@ -2854,7 +2784,7 @@ describe('Views > AutogenView.vue', () => {
})
})
- it('check $message, fetchData() is called when api response have not
jobId result', async (done) => {
+ it('check $notification when api is called and response have not jobId
result', async (done) => {
wrapper = factory({
data: {
showAction: true,
@@ -2884,9 +2814,7 @@ describe('Views > AutogenView.vue', () => {
}
}
- const spyFetchData = jest.spyOn(wrapper.vm, 'fetchData')
mockAxios.mockResolvedValue(mockData)
- spyConsole.log = jest.spyOn(console, 'log').mockImplementation(() =>
{})
await wrapper.vm.$nextTick()
wrapper.vm.form.getFieldDecorator('column1', { initialValue:
'test-column1-value' })
@@ -2900,7 +2828,6 @@ describe('Views > AutogenView.vue', () => {
key: 'labelnametest-name-value',
duration: 2
})
- expect(spyFetchData).toHaveBeenCalled()
done()
})
diff --git a/ui/tests/unit/views/compute/MigrateWizard.spec.js
b/ui/tests/unit/views/compute/MigrateWizard.spec.js
index 2c052e9..233a4d4 100644
--- a/ui/tests/unit/views/compute/MigrateWizard.spec.js
+++ b/ui/tests/unit/views/compute/MigrateWizard.spec.js
@@ -72,7 +72,7 @@ const factory = (opts = {}) => {
}
describe('Views > compute > MigrateWizard.vue', () => {
- jest.spyOn(console, 'warn').mockImplementation(() => {})
+ // jest.spyOn(console, 'warn').mockImplementation(() => {})
beforeEach(() => {
jest.clearAllMocks()
@@ -345,6 +345,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
}
}
}
+ mockAxios.mockResolvedValue(mockData)
router = common.createMockRouter([{
name: 'testRouter1',
@@ -370,9 +371,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
}
})
router.push({ name: 'testRouter1' })
-
- jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
- mockAxios.mockResolvedValue(mockData)
+ wrapper.vm.loading = false
await wrapper.vm.$nextTick()
await wrapper.vm.submitForm()
@@ -406,6 +405,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
}
}
}
+ mockAxios.mockResolvedValue(mockData)
router = common.createMockRouter([{
name: 'testRouter2',
@@ -429,11 +429,9 @@ describe('Views > compute > MigrateWizard.vue', () => {
}
}
})
- router.push({ name: 'testRouter2' })
- jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
-
- mockAxios.mockResolvedValue(mockData)
+ router.push({ name: 'testRouter2' })
+ wrapper.vm.loading = false
await wrapper.vm.$nextTick()
await wrapper.vm.submitForm()
@@ -457,7 +455,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
it('check api is called when isUserVm=false', async (done) => {
const mockData = {
- migratesystemvmresponse: {
+ migratevirtualmachineresponse: {
jobid: 'test-job-id'
},
queryasyncjobresultresponse: {
@@ -467,7 +465,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
}
}
}
-
+ mockAxios.mockResolvedValue(mockData)
router = common.createMockRouter([{
name: 'testRouter3',
path: '/test-router-3',
@@ -492,9 +490,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
}
})
router.push({ name: 'testRouter3' })
-
- jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
- mockAxios.mockResolvedValue(mockData)
+ wrapper.vm.loading = false
await wrapper.vm.$nextTick()
await wrapper.vm.submitForm()
@@ -516,7 +512,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
})
})
- it('check store dispatch `AddAsyncJob` and $pollJob have successMethod()
is called with requiresStorageMotion is true', async (done) => {
+ it('check $pollJob have successMethod() is called with
requiresStorageMotion is true', async (done) => {
const mockData = {
migratevirtualmachinewithvolumeresponse: {
jobid: 'test-job-id-case-1'
@@ -528,7 +524,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
}
}
}
-
+ mockAxios.mockResolvedValue(mockData)
router = common.createMockRouter([{
name: 'testRouter4',
path: '/test-router-4',
@@ -553,10 +549,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
}
})
router.push({ name: 'testRouter4' })
-
- jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
- mockAxios.mockResolvedValue(mockData)
-
+ wrapper.vm.loading = false
await wrapper.vm.$nextTick()
await wrapper.vm.submitForm()
@@ -580,7 +573,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
}
}
}
-
+ mockAxios.mockResolvedValue(mockData)
router = common.createMockRouter([{
name: 'testRouter5',
path: '/test-router-5',
@@ -605,10 +598,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
}
})
router.push({ name: 'testRouter5' })
-
- jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
- mockAxios.mockResolvedValue(mockData)
-
+ wrapper.vm.loading = false
await wrapper.vm.$nextTick()
await wrapper.vm.submitForm()
@@ -619,9 +609,9 @@ describe('Views > compute > MigrateWizard.vue', () => {
})
})
- it('check store dispatch `AddAsyncJob` and $pollJob have successMethod()
is called with isUserVm is false', async (done) => {
+ it('check $pollJob have successMethod() is called with isUserVm is
false', async (done) => {
const mockData = {
- migratesystemvmresponse: {
+ migratevirtualmachineresponse: {
jobid: 'test-job-id-case-2'
},
queryasyncjobresultresponse: {
@@ -631,7 +621,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
}
}
}
-
+ mockAxios.mockResolvedValue(mockData)
router = common.createMockRouter([{
name: 'testRouter6',
path: '/test-router-6',
@@ -656,10 +646,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
}
})
router.push({ name: 'testRouter6' })
-
- jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
- mockAxios.mockResolvedValue(mockData)
-
+ wrapper.vm.loading = false
await wrapper.vm.$nextTick()
await wrapper.vm.submitForm()
@@ -673,7 +660,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
it('check $pollJob have errorMethod() is called', async (done) => {
const mockData = {
- migratesystemvmresponse: {
+ migratevirtualmachinewithvolumeresponse: {
jobid: 'test-job-id-case-3'
},
queryasyncjobresultresponse: {
@@ -683,6 +670,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
}
}
}
+ mockAxios.mockResolvedValue(mockData)
wrapper = factory({
props: {
resource: {
@@ -698,10 +686,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
}
}
})
- jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
-
- mockAxios.mockResolvedValue(mockData)
-
+ wrapper.vm.loading = false
await wrapper.vm.$nextTick()
await wrapper.vm.submitForm()
@@ -715,10 +700,11 @@ describe('Views > compute > MigrateWizard.vue', () => {
it('check $pollJob have catchMethod() is called', async (done) => {
const mockData = {
- migratesystemvmresponse: {
+ migratevirtualmachinewithvolumeresponse: {
jobid: 'test-job-id-case-4'
}
}
+ mockAxios.mockResolvedValue(mockData)
wrapper = factory({
props: {
resource: {
@@ -734,10 +720,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
}
}
})
- jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
-
- mockAxios.mockResolvedValue(mockData)
-
+ wrapper.vm.loading = false
await wrapper.vm.$nextTick()
await wrapper.vm.submitForm()
@@ -753,7 +736,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
const mockError = {
message: 'Error: throw error message'
}
-
+ mockAxios.mockRejectedValue(mockError)
wrapper = factory({
props: {
resource: {}
@@ -766,10 +749,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
}
}
})
- jest.spyOn(wrapper.vm, 'fetchData').mockImplementation(() => {})
-
- mockAxios.mockRejectedValue(mockError)
-
+ wrapper.vm.loading = false
await wrapper.vm.$nextTick()
await wrapper.vm.submitForm()