2018-05-25 08:03:45 +00:00
|
|
|
import './index.js';
|
2018-05-08 07:25:15 +00:00
|
|
|
|
2018-08-03 06:25:13 +00:00
|
|
|
describe('Ticket', () => {
|
2018-05-08 07:25:15 +00:00
|
|
|
describe('Component vnTicketSale', () => {
|
2018-11-06 13:27:16 +00:00
|
|
|
let controller;
|
2018-10-22 06:23:10 +00:00
|
|
|
let $element;
|
2018-05-08 07:25:15 +00:00
|
|
|
let $scope;
|
2018-10-22 06:23:10 +00:00
|
|
|
let $httpBackend;
|
|
|
|
|
|
|
|
let ticket = {
|
|
|
|
id: 1,
|
|
|
|
clientFk: 1,
|
|
|
|
shipped: 1,
|
2019-03-29 06:29:09 +00:00
|
|
|
created: new Date(),
|
|
|
|
client: {salesPersonFk: 1},
|
|
|
|
address: {mobile: 111111111}
|
2018-10-22 06:23:10 +00:00
|
|
|
};
|
|
|
|
let sales = [
|
|
|
|
{
|
|
|
|
id: 1,
|
2019-03-29 06:29:09 +00:00
|
|
|
concept: 'Item 1',
|
2018-10-22 06:23:10 +00:00
|
|
|
quantity: 5,
|
|
|
|
price: 23.5,
|
|
|
|
discount: 0
|
|
|
|
}, {
|
|
|
|
id: 4,
|
2019-03-29 06:29:09 +00:00
|
|
|
concept: 'Item 2',
|
2018-10-22 06:23:10 +00:00
|
|
|
quantity: 20,
|
|
|
|
price: 5.5,
|
|
|
|
discount: 0
|
|
|
|
}
|
|
|
|
];
|
2018-05-08 07:25:15 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-10-22 06:23:10 +00:00
|
|
|
ngModule('item');
|
|
|
|
ngModule('ticket');
|
2019-03-29 06:29:09 +00:00
|
|
|
ngModule('client');
|
2018-05-08 07:25:15 +00:00
|
|
|
});
|
|
|
|
|
2018-10-22 06:23:10 +00:00
|
|
|
beforeEach(angular.mock.inject(($compile, $rootScope, $state, _$httpBackend_) => {
|
|
|
|
$state.params.id = ticket.id;
|
|
|
|
|
2018-05-08 07:25:15 +00:00
|
|
|
$scope = $rootScope.$new();
|
2018-10-22 06:23:10 +00:00
|
|
|
$scope.ticket = ticket;
|
|
|
|
|
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$httpBackend.whenGET(/api\/Tickets\/1\/getSales.*/).respond(sales);
|
2019-05-27 06:46:11 +00:00
|
|
|
$httpBackend.whenGET(`/api/Tickets/1/getVAT`).respond(200, 10.5);
|
|
|
|
$httpBackend.whenGET(`/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-05-08 07:25:15 +00:00
|
|
|
}));
|
|
|
|
|
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};
|
2019-05-27 06:46:11 +00:00
|
|
|
$httpBackend.expectPOST(`/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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-21 07:43:04 +00:00
|
|
|
describe('total/VAT/subtotal properties', () => {
|
2018-10-22 06:23:10 +00:00
|
|
|
it('should fill total, VAT and subTotal', () => {
|
2019-02-21 07:43:04 +00:00
|
|
|
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', () => {
|
2018-05-08 07:54:14 +00:00
|
|
|
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-05-08 07:54:14 +00:00
|
|
|
|
2018-11-06 13:27:16 +00:00
|
|
|
expect(controller.isChecked).toBeTruthy();
|
2018-05-08 07:54:14 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-05-08 07:25:15 +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']};
|
2018-05-08 07:25:15 +00:00
|
|
|
filter = encodeURIComponent(JSON.stringify(filter));
|
|
|
|
let res = [{id: 3}];
|
2018-11-06 13:27:16 +00:00
|
|
|
spyOn(controller, 'onStateChange');
|
2018-05-08 07:25:15 +00:00
|
|
|
|
2019-05-27 06:46:11 +00:00
|
|
|
$httpBackend.whenGET(`/api/States?filter=${filter}`).respond(res);
|
2018-11-06 13:27:16 +00:00
|
|
|
controller.onStateOkClick();
|
2018-05-08 07:25:15 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
2018-11-06 13:27:16 +00:00
|
|
|
expect(controller.onStateChange).toHaveBeenCalledWith(3);
|
2018-05-08 07:25:15 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onStateChange()', () => {
|
2018-08-02 08:54:03 +00:00
|
|
|
it('should perform a post and then call a function', () => {
|
2019-05-27 06:46:11 +00:00
|
|
|
$httpBackend.expectPOST(`/api/TicketTrackings/changeState`).respond();
|
2018-11-06 13:27:16 +00:00
|
|
|
controller.onStateChange(3);
|
2018-05-08 07:25:15 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
});
|
2018-05-08 07:54:14 +00:00
|
|
|
|
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
|
|
|
|
2019-05-27 06:46:11 +00:00
|
|
|
$httpBackend.whenPOST(`/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-05-08 07:54:14 +00:00
|
|
|
|
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-05-08 07:54:14 +00:00
|
|
|
});
|
2018-07-03 13:23:10 +00:00
|
|
|
});
|
2018-05-08 07:54:14 +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
|
|
|
|
};
|
|
|
|
|
2019-05-27 06:46:11 +00:00
|
|
|
$httpBackend.expectPOST(`/api/Sales/reserve`, expectedRequest).respond();
|
2018-11-06 13:27:16 +00:00
|
|
|
controller.unmarkAsReserved(false);
|
2018-05-08 07:54:14 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
});
|
2019-03-29 06:29:09 +00:00
|
|
|
|
|
|
|
describe('showSMSDialog()', () => {
|
|
|
|
it('should open an SMS dialog with specified data', () => {
|
|
|
|
spyOn(controller.$scope.sms, 'open');
|
|
|
|
|
|
|
|
controller.sales[1].checked = true;
|
|
|
|
controller.showSMSDialog();
|
|
|
|
|
|
|
|
expect(controller.$scope.sms.open).toHaveBeenCalledWith();
|
2019-04-16 06:21:20 +00:00
|
|
|
expect(controller.newSMS.destination).toEqual(111111111);
|
2019-03-29 06:29:09 +00:00
|
|
|
expect(controller.newSMS.message).not.toEqual('');
|
|
|
|
});
|
|
|
|
});
|
2018-05-08 07:25:15 +00:00
|
|
|
});
|
|
|
|
});
|