#6696 - mana #1052
|
@ -0,0 +1,86 @@
|
|||
import { vi, describe, it, beforeEach, afterEach, expect } from 'vitest';
|
||||
import { createWrapper } from 'app/test/vitest/helper';
|
||||
import TicketSale from 'pages/Ticket/Card/TicketSale.vue';
|
||||
import axios from 'axios';
|
||||
|
||||
describe('TicketSale ', () => {
|
||||
let wrapper;
|
||||
let vm;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.spyOn(axios, 'post').mockResolvedValue({});
|
||||
vi.spyOn(axios, 'get').mockImplementation(() => ({
|
||||
data: [
|
||||
{ id: 1, discount: 5 },
|
||||
{ id: 2, discount: 7 },
|
||||
],
|
||||
}));
|
||||
wrapper = createWrapper(TicketSale);
|
||||
// wrapper.vm.route = { params: { id: 123 } };
|
||||
vm = wrapper.vm;
|
||||
vi.spyOn(vm, 'isSalePrepared').mockResolvedValue(true);
|
||||
vm.edit = { discount: 10 }; // Set the discount in the edit state
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should update discounts for sales when changes exist', async () => {
|
||||
const sales = [
|
||||
{ id: 1, discount: 5 },
|
||||
{ id: 2, discount: 7 },
|
||||
];
|
||||
const componentName = 'TicketSale';
|
||||
|
||||
await vm.updateDiscount(sales, componentName, 10);
|
||||
|
||||
expect(sales[0].discount).toBe(10);
|
||||
expect(sales[1].discount).toBe(10);
|
||||
});
|
||||
|
||||
it.only('should not update discounts if there are no changes', async () => {
|
||||
const sales = [
|
||||
{ id: 1, discount: 10 },
|
||||
{ id: 2, discount: 10 },
|
||||
];
|
||||
const componentName = 'TicketSale';
|
||||
|
||||
await vm.updateDiscount(sales, componentName);
|
||||
|
||||
expect(axios.post).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not update discounts if any sale is not prepared', async () => {
|
||||
vi.spyOn(vm, 'isSalePrepared').mockImplementation((sale) =>
|
||||
Promise.resolve(sale.id !== 1)
|
||||
);
|
||||
const sales = [
|
||||
{ id: 1, discount: 5 },
|
||||
{ id: 2, discount: 7 },
|
||||
];
|
||||
const componentName = 'TicketSale';
|
||||
|
||||
await vm.updateDiscount(sales, componentName);
|
||||
|
||||
expect(axios.post).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should reset edit state after updating discounts', async () => {
|
||||
const sales = [
|
||||
{ id: 1, discount: 5 },
|
||||
{ id: 2, discount: 7 },
|
||||
];
|
||||
const componentName = 'TicketSale';
|
||||
|
||||
await vm.updateDiscount(sales, componentName);
|
||||
|
||||
expect(vm.edit).toEqual({
|
||||
price: null,
|
||||
discount: null,
|
||||
sale: null,
|
||||
sales: null,
|
||||
oldQuantity: null,
|
||||
});
|
||||
});
|
||||
});
|
|
@ -86,7 +86,7 @@ export function createWrapper(component, options) {
|
|||
},
|
||||
};
|
||||
|
||||
const mountOptions = Object.assign({}, defaultOptions);
|
||||
const mountOptions = { ...defaultOptions };
|
||||
|
||||
if (options instanceof Object) {
|
||||
Object.assign(mountOptions, options);
|
||||
|
|
Loading…
Reference in New Issue