salix-front/test/vitest/__tests__/pages/Wagons/WagonCreate.spec.js

73 lines
1.8 KiB
JavaScript
Raw Normal View History

2023-03-21 11:47:43 +00:00
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper';
import WagonCreate from 'pages/Wagon/WagonCreate.vue';
describe('WagonCreate', () => {
let vm;
beforeAll(() => {
vm = createWrapper(WagonCreate, {propsData: {
id: 1,
}}).vm;
});
afterEach(() => {
vi.clearAllMocks();
});
describe('onSubmit()', () => {
it('should create or update a wagon', async () => {
vi.spyOn(axios, 'patch').mockResolvedValue({ data: true });
vm.wagon = {
id: vm.entityId,
label: 1234,
plate: 'MOCK PLATE',
volume: 50,
typeFk: 1,
};
await vm.onSubmit();
expect(axios.patch).toHaveBeenCalledWith(
`Wagons`, vm.wagon
);
});
});
describe('onReset()', () => {
it('should reset wagon', async () => {
vm.originalData = {
label: 1234,
plate: 'Original',
volume: 200,
typeFk: 1,
};
vm.wagon = {
label: 4321,
plate: 'Edited',
volume: 50,
typeFk: 2,
};
await vm.onReset();
expect(vm.wagon).toEqual(vm.originalData);
});
});
describe('fetch()', () => {
it('should fetch data', async () => {
vi.spyOn(axios, 'get').mockResolvedValue({ data: true });
await vm.fetch();
expect(axios.get).toHaveBeenCalledWith(
`WagonTypes`
);
expect(axios.get).toHaveBeenCalledWith(
`Wagons/1`
);
});
});
});