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; const claimMock = { claimDms: [ { dmsFk: 1, dms: { contentType: 'contentType', }, }, ], client: { id: '1', }, }; beforeAll(() => { vm = createWrapper(ClaimPhoto, { global: { stubs: ['FetchData', 'TeleportSlot'], mocks: { claimDms: [{ dmsFk: 1 }], claimDmsRef: { hola: 'hola' }, }, }, }).vm; }); afterEach(() => { 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(axios.post).toHaveBeenCalledWith( `ClaimDms/${claimMock.claimDms[0].dmsFk}/removeFile` ); expect(vm.quasar.notify).toHaveBeenCalledWith( expect.objectContaining({ type: 'positive' }) ); expect(vm.claimDms).toEqual([]); }); }); describe('viewDeleteDms()', () => { it('should call quasar dialog', async () => { 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('create()', () => { it('should upload file and call quasar notify', async () => { const files = [{ name: 'firstFile' }]; vi.mock('claimDmsRef', {}); vi.spyOn(axios, 'post').mockResolvedValue({ data: true }); vi.spyOn(vm.quasar, 'notify'); await vm.create(files); expect(axios.post).toHaveBeenCalledWith( expect.objectContaining({ type: 'positive' }) ); expect(vm.quasar.notify).toHaveBeenCalledWith( expect.objectContaining({ type: 'positive' }) ); }); }); });