import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; import { ref } from 'vue'; import { mount } from '@vue/test-utils'; import { createWrapper, axios } from 'app/test/vitest/helper'; import ClaimPhoto from 'pages/Claim/Card/ClaimPhoto.vue'; import * as FormData from 'form-data'; 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 }], }, }, }).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(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.skip('create()', () => { it('should upload file and call quasar notify', async () => { const files = [{ name: 'firstFile' }]; vi.spyOn(axios, 'post').mockResolvedValue({ data: true }); vi.spyOn(vm.quasar, 'notify'); await vm.create(files); expect(axios).toHaveBeenCalledWith( expect.objectContaining({ type: 'positive' }) ); expect(vm.quasar.notify).toHaveBeenCalledWith( expect.objectContaining({ type: 'positive' }) ); }); }); });