salix-front/test/vitest/__tests__/pages/Tickets/TicketAdvance.spec.js

121 lines
3.9 KiB
JavaScript
Raw Normal View History

2024-10-28 12:24:46 +00:00
import { vi, describe, expect, it, beforeAll, afterEach, beforeEach } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper';
import TicketAdvance from 'pages/Ticket/TicketAdvance.vue';
import { Notify } from 'quasar';
2024-10-28 13:21:03 +00:00
import { nextTick } from 'vue';
2024-10-28 12:24:46 +00:00
describe('TicketAdvance', () => {
let wrapper;
let vm;
beforeAll(() => {
vi.spyOn(axios, 'get').mockImplementation(() => ({ data: [] }));
wrapper = createWrapper(TicketAdvance);
vm = wrapper.vm;
2024-10-28 13:21:03 +00:00
vi.spyOn(vm.vnTableRef, 'reload').mockImplementation(() => vi.fn());
vm.vnTableRef.value = { params: {} };
2024-10-28 12:24:46 +00:00
});
beforeEach(() => {
Notify.create = vi.fn();
});
afterEach(() => {
vi.clearAllMocks();
});
describe('requestComponentUpdate()', () => {
const mockTicket = {
futureId: 1,
futureClientFk: 1,
nickname: 'test',
futureAddressFk: 1,
futureAgencyModeFk: 1,
futureWarehouseFk: 1,
futureCompanyFk: 1,
2024-10-28 13:21:03 +00:00
landed: '2023-01-02',
2024-10-28 12:24:46 +00:00
zoneFk: 1,
};
const mockParams = {
clientFk: 1,
nickname: 'test',
agencyModeFk: 1,
addressFk: 1,
zoneFk: 1,
warehouseFk: 1,
companyFk: 1,
2024-10-28 13:21:03 +00:00
landed: '2023-01-02',
shipped: '2023-01-01',
2024-10-28 12:24:46 +00:00
isDeleted: false,
isWithoutNegatives: false,
newTicket: undefined,
keepPrice: true,
};
const queryResult = 'tickets/1/componentUpdate';
it('should return query and params when ticket has no landed', async () => {
2024-10-28 13:21:03 +00:00
vm.vnTableRef.params.dateToAdvance = '2023-01-01';
await nextTick();
const mockLanded = { landed: '2023-01-02', zoneFk: 1 };
2024-10-28 12:24:46 +00:00
vi.spyOn(vm, 'getLanded').mockResolvedValue(mockLanded);
const { query, params } = await vm.requestComponentUpdate(mockTicket, false);
expect(query).toBe(queryResult);
expect(params).toEqual(mockParams);
});
it('should return query and params when ticket has landed', async () => {
const { query, params } = await vm.requestComponentUpdate(mockTicket, false);
expect(query).toBe(queryResult);
expect(params).toEqual(mockParams);
});
});
describe('moveTicketsAdvance()', () => {
it('should move tickets and notify success', async () => {
const tickets = [
{
id: 1,
futureId: 2,
futureShipped: '2023-01-01',
shipped: '2023-01-02',
workerFk: 1,
},
{
id: 2,
futureId: 3,
futureShipped: '2023-01-01',
shipped: '2023-01-02',
workerFk: 1,
},
];
2024-10-28 13:21:03 +00:00
vm.selectedTickets = tickets;
2024-10-28 12:24:46 +00:00
vi.spyOn(axios, 'post').mockResolvedValue({});
await vm.moveTicketsAdvance();
expect(axios.post).toHaveBeenCalledOnce('Tickets/merge', {
tickets: [
{
originId: 2,
destinationId: 1,
originShipped: '2023-01-01',
destinationShipped: '2023-01-02',
workerFk: 1,
},
{
originId: 3,
destinationId: 2,
originShipped: '2023-01-01',
destinationShipped: '2023-01-02',
workerFk: 1,
},
],
});
2024-10-28 13:21:03 +00:00
expect(vm.vnTableRef.reload).toHaveBeenCalled();
expect(Notify.create).toHaveBeenCalled();
2024-10-28 12:24:46 +00:00
expect(vm.selectedTickets).toEqual([]);
});
});
});