test: refs #7073 add unit tests for VnDms component #1198

Open
jtubau wants to merge 4 commits from 7073-createTestToVnDms into dev
1 changed files with 21 additions and 5 deletions
Showing only changes of commit 5b6ad1a7c0 - Show all commits

View File

@ -1,4 +1,4 @@
import { createWrapper, axios, flushPromises } from 'app/test/vitest/helper'; import { createWrapper, axios } from 'app/test/vitest/helper';
import { vi, afterEach, beforeEach, beforeAll, describe, expect, it } from 'vitest'; import { vi, afterEach, beforeEach, beforeAll, describe, expect, it } from 'vitest';
import VnDms from 'src/components/common/VnDms.vue'; import VnDms from 'src/components/common/VnDms.vue';
@ -115,16 +115,32 @@ describe('VnDms', () => {
await vm.save(); await vm.save();
expect(postMock).toHaveBeenCalledWith(vm.getUrl(), expect.any(FormData), { params: expectedBody }); expect(postMock).toHaveBeenCalledWith(vm.getUrl(), expect.any(FormData), { params: expectedBody });
expect(wrapper.emitted('onDataSaved')).toBeTruthy(); expect(wrapper.emitted('onDataSaved')).toBeTruthy();
//expect(emitMock).toHaveBeenCalledWith('onDataSaved', expectedBody, postResponseMock);
}); });
}); });
describe('defaultData', () => { describe('defaultData', () => {
it('should set default data correctly', async () => { it('should set dms with formInitialData', async () => {
await wrapper.setProps({ formInitialData: null }); const testData = {
hasFile: false,
hasFileAttached: false,
reference: 'defaultData-test',
warehouseFk: 2,
companyFk: 3,
dmsTypeFk: 2,
description: 'This is a test description'
}
await wrapper.setProps({ formInitialData: testData });
vm.defaultData(); vm.defaultData();
expect(vm.dms.reference).toBe('123'); expect(vm.dms).toEqual(testData);
});
it('should add reference with "route.params.id" to dms if formInitialData is null', async () => {
await wrapper.setProps({ formInitialData: null });
vm.route.params.id= '111';
vm.defaultData();
expect(vm.dms.reference).toBe('111');
}); });
}); });
}); });