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

48 lines
1.4 KiB
JavaScript

import { vi, describe, expect, it, beforeAll, beforeEach, afterEach } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper';
import ClaimLinesImport from 'pages/Claim/Card/ClaimLinesImport.vue';
describe('ClaimLinesImport', () => {
let vm;
beforeAll(() => {
vm = createWrapper(ClaimLinesImport, {
global: {
stubs: ['FetchData'],
mocks: {
fetch: vi.fn(),
},
},
}).vm;
});
afterEach(() => {
vi.clearAllMocks();
});
describe('importLines()', () => {
it('should make a POST request and then call to the quasar notify() method', async () => {
vi.spyOn(axios, 'post').mockResolvedValue({ data: true });
vi.spyOn(vm.quasar, 'notify');
vm.selected = [{ id: 1, saleFk: 1, claimFk: 1 }];
vm.route.params.id = 1;
await vm.importLines();
const expectedData = [{ saleFk: 1, claimFk: 1 }];
expect(axios.post).toHaveBeenCalledWith('ClaimBeginnings', expectedData, {
signal: expect.any(Object),
});
expect(vm.quasar.notify).toHaveBeenCalledWith(
expect.objectContaining({
message: 'Lines added to claim',
type: 'positive',
})
);
expect(vm.canceller).toEqual(null);
});
});
});