#6696 - mana #1052
|
@ -264,11 +264,6 @@ const onDiscountClick = async (sale) => {
|
||||||
sale: JSON.parse(JSON.stringify(sale)),
|
sale: JSON.parse(JSON.stringify(sale)),
|
||||||
discount: sale.discount,
|
discount: sale.discount,
|
||||||
};
|
};
|
||||||
} else {
|
|
||||||
edit.value = {
|
|
||||||
sales: selectedValidSales.value || [],
|
|
||||||
discount: null,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ const props = defineProps({
|
||||||
ticket: {
|
ticket: {
|
||||||
type: Object,
|
type: Object,
|
||||||
required: true,
|
required: true,
|
||||||
default: () => {},
|
|
||||||
},
|
},
|
||||||
sales: {
|
sales: {
|
||||||
type: Array,
|
type: Array,
|
||||||
|
|
|
@ -15,7 +15,19 @@ describe('TicketSale ', () => {
|
||||||
{ id: 2, discount: 7 },
|
{ id: 2, discount: 7 },
|
||||||
],
|
],
|
||||||
}));
|
}));
|
||||||
wrapper = createWrapper(TicketSale);
|
wrapper = createWrapper(TicketSale, {
|
||||||
|
props: {
|
||||||
|
ticket: { id: 123, name: 'Sample Ticket' },
|
||||||
|
isTicketEditable: true,
|
||||||
|
},
|
||||||
|
global: {
|
||||||
|
mocks: {
|
||||||
|
store: {
|
||||||
|
data: { id: 123, name: 'Sample Ticket' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
// wrapper.vm.route = { params: { id: 123 } };
|
// wrapper.vm.route = { params: { id: 123 } };
|
||||||
vm = wrapper.vm;
|
vm = wrapper.vm;
|
||||||
vi.spyOn(vm, 'isSalePrepared').mockResolvedValue(true);
|
vi.spyOn(vm, 'isSalePrepared').mockResolvedValue(true);
|
||||||
|
@ -31,22 +43,41 @@ describe('TicketSale ', () => {
|
||||||
{ id: 1, discount: 5 },
|
{ id: 1, discount: 5 },
|
||||||
{ id: 2, discount: 7 },
|
{ id: 2, discount: 7 },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const newDiscount = 10;
|
||||||
const componentName = 'TicketSale';
|
const componentName = 'TicketSale';
|
||||||
|
|
||||||
await vm.updateDiscount(sales, componentName, 10);
|
await vm.updateDiscount(sales, componentName, newDiscount);
|
||||||
|
|
||||||
expect(sales[0].discount).toBe(10);
|
expect(sales[0].discount).toBe(newDiscount);
|
||||||
expect(sales[1].discount).toBe(10);
|
expect(sales[1].discount).toBe(newDiscount);
|
||||||
|
expect(vm.edit).toEqual({
|
||||||
|
price: null,
|
||||||
|
discount: null,
|
||||||
|
sale: null,
|
||||||
|
sales: null,
|
||||||
|
oldQuantity: null,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it.only('should not update discounts if there are no changes', async () => {
|
it.only('should not update discounts if there are no changes', async () => {
|
||||||
|
const newDiscount = 10;
|
||||||
const sales = [
|
const sales = [
|
||||||
{ id: 1, discount: 10 },
|
{ id: 1, itemFk: 123, discount: 10 },
|
||||||
{ id: 2, discount: 10 },
|
{ id: 2, itemFk: 456, discount: 10 },
|
||||||
];
|
];
|
||||||
const componentName = 'TicketSale';
|
const componentName = 'TicketSale';
|
||||||
|
|
||||||
await vm.updateDiscount(sales, componentName);
|
await vm.updateDiscount(sales, componentName, newDiscount);
|
||||||
|
|
||||||
|
expect(axios.post).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not update discounts if there is no discount', async () => {
|
||||||
|
const sales = [{ id: 1, discount: 10 }];
|
||||||
|
const componentName = 'TicketSale';
|
||||||
|
|
||||||
|
await vm.updateDiscount(sales, componentName, null);
|
||||||
|
|
||||||
expect(axios.post).not.toHaveBeenCalled();
|
expect(axios.post).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
@ -65,22 +96,4 @@ describe('TicketSale ', () => {
|
||||||
|
|
||||||
expect(axios.post).not.toHaveBeenCalled();
|
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,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue