salix/modules/ticket/front/basic-data/step-two/index.spec.js

167 lines
5.5 KiB
JavaScript

import './index.js';
describe('Ticket', () => {
describe('Component vnTicketBasicDataStepTwo', () => {
let controller;
beforeEach(ngModule('ticket'));
beforeEach(inject($componentController => {
const $element = angular.element('<vn-ticket-basic-data-step-two><vn-ticket-basic-data-step-two>');
controller = $componentController('vnTicketBasicDataStepTwo', {$element});
}));
describe('getTotalPrice()', () => {
it('should calculate the total price of the sale based on the data received', () => {
controller.ticket = {
sale: {
items: [{
quantity: 10,
price: 0.1,
component: {newPrice: 0.2, difference: 0.3}
}]
}
};
controller.getTotalPrice();
expect(controller.totalPrice).toEqual(1);
});
});
describe('getTotalNewPrice()', () => {
it('should calculate the total new price of the sale based on the data received', () => {
controller.ticket = {
sale: {
items: [{
quantity: 10,
price: 0.1,
component: {newPrice: 0.2, difference: 0.3}
}]
}
};
controller.getTotalNewPrice();
expect(controller.totalNewPrice).toEqual(2);
});
});
describe('getTotalDifferenceOfPrice()', () => {
it('should calculate the total price difference of the sale based on the data received', () => {
controller.ticket = {
sale: {
items: [{
quantity: 10,
price: 0.1,
component: {newPrice: 0.2, difference: 0.3}
}]
}
};
controller.getTotalDifferenceOfPrice();
expect(controller.totalPriceDifference).toEqual(0.3);
});
});
describe('ticketHaveNegatives()', () => {
it('should show if ticket have any negative, have differences, but not all sale are negative', () => {
controller.ticket = {
sale: {
items: [
{
item: 1,
quantity: 2,
movable: 1
},
{
item: 2,
quantity: 1,
movable: 5
}
],
haveDifferences: true
}
};
controller.ticketHaveNegatives();
expect(controller.haveNegatives).toEqual(true);
});
it('should not show if ticket not have any negative', () => {
controller.ticket = {
sale: {
items: [
{
item: 1,
quantity: 2,
movable: 1
},
{
item: 2,
quantity: 2,
movable: 1
}
],
haveDifferences: true
}
};
controller.ticketHaveNegatives();
expect(controller.haveNegatives).toEqual(false);
});
it('should not show if all sale are negative', () => {
controller.ticket = {
sale: {
items: [
{
item: 1,
quantity: 2,
movable: 1
},
{
item: 2,
quantity: 2,
movable: 1
}
],
haveDifferences: true
}
};
controller.ticketHaveNegatives();
expect(controller.haveNegatives).toEqual(false);
});
it('should not show if ticket not have differences', () => {
controller.ticket = {
sale: {
items: [
{
item: 1,
quantity: 2,
movable: 1
},
{
item: 2,
quantity: 1,
movable: 2
}
],
haveDifferences: false
}
};
controller.ticketHaveNegatives();
expect(controller.haveNegatives).toEqual(false);
});
});
});
});