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', () => {
|
2023-03-21 14:46:21 +00:00
|
|
|
let vmEdit, vmCreate;
|
|
|
|
const entityId = 1;
|
2023-03-21 11:47:43 +00:00
|
|
|
|
|
|
|
beforeAll(() => {
|
2023-08-25 08:56:03 +00:00
|
|
|
vmEdit = createWrapper(WagonCreate, {
|
|
|
|
propsData: {
|
2023-03-21 14:46:21 +00:00
|
|
|
id: entityId,
|
2023-08-25 08:56:03 +00:00
|
|
|
},
|
|
|
|
}).vm;
|
2023-03-21 14:46:21 +00:00
|
|
|
vmCreate = createWrapper(WagonCreate).vm;
|
2023-03-21 11:47:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vi.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onSubmit()', () => {
|
2023-03-21 14:46:21 +00:00
|
|
|
it('should create a wagon', async () => {
|
2023-03-21 11:47:43 +00:00
|
|
|
vi.spyOn(axios, 'patch').mockResolvedValue({ data: true });
|
2023-03-21 14:46:21 +00:00
|
|
|
vmCreate.wagon = {
|
2023-03-21 11:47:43 +00:00
|
|
|
label: 1234,
|
|
|
|
plate: 'MOCK PLATE',
|
|
|
|
volume: 50,
|
|
|
|
typeFk: 1,
|
|
|
|
};
|
|
|
|
|
2023-03-21 14:46:21 +00:00
|
|
|
await vmCreate.onSubmit();
|
2023-03-21 11:47:43 +00:00
|
|
|
|
2023-08-25 08:56:03 +00:00
|
|
|
expect(axios.patch).toHaveBeenCalledWith(`Wagons`, vmCreate.wagon);
|
2023-03-21 14:46:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should update a wagon', async () => {
|
|
|
|
vi.spyOn(axios, 'patch').mockResolvedValue({ data: true });
|
|
|
|
vmEdit.wagon = {
|
|
|
|
id: entityId,
|
|
|
|
label: 1234,
|
|
|
|
plate: 'MOCK PLATE',
|
|
|
|
volume: 50,
|
|
|
|
typeFk: 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
await vmEdit.onSubmit();
|
|
|
|
|
2023-08-25 08:56:03 +00:00
|
|
|
expect(axios.patch).toHaveBeenCalledWith(`Wagons`, vmEdit.wagon);
|
2023-03-21 11:47:43 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onReset()', () => {
|
2023-03-21 14:46:21 +00:00
|
|
|
it('should reset wagon if have id', async () => {
|
|
|
|
vmEdit.originalData = {
|
2023-03-21 11:47:43 +00:00
|
|
|
label: 1234,
|
|
|
|
plate: 'Original',
|
|
|
|
volume: 200,
|
|
|
|
typeFk: 1,
|
|
|
|
};
|
2023-03-21 14:46:21 +00:00
|
|
|
vmEdit.wagon = {
|
|
|
|
label: 4321,
|
|
|
|
plate: 'Edited',
|
|
|
|
volume: 50,
|
|
|
|
typeFk: 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
await vmEdit.onReset();
|
|
|
|
|
|
|
|
expect(vmEdit.wagon).toEqual(vmEdit.originalData);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should reset wagon if not have id', async () => {
|
|
|
|
vmCreate.wagon = {
|
2023-03-21 11:47:43 +00:00
|
|
|
label: 4321,
|
|
|
|
plate: 'Edited',
|
|
|
|
volume: 50,
|
|
|
|
typeFk: 2,
|
|
|
|
};
|
|
|
|
|
2023-03-21 14:46:21 +00:00
|
|
|
await vmCreate.onReset();
|
2023-03-21 11:47:43 +00:00
|
|
|
|
2023-03-21 14:46:21 +00:00
|
|
|
expect(vmCreate.wagon).toEqual({});
|
2023-03-21 11:47:43 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fetch()', () => {
|
|
|
|
it('should fetch data', async () => {
|
2023-08-25 08:56:03 +00:00
|
|
|
vi.spyOn(axios, 'get').mockResolvedValue({ data: [] });
|
2023-03-21 11:47:43 +00:00
|
|
|
|
2023-03-21 14:46:21 +00:00
|
|
|
await vmEdit.fetch();
|
2023-03-21 11:47:43 +00:00
|
|
|
|
2023-08-25 08:56:03 +00:00
|
|
|
expect(axios.get).toHaveBeenCalledWith(`WagonTypes`);
|
|
|
|
expect(axios.get).toHaveBeenCalledWith(`Wagons/${entityId}`);
|
2023-03-21 11:47:43 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|