salix/client/ticket/src/sale/index.spec.js

193 lines
6.3 KiB
JavaScript
Raw Normal View History

import './index.js';
2018-08-03 06:25:13 +00:00
describe('Ticket', () => {
describe('Component vnTicketSale', () => {
2018-10-22 06:23:10 +00:00
let $ctrl;
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);
$element = $compile('<vn-ticket-sale ticket="ticket"></vn-ticket-sale>')($scope);
$ctrl = $element.controller('vnTicketSale');
$ctrl.card = {reload: () => {}};
$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', () => {
spyOn(window, 'open');
2018-09-11 10:49:31 +00:00
let res = {id: 1};
$httpBackend.expectPOST(`claim/api/Claims/createFromSales`).respond(res);
2018-10-22 06:23:10 +00:00
$ctrl.createClaim();
2018-09-11 10:49:31 +00:00
$httpBackend.flush();
let urlMock = null;
expect(window.open).toHaveBeenCalledWith(urlMock, '_blank');
});
});
2018-10-22 06:23:10 +00:00
describe('total/VAT/subTotal properties', () => {
it('should fill total, VAT and subTotal', () => {
expect($ctrl.subTotal).toEqual(227.5);
expect($ctrl.VAT).toEqual(10.5);
expect($ctrl.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-10-22 06:23:10 +00:00
$ctrl.sales[0].checked = true;
2018-10-22 06:23:10 +00:00
expect($ctrl.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-10-22 06:23:10 +00:00
let sale = $ctrl.sales[1];
sale.checked = true;
let expectedResult = [{id: sale.id, instance: 1}];
2018-07-13 13:57:19 +00:00
2018-10-22 06:23:10 +00:00
expect($ctrl.getCheckedLines()).toEqual(expectedResult);
2018-07-13 13:57:19 +00:00
});
});
describe('onStateOkClick()', () => {
it('should perform a get and then call a function', () => {
let filter = {where: {code: "OK"}, fields: ["id"]};
filter = encodeURIComponent(JSON.stringify(filter));
let res = [{id: 3}];
2018-10-22 06:23:10 +00:00
spyOn($ctrl, 'onStateChange');
$httpBackend.whenGET(`/ticket/api/States?filter=${filter}`).respond(res);
2018-10-22 06:23:10 +00:00
$ctrl.onStateOkClick();
$httpBackend.flush();
2018-10-22 06:23:10 +00:00
expect($ctrl.onStateChange).toHaveBeenCalledWith(3);
});
});
2018-07-13 13:57:19 +00:00
describe('showAddTurnDialog()', () => {
2018-07-17 06:44:31 +00:00
it('should call contrtoller.$scope.addTurn.show()', () => {
2018-10-22 06:23:10 +00:00
$ctrl.$scope.addTurn = {show: () => {}};
spyOn($ctrl.$scope.addTurn, 'show');
$ctrl.showAddTurnDialog();
2018-07-13 13:57:19 +00:00
2018-10-22 06:23:10 +00:00
expect($ctrl.$scope.addTurn.show).toHaveBeenCalledWith();
2018-07-13 13:57:19 +00:00
});
});
describe('addTurn(day)', () => {
2018-07-13 13:57:19 +00:00
it('should make a query and call $.addTurn.hide() and vnApp.showSuccess()', () => {
2018-10-22 06:23:10 +00:00
spyOn($ctrl.$scope.addTurn, 'hide');
2018-08-03 06:25:13 +00:00
$httpBackend.expectPATCH(`/ticket/api/TicketWeeklies`).respond();
2018-10-22 06:23:10 +00:00
$ctrl.addTurn(1);
$httpBackend.flush();
2018-07-13 13:57:19 +00:00
2018-10-22 06:23:10 +00:00
expect($ctrl.$scope.addTurn.hide).toHaveBeenCalledWith();
2018-07-13 13:57:19 +00:00
});
});
describe('onStateChange()', () => {
it('should perform a post and then call a function', () => {
$httpBackend.expectPOST(`/ticket/api/TicketTrackings/changeState`).respond();
2018-10-22 06:23:10 +00:00
$ctrl.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-10-22 06:23:10 +00:00
$ctrl.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();
$ctrl.onRemoveLinesClick('ACCEPT');
2018-07-03 13:23:10 +00:00
$httpBackend.flush();
2018-10-22 06:23:10 +00:00
expect($ctrl.sales.length).toEqual(1);
2018-07-03 13:23:10 +00:00
});
});
describe('unmarkAsReserved()', () => {
it('should call setReserved with false', () => {
2018-10-22 06:23:10 +00:00
spyOn($ctrl, 'setReserved');
2018-07-03 13:23:10 +00:00
2018-10-22 06:23:10 +00:00
$ctrl.unmarkAsReserved(false);
2018-07-03 13:23:10 +00:00
2018-10-22 06:23:10 +00:00
expect($ctrl.setReserved).toHaveBeenCalledWith(false);
2018-07-03 13:23:10 +00:00
});
});
describe('markAsReserved()', () => {
it('should call setReserved with true', () => {
2018-10-22 06:23:10 +00:00
spyOn($ctrl, 'setReserved');
2018-10-22 06:23:10 +00:00
$ctrl.markAsReserved(true);
2018-07-03 13:23:10 +00:00
2018-10-22 06:23:10 +00:00
expect($ctrl.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-10-22 06:23:10 +00:00
$ctrl.sales[1].checked = true;
let expectedRequest = {
sales: [{
id: sales[1].id,
instance: 1
}],
ticketFk: ticket.id,
reserved: false
};
$httpBackend.expectPOST(`/ticket/api/Sales/reserve`, expectedRequest).respond();
$ctrl.unmarkAsReserved(false);
$httpBackend.flush();
});
});
});
});