salix/modules/ticket/front/sale/index.spec.js

171 lines
5.7 KiB
JavaScript
Raw Normal View History

import './index.js';
2018-08-03 06:25:13 +00:00
describe('Ticket', () => {
describe('Component vnTicketSale', () => {
2018-11-06 13:27:16 +00:00
let controller;
2018-10-22 06:23:10 +00:00
let $element;
let $scope;
2018-10-22 06:23:10 +00:00
let $httpBackend;
let ticket = {
id: 1,
clientFk: 1,
shipped: 1,
client: {salesPersonFk: 1}
};
let sales = [
{
id: 1,
quantity: 5,
price: 23.5,
discount: 0
}, {
id: 4,
quantity: 20,
price: 5.5,
discount: 0
}
];
beforeEach(() => {
2018-10-22 06:23:10 +00:00
ngModule('item');
ngModule('ticket');
});
2018-10-22 06:23:10 +00:00
beforeEach(angular.mock.inject(($compile, $rootScope, $state, _$httpBackend_) => {
$state.params.id = ticket.id;
$scope = $rootScope.$new();
2018-10-22 06:23:10 +00:00
$scope.ticket = ticket;
$httpBackend = _$httpBackend_;
$httpBackend.whenGET(/api\/Tickets\/1\/getSales.*/).respond(sales);
$httpBackend.whenGET(`/ticket/api/Tickets/1/getVAT`).respond(200, 10.5);
$httpBackend.whenGET(`/ticket/api/Tickets/1/subtotal`).respond(200, 227.5);
2018-10-22 06:23:10 +00:00
$element = $compile('<vn-ticket-sale ticket="ticket"></vn-ticket-sale>')($scope);
2018-11-06 13:27:16 +00:00
controller = $element.controller('vnTicketSale');
controller.card = {reload: () => {}};
2018-10-22 06:23:10 +00:00
$httpBackend.flush();
}));
2018-10-22 06:23:10 +00:00
afterEach(() => {
$scope.$destroy();
$element.remove();
});
2018-09-11 10:49:31 +00:00
describe('createClaim()', () => {
2018-10-22 06:23:10 +00:00
it('should perform a query and call windows open', () => {
2018-11-06 13:27:16 +00:00
spyOn(controller.$state, 'go');
2018-10-22 06:23:10 +00:00
2018-09-11 10:49:31 +00:00
let res = {id: 1};
$httpBackend.expectPOST(`claim/api/Claims/createFromSales`).respond(res);
2018-11-06 13:27:16 +00:00
controller.createClaim();
2018-09-11 10:49:31 +00:00
$httpBackend.flush();
2018-11-06 13:27:16 +00:00
expect(controller.$state.go).toHaveBeenCalledWith('claim.card.basicData', {id: 1});
2018-09-11 10:49:31 +00:00
});
});
describe('total/VAT/subtotal properties', () => {
2018-10-22 06:23:10 +00:00
it('should fill total, VAT and subTotal', () => {
expect(controller.subtotal).toEqual(227.5);
2018-11-06 13:27:16 +00:00
expect(controller.VAT).toEqual(10.5);
expect(controller.total).toEqual(238);
2018-07-13 13:57:19 +00:00
});
});
2018-10-22 06:23:10 +00:00
describe('isChecked() getter', () => {
it('should set isChecked value to true when one of the instances has the value checked to true', () => {
2018-11-06 13:27:16 +00:00
controller.sales[0].checked = true;
2018-11-06 13:27:16 +00:00
expect(controller.isChecked).toBeTruthy();
});
});
2018-07-13 13:57:19 +00:00
describe('getCheckedLines()', () => {
it('should make an array of the instances with the property checked true()', () => {
2018-11-06 13:27:16 +00:00
let sale = controller.sales[1];
2018-10-22 06:23:10 +00:00
sale.checked = true;
let expectedResult = [{id: sale.id, instance: 1}];
2018-07-13 13:57:19 +00:00
2018-11-06 13:27:16 +00:00
expect(controller.getCheckedLines()).toEqual(expectedResult);
2018-07-13 13:57:19 +00:00
});
});
describe('onStateOkClick()', () => {
it('should perform a get and then call a function', () => {
2018-11-06 13:27:16 +00:00
let filter = {where: {code: 'OK'}, fields: ['id']};
filter = encodeURIComponent(JSON.stringify(filter));
let res = [{id: 3}];
2018-11-06 13:27:16 +00:00
spyOn(controller, 'onStateChange');
$httpBackend.whenGET(`/ticket/api/States?filter=${filter}`).respond(res);
2018-11-06 13:27:16 +00:00
controller.onStateOkClick();
$httpBackend.flush();
2018-11-06 13:27:16 +00:00
expect(controller.onStateChange).toHaveBeenCalledWith(3);
});
});
describe('onStateChange()', () => {
it('should perform a post and then call a function', () => {
$httpBackend.expectPOST(`/ticket/api/TicketTrackings/changeState`).respond();
2018-11-06 13:27:16 +00:00
controller.onStateChange(3);
$httpBackend.flush();
});
});
2018-09-18 07:52:50 +00:00
describe('onRemoveLinesClick()', () => {
2018-07-03 13:23:10 +00:00
it('should call getCheckedLines, call removeInstances, and make a query', () => {
2018-11-06 13:27:16 +00:00
controller.sales[1].checked = true;
2018-07-03 13:23:10 +00:00
2018-10-22 06:23:10 +00:00
$httpBackend.whenPOST(`/ticket/api/Sales/removes`).respond();
2018-11-06 13:27:16 +00:00
controller.onRemoveLinesClick('ACCEPT');
2018-07-03 13:23:10 +00:00
$httpBackend.flush();
2018-11-06 13:27:16 +00:00
expect(controller.sales.length).toEqual(1);
2018-07-03 13:23:10 +00:00
});
});
describe('unmarkAsReserved()', () => {
it('should call setReserved with false', () => {
2018-11-06 13:27:16 +00:00
spyOn(controller, 'setReserved');
2018-07-03 13:23:10 +00:00
2018-11-06 13:27:16 +00:00
controller.unmarkAsReserved(false);
2018-07-03 13:23:10 +00:00
2018-11-06 13:27:16 +00:00
expect(controller.setReserved).toHaveBeenCalledWith(false);
2018-07-03 13:23:10 +00:00
});
});
describe('markAsReserved()', () => {
it('should call setReserved with true', () => {
2018-11-06 13:27:16 +00:00
spyOn(controller, 'setReserved');
2018-11-06 13:27:16 +00:00
controller.markAsReserved(true);
2018-07-03 13:23:10 +00:00
2018-11-06 13:27:16 +00:00
expect(controller.setReserved).toHaveBeenCalledWith(true);
});
2018-07-03 13:23:10 +00:00
});
2018-09-18 07:52:50 +00:00
describe('setReserved()', () => {
2018-07-03 13:23:10 +00:00
it('should call getCheckedLines, $.index.accept and make a query ', () => {
2018-11-06 13:27:16 +00:00
controller.sales[1].checked = true;
2018-10-22 06:23:10 +00:00
let expectedRequest = {
sales: [{
id: sales[1].id,
instance: 1
}],
ticketFk: ticket.id,
reserved: false
};
$httpBackend.expectPOST(`/ticket/api/Sales/reserve`, expectedRequest).respond();
2018-11-06 13:27:16 +00:00
controller.unmarkAsReserved(false);
$httpBackend.flush();
});
});
});
});