2023-02-20 14:13:53 +00:00
|
|
|
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
|
|
|
|
import { createWrapper, axios } from 'app/test/vitest/helper';
|
|
|
|
import ClaimPhoto from 'pages/Claim/Card/ClaimPhoto.vue';
|
|
|
|
|
|
|
|
describe('ClaimPhoto', () => {
|
|
|
|
let vm;
|
2023-02-20 14:15:20 +00:00
|
|
|
|
2023-02-22 13:55:29 +00:00
|
|
|
const claimMock = {
|
|
|
|
claimDms: [
|
|
|
|
{
|
|
|
|
dmsFk: 1,
|
|
|
|
dms: {
|
|
|
|
contentType: 'contentType',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
client: {
|
|
|
|
id: '1',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
beforeAll(() => {
|
|
|
|
vm = createWrapper(ClaimPhoto, {
|
|
|
|
global: {
|
2023-02-24 11:51:29 +00:00
|
|
|
stubs: ['FetchData', 'TeleportSlot', 'vue-i18n'],
|
2023-02-22 13:55:29 +00:00
|
|
|
mocks: {
|
2023-02-24 11:51:29 +00:00
|
|
|
fetch: vi.fn(),
|
2023-02-22 13:55:29 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}).vm;
|
2023-02-20 14:13:53 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2023-02-22 13:55:29 +00:00
|
|
|
vi.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('deleteDms()', () => {
|
|
|
|
it('should delete dms and call quasar notify', async () => {
|
|
|
|
vi.spyOn(axios, 'post').mockResolvedValue({ data: true });
|
|
|
|
vi.spyOn(vm.quasar, 'notify');
|
|
|
|
|
|
|
|
await vm.deleteDms(0);
|
|
|
|
|
2023-02-23 14:20:07 +00:00
|
|
|
expect(axios.post).toHaveBeenCalledWith(
|
|
|
|
`ClaimDms/${claimMock.claimDms[0].dmsFk}/removeFile`
|
|
|
|
);
|
2023-02-22 13:55:29 +00:00
|
|
|
expect(vm.quasar.notify).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({ type: 'positive' })
|
|
|
|
);
|
|
|
|
expect(vm.claimDms).toEqual([]);
|
|
|
|
});
|
2023-02-20 14:13:53 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('viewDeleteDms()', () => {
|
|
|
|
it('should call quasar dialog', async () => {
|
2023-02-22 13:55:29 +00:00
|
|
|
vi.spyOn(vm.quasar, 'dialog');
|
|
|
|
|
|
|
|
await vm.viewDeleteDms(1);
|
|
|
|
|
|
|
|
expect(vm.quasar.dialog).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
componentProps: {
|
|
|
|
message: 'This file will be deleted',
|
|
|
|
icon: 'delete',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setClaimDms()', () => {
|
|
|
|
it('should assign claimDms and client from data', async () => {
|
|
|
|
await vm.setClaimDms(claimMock);
|
|
|
|
|
|
|
|
expect(vm.claimDms).toEqual([
|
|
|
|
{
|
|
|
|
dmsFk: 1,
|
|
|
|
dms: {
|
|
|
|
contentType: 'contentType',
|
|
|
|
},
|
|
|
|
isVideo: false,
|
2023-03-02 09:47:06 +00:00
|
|
|
url: '/api/Claims/1/downloadFile?access_token=',
|
2023-02-22 13:55:29 +00:00
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
expect(vm.client).toEqual(claimMock.client);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-02-23 14:20:07 +00:00
|
|
|
describe('create()', () => {
|
2023-02-22 13:55:29 +00:00
|
|
|
it('should upload file and call quasar notify', async () => {
|
|
|
|
const files = [{ name: 'firstFile' }];
|
2023-02-23 14:20:07 +00:00
|
|
|
|
2023-02-22 13:55:29 +00:00
|
|
|
vi.spyOn(axios, 'post').mockResolvedValue({ data: true });
|
2023-02-20 14:13:53 +00:00
|
|
|
vi.spyOn(vm.quasar, 'notify');
|
2023-02-24 11:51:29 +00:00
|
|
|
vi.spyOn(vm.claimDmsRef, 'fetch');
|
2023-02-20 14:13:53 +00:00
|
|
|
|
2023-02-22 13:55:29 +00:00
|
|
|
await vm.create(files);
|
2023-02-20 14:13:53 +00:00
|
|
|
|
2023-02-23 14:20:07 +00:00
|
|
|
expect(axios.post).toHaveBeenCalledWith(
|
2023-02-24 11:51:29 +00:00
|
|
|
'claims/1/uploadFile',
|
|
|
|
new FormData(),
|
|
|
|
expect.objectContaining({
|
|
|
|
params: expect.objectContaining({ hasFile: false }),
|
|
|
|
})
|
2023-02-22 13:55:29 +00:00
|
|
|
);
|
|
|
|
expect(vm.quasar.notify).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({ type: 'positive' })
|
|
|
|
);
|
2023-02-24 11:51:29 +00:00
|
|
|
|
|
|
|
expect(vm.claimDmsRef.fetch).toHaveBeenCalledOnce();
|
2023-02-20 14:13:53 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|