117 lines
3.8 KiB
JavaScript
117 lines
3.8 KiB
JavaScript
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';
|
|
|
|
describe('TicketAdvance', () => {
|
|
let wrapper;
|
|
let vm;
|
|
|
|
beforeAll(() => {
|
|
vi.spyOn(axios, 'get').mockImplementation(() => ({ data: [] }));
|
|
wrapper = createWrapper(TicketAdvance);
|
|
vm = wrapper.vm;
|
|
// vm.vnTableRef.value = { reload: vi.fn(), params: {} };
|
|
});
|
|
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,
|
|
landed: '2023-01-01',
|
|
zoneFk: 1,
|
|
};
|
|
const mockParams = {
|
|
clientFk: 1,
|
|
nickname: 'test',
|
|
agencyModeFk: 1,
|
|
addressFk: 1,
|
|
zoneFk: 1,
|
|
warehouseFk: 1,
|
|
companyFk: 1,
|
|
landed: '2023-01-01',
|
|
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 () => {
|
|
const mockLanded = { landed: '2023-01-01', zoneFk: 1 };
|
|
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,
|
|
},
|
|
];
|
|
vm.selectedTickets.value = tickets;
|
|
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,
|
|
},
|
|
],
|
|
});
|
|
expect(Notify.create).toHaveBeenCalledWith({
|
|
type: 'positive',
|
|
message: 'advanceTickets.moveTicketSuccess',
|
|
});
|
|
expect(vm.selectedTickets).toEqual([]);
|
|
});
|
|
});
|
|
});
|