salix-front/test/vitest/__tests__/pages/Claims/ClaimPhoto.spec.js

106 lines
3.0 KiB
JavaScript
Raw Normal View History

2023-02-20 14:13:53 +00:00
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import { ref } from 'vue';
2023-02-22 13:55:29 +00:00
import { mount } from '@vue/test-utils';
2023-02-20 14:13:53 +00:00
import { createWrapper, axios } from 'app/test/vitest/helper';
import ClaimPhoto from 'pages/Claim/Card/ClaimPhoto.vue';
2023-02-22 13:55:29 +00:00
import * as FormData from 'form-data';
2023-02-20 14:13:53 +00:00
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: {
stubs: ['FetchData', 'TeleportSlot'],
mocks: {
claimDms: [{ dmsFk: 1 }],
},
},
}).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);
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,
url: '///api/Claims/1/downloadFile?access_token=',
},
]);
expect(vm.client).toEqual(claimMock.client);
});
});
describe.skip('create()', () => {
it('should upload file and call quasar notify', async () => {
const files = [{ name: 'firstFile' }];
vi.spyOn(axios, 'post').mockResolvedValue({ data: true });
2023-02-20 14:13:53 +00:00
vi.spyOn(vm.quasar, 'notify');
2023-02-22 13:55:29 +00:00
await vm.create(files);
2023-02-20 14:13:53 +00:00
2023-02-22 13:55:29 +00:00
expect(axios).toHaveBeenCalledWith(
expect.objectContaining({ type: 'positive' })
);
expect(vm.quasar.notify).toHaveBeenCalledWith(
expect.objectContaining({ type: 'positive' })
);
2023-02-20 14:13:53 +00:00
});
});
});