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

48 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-04-11 12:36:12 +00:00
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(),
},
2024-04-25 12:03:00 +00:00
},
2023-04-11 12:36:12 +00:00
}).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');
2024-04-25 12:03:00 +00:00
vm.selected = [{ id: 1, saleFk: 1, claimFk: 1 }];
2023-04-11 12:36:12 +00:00
2024-04-25 12:03:00 +00:00
vm.route.params.id = 1;
2023-04-11 12:36:12 +00:00
await vm.importLines();
2024-04-25 12:03:00 +00:00
const expectedData = [{ saleFk: 1, claimFk: 1 }];
2023-04-11 12:36:12 +00:00
expect(axios.post).toHaveBeenCalledWith('ClaimBeginnings', expectedData, {
2024-04-25 12:03:00 +00:00
signal: expect.any(Object),
});
2023-04-11 12:36:12 +00:00
expect(vm.quasar.notify).toHaveBeenCalledWith(
expect.objectContaining({
message: 'Lines added to claim',
2024-04-25 12:03:00 +00:00
type: 'positive',
2023-04-11 12:36:12 +00:00
})
);
2024-04-25 12:03:00 +00:00
expect(vm.canceller).toEqual(null);
2023-04-11 12:36:12 +00:00
});
});
});