Skip to content

Commit 2713646

Browse files
author
Daan Hoogland
committed
test
1 parent 4879286 commit 2713646

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,6 +2609,51 @@ describe('Views > AutogenView.vue', () => {
26092609
done()
26102610
})
26112611

2612+
it('API should be called with the option id when currentAction.mapping option is an {id, description} object', async (done) => {
2613+
originalFunc.handleResponse = wrapper.vm.handleResponse
2614+
originalFunc.shouldNavigateBack = wrapper.vm.shouldNavigateBack
2615+
originalFunc.fetchData = wrapper.vm.fetchData
2616+
wrapper.vm.handleResponse = jest.fn(async (json, resourceName, action) => { return Promise.resolve() })
2617+
wrapper.vm.shouldNavigateBack = jest.fn((args) => { return false })
2618+
wrapper.vm.fetchData = jest.fn()
2619+
wrapper.vm.form = { column1: 1 }
2620+
2621+
const event = document.createEvent('Event')
2622+
await mockAxios.mockResolvedValue({})
2623+
await wrapper.setData({
2624+
showAction: true,
2625+
currentAction: {
2626+
api: 'testApiNameCase1',
2627+
label: 'label.name',
2628+
params: [{ name: 'column1', type: 'list' }],
2629+
paramFields: [{ name: 'column1', type: 'list' }],
2630+
mapping: {
2631+
column1: {
2632+
options: [
2633+
{ id: 'column-id-1', description: 'label.column.value.one' },
2634+
{ id: 'column-id-2', description: 'label.column.value.two' }
2635+
]
2636+
}
2637+
}
2638+
},
2639+
resource: {}
2640+
})
2641+
await wrapper.vm.execSubmit(event)
2642+
await flushPromises()
2643+
2644+
expect(mockAxios).toHaveBeenCalled()
2645+
expect(mockAxios).toHaveBeenLastCalledWith({
2646+
url: '/',
2647+
method: 'POST',
2648+
data: common.createDataParams({
2649+
command: 'testApiNameCase1',
2650+
response: 'json',
2651+
column1: 'column-id-2'
2652+
})
2653+
})
2654+
done()
2655+
})
2656+
26122657
it('API should be called when form has input key not exist in currentAction.mapping, type is list and currentAction.params[input] has id', async (done) => {
26132658
originalFunc.handleResponse = wrapper.vm.handleResponse
26142659
originalFunc.shouldNavigateBack = wrapper.vm.shouldNavigateBack

0 commit comments

Comments
 (0)