Skip to content

Commit 1ccd61c

Browse files
Hoang Nguyendavidjumani
andauthored
[TEST] - Test unit - Fix failing UI unit test 4.15 branch (#5219)
* fix error test unit on MigrateWizard * fix error test unit on AutogenView, ActionButton * fix error lint * fix error pollJob originalPage.starWith undefined * Update ui/src/utils/plugins.js Co-authored-by: davidjumani <dj.davidjumani1994@gmail.com> * Update ui/src/utils/plugins.js Co-authored-by: davidjumani <dj.davidjumani1994@gmail.com> * uses a substitution variable if the originalPage is null with queryAsyncJob have jobstatus = 1 * remove argument null Co-authored-by: davidjumani <dj.davidjumani1994@gmail.com>
1 parent c24aee9 commit 1ccd61c

6 files changed

Lines changed: 51 additions & 52 deletions

File tree

ui/src/components/view/ActionButton.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ export default {
143143
this.actionBadge = {}
144144
const arrAsync = []
145145
const actionBadge = this.actions.filter(action => action.showBadge === true)
146-
if ((actionBadge.dataView ? actionBadge.dataView : false) !== this.dataView) return
147146
148147
if (actionBadge && actionBadge.length > 0) {
149148
const dataLength = actionBadge.length

ui/src/utils/plugins.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ export const pollJobPlugin = {
5353
showLoading = true,
5454
catchMessage = i18n.t('label.error.caught'),
5555
catchMethod = () => {},
56-
action = null,
57-
originalPage = null
56+
action = null
5857
} = options
5958

6059
store.dispatch('AddHeaderNotice', {
@@ -64,7 +63,7 @@ export const pollJobPlugin = {
6463
status: 'progress'
6564
})
6665

67-
options.originalPage = options.originalPage ? options.originalPage : this.$router.currentRoute.path
66+
options.originalPage = options.originalPage || this.$router.currentRoute.path
6867
api('queryAsyncJobResult', { jobId }).then(json => {
6968
const result = json.queryasyncjobresultresponse
7069
if (result.jobstatus === 1) {
@@ -90,7 +89,7 @@ export const pollJobPlugin = {
9089

9190
// Ensure we refresh on the same / parent page
9291
const currentPage = this.$router.currentRoute.path
93-
const samePage = originalPage === currentPage || originalPage.startsWith(currentPage + '/')
92+
const samePage = options.originalPage === currentPage || options.originalPage.startsWith(currentPage + '/')
9493
if (samePage && (!action || !('isFetchData' in action) || (action.isFetchData))) {
9594
eventBus.$emit('async-job-complete')
9695
}

ui/src/views/AutogenView.vue

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,6 @@ export default {
615615
616616
params.page = this.page
617617
params.pagesize = this.pageSize
618-
this.searchParams = params
619618
api(this.apiName, params).then(json => {
620619
var responseName
621620
var objectName
@@ -703,6 +702,7 @@ export default {
703702
}
704703
}).finally(f => {
705704
this.loading = false
705+
this.searchParams = params
706706
})
707707
},
708708
closeAction () {
@@ -949,34 +949,38 @@ export default {
949949
})
950950
},
951951
handleResponse (response, resourceName, action, showLoading = true) {
952-
for (const obj in response) {
953-
if (obj.includes('response')) {
954-
if (response[obj].jobid) {
955-
return new Promise(resolve => {
956-
const jobid = response[obj].jobid
957-
resolve(this.pollActionCompletion(jobid, action, resourceName, showLoading))
958-
})
959-
} else {
960-
var message = action.successMessage ? this.$t(action.successMessage) : this.$t(action.label) +
961-
(resourceName ? ' - ' + resourceName : '')
962-
var duration = 2
963-
if (action.additionalMessage) {
964-
message = message + ' - ' + this.$t(action.successMessage)
965-
duration = 5
952+
return new Promise(resolve => {
953+
let jobId = null
954+
for (const obj in response) {
955+
if (obj.includes('response')) {
956+
if (response[obj].jobid) {
957+
jobId = response[obj].jobid
958+
} else {
959+
var message = action.successMessage ? this.$t(action.successMessage) : this.$t(action.label) +
960+
(resourceName ? ' - ' + resourceName : '')
961+
var duration = 2
962+
if (action.additionalMessage) {
963+
message = message + ' - ' + this.$t(action.successMessage)
964+
duration = 5
965+
}
966+
this.$message.success({
967+
content: message,
968+
key: action.label + resourceName,
969+
duration: duration
970+
})
966971
}
967-
this.$message.success({
968-
content: message,
969-
key: action.label + resourceName,
970-
duration: duration
971-
})
972+
break
972973
}
973-
break
974974
}
975-
}
976-
if (['addLdapConfiguration', 'deleteLdapConfiguration'].includes(action.api)) {
977-
this.$store.dispatch('UpdateConfiguration')
978-
}
979-
return false
975+
if (['addLdapConfiguration', 'deleteLdapConfiguration'].includes(action.api)) {
976+
this.$store.dispatch('UpdateConfiguration')
977+
}
978+
if (jobId) {
979+
return resolve(this.pollActionCompletion(jobId, action, resourceName, showLoading))
980+
}
981+
982+
return resolve(false)
983+
})
980984
},
981985
execSubmit (e) {
982986
e.preventDefault()

ui/tests/mockData/ActionButton.mock.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
{
22
"messages": {
3-
"en": { "label.action": "action-en" },
4-
"de": { "label.action": "action-de" }
3+
"en": {
4+
"label.action": "action-en",
5+
"label.view.console": "Console-en"
6+
},
7+
"de": {
8+
"label.action": "action-de",
9+
"label.view.console": "Console-de"
10+
}
511
},
612
"apis": {
713
"test-api-case-1": {},

ui/tests/unit/views/AutogenView.spec.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ const state = {
3636
store = common.createMockStore(state)
3737
i18n = common.createMockI18n('en', mockData.messages)
3838

39-
const actions = {
40-
AddAsyncJob: jest.fn((jobId) => {})
41-
}
4239
const spyConsole = {
4340
log: null,
4441
warn: null
@@ -2814,8 +2811,8 @@ describe('Views > AutogenView.vue', () => {
28142811
}, 1000)
28152812
})
28162813

2817-
it('check pollActionCompletion() and action AddAsyncJob is called when api is called and response have jobId result', async (done) => {
2818-
store = common.createMockStore(state, actions)
2814+
it('check pollActionCompletion() is called when api is called and response have jobId result', async (done) => {
2815+
store = common.createMockStore(state)
28192816
wrapper = factory({
28202817
store: store,
28212818
data: {
@@ -2851,14 +2848,13 @@ describe('Views > AutogenView.vue', () => {
28512848
wrapper.vm.execSubmit(event)
28522849

28532850
setTimeout(() => {
2854-
expect(actions.AddAsyncJob).toHaveBeenCalled()
28552851
expect(spyPollAction).toHaveBeenCalled()
28562852

28572853
done()
28582854
})
28592855
})
28602856

2861-
it('check $notification when api is called and response have not jobId result', async (done) => {
2857+
it('check $message, fetchData() is called when api response have not jobId result', async (done) => {
28622858
wrapper = factory({
28632859
data: {
28642860
showAction: true,
@@ -2888,6 +2884,7 @@ describe('Views > AutogenView.vue', () => {
28882884
}
28892885
}
28902886

2887+
const spyFetchData = jest.spyOn(wrapper.vm, 'fetchData')
28912888
mockAxios.mockResolvedValue(mockData)
28922889
spyConsole.log = jest.spyOn(console, 'log').mockImplementation(() => {})
28932890

@@ -2903,6 +2900,7 @@ describe('Views > AutogenView.vue', () => {
29032900
key: 'labelnametest-name-value',
29042901
duration: 2
29052902
})
2903+
expect(spyFetchData).toHaveBeenCalled()
29062904

29072905
done()
29082906
})

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ jest.mock('axios', () => mockAxios)
2525
let wrapper, i18n, store, mocks
2626

2727
const state = {}
28-
const actions = {
29-
AddAsyncJob: jest.fn((jobObject) => {})
30-
}
3128
mocks = {
3229
$message: {
3330
error: jest.fn((message) => {})
@@ -56,7 +53,7 @@ mocks = {
5653
})
5754
}
5855
i18n = common.createMockI18n('en', mockData.messages)
59-
store = common.createMockStore(state, actions)
56+
store = common.createMockStore(state)
6057

6158
const factory = (opts = {}) => {
6259
i18n = opts.i18n || i18n
@@ -434,7 +431,7 @@ describe('Views > compute > MigrateWizard.vue', () => {
434431
})
435432
})
436433

437-
it('check store dispatch `AddAsyncJob` and $pollJob have successMethod() is called with requiresStorageMotion is true', async (done) => {
434+
it('check $pollJob have successMethod() is called with requiresStorageMotion is true', async (done) => {
438435
const mockData = {
439436
migratevirtualmachinewithvolumeresponse: {
440437
jobid: 'test-job-id-case-1'
@@ -469,15 +466,14 @@ describe('Views > compute > MigrateWizard.vue', () => {
469466
await wrapper.vm.submitForm()
470467

471468
setTimeout(() => {
472-
expect(actions.AddAsyncJob).toHaveBeenCalled()
473469
expect(mocks.$pollJob).toHaveBeenCalled()
474470
expect(wrapper.emitted()['close-action'][0]).toEqual([])
475471

476472
done()
477473
})
478474
})
479475

480-
it('check store dispatch `AddAsyncJob` and $pollJob have successMethod() is called with requiresStorageMotion is false', async (done) => {
476+
it('check $pollJob have successMethod() is called with requiresStorageMotion is false', async (done) => {
481477
const mockData = {
482478
migratevirtualmachineresponse: {
483479
jobid: 'test-job-id-case-2'
@@ -512,15 +508,14 @@ describe('Views > compute > MigrateWizard.vue', () => {
512508
await wrapper.vm.submitForm()
513509

514510
setTimeout(() => {
515-
expect(actions.AddAsyncJob).toHaveBeenCalled()
516511
expect(mocks.$pollJob).toHaveBeenCalled()
517512
expect(wrapper.emitted()['close-action'][0]).toEqual([])
518513

519514
done()
520515
})
521516
})
522517

523-
it('check store dispatch `AddAsyncJob` and $pollJob have errorMethod() is called', async (done) => {
518+
it('check $pollJob have errorMethod() is called', async (done) => {
524519
const mockData = {
525520
migratevirtualmachinewithvolumeresponse: {
526521
jobid: 'test-job-id-case-3'
@@ -555,15 +550,14 @@ describe('Views > compute > MigrateWizard.vue', () => {
555550
await wrapper.vm.submitForm()
556551

557552
setTimeout(() => {
558-
expect(actions.AddAsyncJob).toHaveBeenCalled()
559553
expect(mocks.$pollJob).toHaveBeenCalled()
560554
expect(wrapper.emitted()['close-action'][0]).toEqual([])
561555

562556
done()
563557
})
564558
})
565559

566-
it('check store dispatch `AddAsyncJob` and $pollJob have catchMethod() is called', async (done) => {
560+
it('check $pollJob have catchMethod() is called', async (done) => {
567561
const mockData = {
568562
migratevirtualmachinewithvolumeresponse: {
569563
jobid: 'test-job-id-case-4'
@@ -592,7 +586,6 @@ describe('Views > compute > MigrateWizard.vue', () => {
592586
await wrapper.vm.submitForm()
593587

594588
setTimeout(() => {
595-
expect(actions.AddAsyncJob).toHaveBeenCalled()
596589
expect(mocks.$pollJob).toHaveBeenCalled()
597590
expect(wrapper.emitted()['close-action'][0]).toEqual([])
598591

0 commit comments

Comments
 (0)