From c10ec22ce5dff9bb3483b2bee9101db8d60294a9 Mon Sep 17 00:00:00 2001 From: utchoang Date: Tue, 20 Jul 2021 07:46:09 +0700 Subject: [PATCH 1/8] fix error test unit on MigrateWizard --- .../unit/views/compute/MigrateWizard.spec.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/ui/tests/unit/views/compute/MigrateWizard.spec.js b/ui/tests/unit/views/compute/MigrateWizard.spec.js index 14c8a899233b..210bf1c6726d 100644 --- a/ui/tests/unit/views/compute/MigrateWizard.spec.js +++ b/ui/tests/unit/views/compute/MigrateWizard.spec.js @@ -25,9 +25,6 @@ jest.mock('axios', () => mockAxios) let wrapper, i18n, store, mocks const state = {} -const actions = { - AddAsyncJob: jest.fn((jobObject) => {}) -} mocks = { $message: { error: jest.fn((message) => {}) @@ -56,7 +53,7 @@ mocks = { }) } i18n = common.createMockI18n('en', mockData.messages) -store = common.createMockStore(state, actions) +store = common.createMockStore(state) const factory = (opts = {}) => { i18n = opts.i18n || i18n @@ -434,7 +431,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' @@ -469,7 +466,6 @@ describe('Views > compute > MigrateWizard.vue', () => { await wrapper.vm.submitForm() setTimeout(() => { - expect(actions.AddAsyncJob).toHaveBeenCalled() expect(mocks.$pollJob).toHaveBeenCalled() expect(wrapper.emitted()['close-action'][0]).toEqual([]) @@ -477,7 +473,7 @@ describe('Views > compute > MigrateWizard.vue', () => { }) }) - it('check store dispatch `AddAsyncJob` and $pollJob have successMethod() is called with requiresStorageMotion is false', async (done) => { + it('check $pollJob have successMethod() is called with requiresStorageMotion is false', async (done) => { const mockData = { migratevirtualmachineresponse: { jobid: 'test-job-id-case-2' @@ -512,7 +508,6 @@ describe('Views > compute > MigrateWizard.vue', () => { await wrapper.vm.submitForm() setTimeout(() => { - expect(actions.AddAsyncJob).toHaveBeenCalled() expect(mocks.$pollJob).toHaveBeenCalled() expect(wrapper.emitted()['close-action'][0]).toEqual([]) @@ -520,7 +515,7 @@ describe('Views > compute > MigrateWizard.vue', () => { }) }) - it('check store dispatch `AddAsyncJob` and $pollJob have errorMethod() is called', async (done) => { + it('check $pollJob have errorMethod() is called', async (done) => { const mockData = { migratevirtualmachinewithvolumeresponse: { jobid: 'test-job-id-case-3' @@ -555,7 +550,6 @@ describe('Views > compute > MigrateWizard.vue', () => { await wrapper.vm.submitForm() setTimeout(() => { - expect(actions.AddAsyncJob).toHaveBeenCalled() expect(mocks.$pollJob).toHaveBeenCalled() expect(wrapper.emitted()['close-action'][0]).toEqual([]) @@ -563,7 +557,7 @@ describe('Views > compute > MigrateWizard.vue', () => { }) }) - it('check store dispatch `AddAsyncJob` and $pollJob have catchMethod() is called', async (done) => { + it('check $pollJob have catchMethod() is called', async (done) => { const mockData = { migratevirtualmachinewithvolumeresponse: { jobid: 'test-job-id-case-4' @@ -592,7 +586,6 @@ describe('Views > compute > MigrateWizard.vue', () => { await wrapper.vm.submitForm() setTimeout(() => { - expect(actions.AddAsyncJob).toHaveBeenCalled() expect(mocks.$pollJob).toHaveBeenCalled() expect(wrapper.emitted()['close-action'][0]).toEqual([]) From c9040aa96c13a3dc4fce432babe39e7cddde0c72 Mon Sep 17 00:00:00 2001 From: utchoang Date: Tue, 20 Jul 2021 09:04:20 +0700 Subject: [PATCH 2/8] fix error test unit on AutogenView, ActionButton --- ui/src/components/view/ActionButton.vue | 1 - ui/src/views/AutogenView.vue | 62 ++++++++++++++---------- ui/tests/mockData/ActionButton.mock.json | 10 +++- ui/tests/unit/views/AutogenView.spec.js | 12 ++--- 4 files changed, 49 insertions(+), 36 deletions(-) diff --git a/ui/src/components/view/ActionButton.vue b/ui/src/components/view/ActionButton.vue index 7d5497bd1d8e..bf9f63b0fdd6 100644 --- a/ui/src/components/view/ActionButton.vue +++ b/ui/src/components/view/ActionButton.vue @@ -143,7 +143,6 @@ export default { this.actionBadge = {} const arrAsync = [] const actionBadge = this.actions.filter(action => action.showBadge === true) - if ((actionBadge.dataView ? actionBadge.dataView : false) !== this.dataView) return if (actionBadge && actionBadge.length > 0) { const dataLength = actionBadge.length diff --git a/ui/src/views/AutogenView.vue b/ui/src/views/AutogenView.vue index f274ecf54443..631bf3a3ce78 100644 --- a/ui/src/views/AutogenView.vue +++ b/ui/src/views/AutogenView.vue @@ -615,7 +615,6 @@ export default { params.page = this.page params.pagesize = this.pageSize - this.searchParams = params api(this.apiName, params).then(json => { var responseName var objectName @@ -703,6 +702,7 @@ export default { } }).finally(f => { this.loading = false + this.searchParams = params }) }, closeAction () { @@ -949,41 +949,47 @@ export default { }) }, handleResponse (response, resourceName, action, showLoading = true) { - for (const obj in response) { - if (obj.includes('response')) { - if (response[obj].jobid) { - return new Promise(resolve => { - const jobid = response[obj].jobid - resolve(this.pollActionCompletion(jobid, action, resourceName, showLoading)) - }) - } else { - var message = action.successMessage ? this.$t(action.successMessage) : this.$t(action.label) + - (resourceName ? ' - ' + resourceName : '') - var duration = 2 - if (action.additionalMessage) { - message = message + ' - ' + this.$t(action.successMessage) - duration = 5 + return new Promise(resolve => { + let jobId = null; + for (const obj in response) { + if (obj.includes('response')) { + if (response[obj].jobid) { + jobId = response[obj].jobid + } else { + var message = action.successMessage ? this.$t(action.successMessage) : this.$t(action.label) + + (resourceName ? ' - ' + resourceName : '') + var duration = 2 + if (action.additionalMessage) { + message = message + ' - ' + this.$t(action.successMessage) + duration = 5 + } + this.$message.success({ + content: message, + key: action.label + resourceName, + duration: duration + }) } - this.$message.success({ - content: message, - key: action.label + resourceName, - duration: duration - }) + break } - break } - } - if (['addLdapConfiguration', 'deleteLdapConfiguration'].includes(action.api)) { - this.$store.dispatch('UpdateConfiguration') - } - return false + if (['addLdapConfiguration', 'deleteLdapConfiguration'].includes(action.api)) { + this.$store.dispatch('UpdateConfiguration') + } + if (jobId) { + return resolve(this.pollActionCompletion(jobId, action, resourceName, showLoading)) + } + + return resolve(false) + }) }, execSubmit (e) { e.preventDefault() + console.log('submit'); this.form.validateFields((err, values) => { if (err) { return } + console.log('submit1'); const params = {} const action = this.currentAction if ('id' in this.resource && action.params.map(i => { return i.name }).includes('id')) { @@ -1050,7 +1056,9 @@ export default { } else { args = [action.api, params] } + console.log(args); api(...args).then(json => { + console.log(1); this.handleResponse(json, resourceName, action).then(jobId => { hasJobId = jobId if ((action.icon === 'delete' || ['archiveEvents', 'archiveAlerts', 'unmanageVirtualMachine'].includes(action.api)) && this.dataView) { @@ -1061,8 +1069,10 @@ export default { } } }) + console.log(3); this.closeAction() }).catch(error => { + console.log(4); if ([401].includes(error.response.status)) { return } diff --git a/ui/tests/mockData/ActionButton.mock.json b/ui/tests/mockData/ActionButton.mock.json index c0934d00b3e3..85ff8f1fe801 100644 --- a/ui/tests/mockData/ActionButton.mock.json +++ b/ui/tests/mockData/ActionButton.mock.json @@ -1,7 +1,13 @@ { "messages": { - "en": { "label.action": "action-en" }, - "de": { "label.action": "action-de" } + "en": { + "label.action": "action-en", + "label.view.console": "Console-en" + }, + "de": { + "label.action": "action-de", + "label.view.console": "Console-de" + } }, "apis": { "test-api-case-1": {}, diff --git a/ui/tests/unit/views/AutogenView.spec.js b/ui/tests/unit/views/AutogenView.spec.js index 8823894dbcc8..807889d22242 100644 --- a/ui/tests/unit/views/AutogenView.spec.js +++ b/ui/tests/unit/views/AutogenView.spec.js @@ -36,9 +36,6 @@ const state = { store = common.createMockStore(state) i18n = common.createMockI18n('en', mockData.messages) -const actions = { - AddAsyncJob: jest.fn((jobId) => {}) -} const spyConsole = { log: null, warn: null @@ -2814,8 +2811,8 @@ describe('Views > AutogenView.vue', () => { }, 1000) }) - it('check pollActionCompletion() and action AddAsyncJob is called when api is called and response have jobId result', async (done) => { - store = common.createMockStore(state, actions) + it('check pollActionCompletion() is called when api is called and response have jobId result', async (done) => { + store = common.createMockStore(state) wrapper = factory({ store: store, data: { @@ -2851,14 +2848,13 @@ describe('Views > AutogenView.vue', () => { wrapper.vm.execSubmit(event) setTimeout(() => { - expect(actions.AddAsyncJob).toHaveBeenCalled() expect(spyPollAction).toHaveBeenCalled() done() }) }) - it('check $notification when api is called and response have not jobId result', async (done) => { + it('check $message, fetchData() is called when api response have not jobId result', async (done) => { wrapper = factory({ data: { showAction: true, @@ -2888,6 +2884,7 @@ describe('Views > AutogenView.vue', () => { } } + const spyFetchData = jest.spyOn(wrapper.vm, 'fetchData') mockAxios.mockResolvedValue(mockData) spyConsole.log = jest.spyOn(console, 'log').mockImplementation(() => {}) @@ -2903,6 +2900,7 @@ describe('Views > AutogenView.vue', () => { key: 'labelnametest-name-value', duration: 2 }) + expect(spyFetchData).toHaveBeenCalled(); done() }) From af9a511bdb6ca63709bb22c791bf71a2536d5039 Mon Sep 17 00:00:00 2001 From: utchoang Date: Tue, 20 Jul 2021 10:16:39 +0700 Subject: [PATCH 3/8] fix error lint --- ui/src/views/AutogenView.vue | 10 ++-------- ui/tests/unit/views/AutogenView.spec.js | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/ui/src/views/AutogenView.vue b/ui/src/views/AutogenView.vue index 631bf3a3ce78..5d365dfc9567 100644 --- a/ui/src/views/AutogenView.vue +++ b/ui/src/views/AutogenView.vue @@ -950,11 +950,11 @@ export default { }, handleResponse (response, resourceName, action, showLoading = true) { return new Promise(resolve => { - let jobId = null; + let jobId = null for (const obj in response) { if (obj.includes('response')) { if (response[obj].jobid) { - jobId = response[obj].jobid + jobId = response[obj].jobid } else { var message = action.successMessage ? this.$t(action.successMessage) : this.$t(action.label) + (resourceName ? ' - ' + resourceName : '') @@ -984,12 +984,10 @@ export default { }, execSubmit (e) { e.preventDefault() - console.log('submit'); this.form.validateFields((err, values) => { if (err) { return } - console.log('submit1'); const params = {} const action = this.currentAction if ('id' in this.resource && action.params.map(i => { return i.name }).includes('id')) { @@ -1056,9 +1054,7 @@ export default { } else { args = [action.api, params] } - console.log(args); api(...args).then(json => { - console.log(1); this.handleResponse(json, resourceName, action).then(jobId => { hasJobId = jobId if ((action.icon === 'delete' || ['archiveEvents', 'archiveAlerts', 'unmanageVirtualMachine'].includes(action.api)) && this.dataView) { @@ -1069,10 +1065,8 @@ export default { } } }) - console.log(3); this.closeAction() }).catch(error => { - console.log(4); if ([401].includes(error.response.status)) { return } diff --git a/ui/tests/unit/views/AutogenView.spec.js b/ui/tests/unit/views/AutogenView.spec.js index 807889d22242..a866aaea1f6a 100644 --- a/ui/tests/unit/views/AutogenView.spec.js +++ b/ui/tests/unit/views/AutogenView.spec.js @@ -2900,7 +2900,7 @@ describe('Views > AutogenView.vue', () => { key: 'labelnametest-name-value', duration: 2 }) - expect(spyFetchData).toHaveBeenCalled(); + expect(spyFetchData).toHaveBeenCalled() done() }) From d42f306e62a4c1e54ad69032aa9cec874e0e0f1e Mon Sep 17 00:00:00 2001 From: utchoang Date: Mon, 26 Jul 2021 10:06:17 +0700 Subject: [PATCH 4/8] fix error pollJob originalPage.starWith undefined --- ui/src/utils/plugins.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/src/utils/plugins.js b/ui/src/utils/plugins.js index 60dfff287316..8780e7c77d28 100644 --- a/ui/src/utils/plugins.js +++ b/ui/src/utils/plugins.js @@ -64,7 +64,7 @@ export const pollJobPlugin = { status: 'progress' }) - options.originalPage = options.originalPage ? options.originalPage : this.$router.currentRoute.path + const originalPageOpts = originalPage || this.$router.currentRoute.path api('queryAsyncJobResult', { jobId }).then(json => { const result = json.queryasyncjobresultresponse if (result.jobstatus === 1) { @@ -90,7 +90,7 @@ export const pollJobPlugin = { // Ensure we refresh on the same / parent page const currentPage = this.$router.currentRoute.path - const samePage = originalPage === currentPage || originalPage.startsWith(currentPage + '/') + const samePage = originalPageOpts === currentPage || originalPageOpts.startsWith(currentPage + '/') if (samePage && (!action || !('isFetchData' in action) || (action.isFetchData))) { eventBus.$emit('async-job-complete') } From 3a16d957a0c47c1add9aa6a3c64d3f3941a660a1 Mon Sep 17 00:00:00 2001 From: Hoang Nguyen Date: Thu, 29 Jul 2021 07:28:47 +0700 Subject: [PATCH 5/8] Update ui/src/utils/plugins.js Co-authored-by: davidjumani --- ui/src/utils/plugins.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/utils/plugins.js b/ui/src/utils/plugins.js index 8780e7c77d28..827107b9026e 100644 --- a/ui/src/utils/plugins.js +++ b/ui/src/utils/plugins.js @@ -64,7 +64,7 @@ export const pollJobPlugin = { status: 'progress' }) - const originalPageOpts = originalPage || this.$router.currentRoute.path + options.originalPage = options.originalPage || this.$router.currentRoute.path api('queryAsyncJobResult', { jobId }).then(json => { const result = json.queryasyncjobresultresponse if (result.jobstatus === 1) { From 88c5386bb1828c80920ca3bfbf77a9f7e5dd4224 Mon Sep 17 00:00:00 2001 From: Hoang Nguyen Date: Thu, 29 Jul 2021 07:28:55 +0700 Subject: [PATCH 6/8] Update ui/src/utils/plugins.js Co-authored-by: davidjumani --- ui/src/utils/plugins.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/utils/plugins.js b/ui/src/utils/plugins.js index 827107b9026e..a7747b3e2546 100644 --- a/ui/src/utils/plugins.js +++ b/ui/src/utils/plugins.js @@ -90,7 +90,7 @@ export const pollJobPlugin = { // Ensure we refresh on the same / parent page const currentPage = this.$router.currentRoute.path - const samePage = originalPageOpts === currentPage || originalPageOpts.startsWith(currentPage + '/') + const samePage = options.originalPage === currentPage || options.originalPage.startsWith(currentPage + '/') if (samePage && (!action || !('isFetchData' in action) || (action.isFetchData))) { eventBus.$emit('async-job-complete') } From 1276c696928c4325c4db9777913386fc71563790 Mon Sep 17 00:00:00 2001 From: utchoang Date: Thu, 29 Jul 2021 13:37:47 +0700 Subject: [PATCH 7/8] uses a substitution variable if the originalPage is null with queryAsyncJob have jobstatus = 1 --- ui/src/utils/plugins.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ui/src/utils/plugins.js b/ui/src/utils/plugins.js index a7747b3e2546..b1ed33e536d1 100644 --- a/ui/src/utils/plugins.js +++ b/ui/src/utils/plugins.js @@ -64,7 +64,8 @@ export const pollJobPlugin = { status: 'progress' }) - options.originalPage = options.originalPage || this.$router.currentRoute.path + const originalPageReceive = originalPage || this.$router.currentRoute.path + options.originalPage = originalPageReceive api('queryAsyncJobResult', { jobId }).then(json => { const result = json.queryasyncjobresultresponse if (result.jobstatus === 1) { @@ -90,7 +91,7 @@ export const pollJobPlugin = { // Ensure we refresh on the same / parent page const currentPage = this.$router.currentRoute.path - const samePage = options.originalPage === currentPage || options.originalPage.startsWith(currentPage + '/') + const samePage = originalPageReceive === currentPage || originalPageReceive.startsWith(currentPage + '/') if (samePage && (!action || !('isFetchData' in action) || (action.isFetchData))) { eventBus.$emit('async-job-complete') } From 6274f9dd9a161bbe751cb819f25f95cf181c59fc Mon Sep 17 00:00:00 2001 From: utchoang Date: Fri, 30 Jul 2021 13:20:21 +0700 Subject: [PATCH 8/8] remove argument null --- ui/src/utils/plugins.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ui/src/utils/plugins.js b/ui/src/utils/plugins.js index b1ed33e536d1..3c512d2d261c 100644 --- a/ui/src/utils/plugins.js +++ b/ui/src/utils/plugins.js @@ -53,8 +53,7 @@ export const pollJobPlugin = { showLoading = true, catchMessage = i18n.t('label.error.caught'), catchMethod = () => {}, - action = null, - originalPage = null + action = null } = options store.dispatch('AddHeaderNotice', { @@ -64,8 +63,7 @@ export const pollJobPlugin = { status: 'progress' }) - const originalPageReceive = originalPage || this.$router.currentRoute.path - options.originalPage = originalPageReceive + options.originalPage = options.originalPage || this.$router.currentRoute.path api('queryAsyncJobResult', { jobId }).then(json => { const result = json.queryasyncjobresultresponse if (result.jobstatus === 1) { @@ -91,7 +89,7 @@ export const pollJobPlugin = { // Ensure we refresh on the same / parent page const currentPage = this.$router.currentRoute.path - const samePage = originalPageReceive === currentPage || originalPageReceive.startsWith(currentPage + '/') + const samePage = options.originalPage === currentPage || options.originalPage.startsWith(currentPage + '/') if (samePage && (!action || !('isFetchData' in action) || (action.isFetchData))) { eventBus.$emit('async-job-complete') }