2018-05-25 08:03:45 +00:00
|
|
|
import './index.js';
|
2018-05-08 07:25:15 +00:00
|
|
|
|
2018-07-03 13:23:10 +00:00
|
|
|
describe('Ticket', () => {
|
2018-05-08 07:25:15 +00:00
|
|
|
describe('Component vnTicketSale', () => {
|
|
|
|
let $componentController;
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
let $state;
|
|
|
|
let $scope;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
angular.mock.module('ticket');
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_, $rootScope) => {
|
|
|
|
$componentController = _$componentController_;
|
|
|
|
$httpBackend = _$httpBackend_;
|
2018-05-25 15:25:35 +00:00
|
|
|
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
2018-05-08 07:25:15 +00:00
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$state = _$state_;
|
|
|
|
$state.params.id = 1;
|
|
|
|
controller = $componentController('vnTicketSale', {$scope: $scope}, {$state: $state});
|
2018-07-03 13:23:10 +00:00
|
|
|
controller.ticket = {id: 1};
|
|
|
|
controller.$ = {index: {model: {instances: [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
quantity: 5,
|
|
|
|
price: 23.5,
|
|
|
|
discount: 0,
|
|
|
|
checked: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 4,
|
|
|
|
quantity: 20,
|
|
|
|
price: 5.5,
|
|
|
|
discount: 0,
|
|
|
|
checked: true
|
|
|
|
}
|
|
|
|
]}, accept: () => {
|
|
|
|
return {
|
|
|
|
then: () => {}
|
|
|
|
};
|
|
|
|
}}};
|
2018-05-08 07:25:15 +00:00
|
|
|
}));
|
|
|
|
|
2018-05-08 07:54:14 +00:00
|
|
|
describe('isChecked() setter/getter', () => {
|
|
|
|
it('should set isChecked value to true when one of the instances has the value checked to true', () => {
|
|
|
|
let lines = [
|
|
|
|
{checked: false},
|
|
|
|
{checked: true}
|
|
|
|
];
|
2018-07-03 13:23:10 +00:00
|
|
|
controller.$.index.model.instances = lines;
|
2018-05-08 07:54:14 +00:00
|
|
|
|
|
|
|
expect(controller.isChecked).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-05-08 07:25:15 +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}];
|
|
|
|
spyOn(controller, 'onStateChange');
|
|
|
|
|
|
|
|
$httpBackend.whenGET(`/ticket/api/States?filter=${filter}`).respond(res);
|
|
|
|
$httpBackend.expectGET(`/ticket/api/States?filter=${filter}`);
|
|
|
|
controller.onStateOkClick();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.onStateChange).toHaveBeenCalledWith(3);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onStateChange()', () => {
|
|
|
|
it('should perform a post and then call a function', () => {
|
2018-06-06 14:54:40 +00:00
|
|
|
$httpBackend.expectPOST(`/ticket/api/TicketTrackings/changeState`).respond();
|
2018-05-08 07:25:15 +00:00
|
|
|
controller.card = {reload: () => {}};
|
|
|
|
controller.onStateChange(3);
|
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
});
|
2018-05-08 07:54:14 +00:00
|
|
|
|
2018-07-03 13:23:10 +00:00
|
|
|
describe('getTaxes()', () => {
|
|
|
|
it('should call getSubTotal and getVAT', () => {
|
|
|
|
spyOn(controller, 'getSubTotal');
|
|
|
|
spyOn(controller, 'getVAT');
|
|
|
|
controller.getTaxes();
|
|
|
|
|
|
|
|
expect(controller.getSubTotal).toHaveBeenCalledWith();
|
|
|
|
expect(controller.getVAT).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getTaxes()', () => {
|
|
|
|
it('should call getSubTotal and getVAT', () => {
|
|
|
|
spyOn(controller, 'getSubTotal');
|
|
|
|
spyOn(controller, 'getVAT');
|
|
|
|
controller.getTaxes();
|
|
|
|
|
|
|
|
expect(controller.getSubTotal).toHaveBeenCalledWith();
|
|
|
|
expect(controller.getVAT).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
xdescribe('onRemoveLinesClick()', () => {
|
|
|
|
it('should call getCheckedLines, call removeInstances, and make a query', () => {
|
|
|
|
spyOn(controller, 'getCheckedLines');
|
|
|
|
spyOn(controller, 'removeInstances');
|
|
|
|
$httpBackend.expectPOST(`/ticket/api/Sales/removes`).respond();
|
|
|
|
|
|
|
|
controller.onRemoveLinesClick('ACCEPT');
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.getCheckedLines).toHaveBeenCalledWith();
|
|
|
|
expect(controller.removeInstances).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('unmarkAsReserved()', () => {
|
|
|
|
it('should call setReserved with false', () => {
|
|
|
|
spyOn(controller, 'setReserved');
|
|
|
|
|
|
|
|
controller.unmarkAsReserved(false);
|
|
|
|
|
|
|
|
expect(controller.setReserved).toHaveBeenCalledWith(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('markAsReserved()', () => {
|
|
|
|
it('should call setReserved with true', () => {
|
|
|
|
spyOn(controller, 'setReserved');
|
2018-05-08 07:54:14 +00:00
|
|
|
|
2018-07-03 13:23:10 +00:00
|
|
|
controller.markAsReserved(true);
|
|
|
|
|
|
|
|
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-07-03 13:23:10 +00:00
|
|
|
describe('setReserved()', () => {
|
|
|
|
it('should call getCheckedLines, $.index.accept and make a query ', () => {
|
|
|
|
spyOn(controller, 'getCheckedLines');
|
|
|
|
spyOn(controller.$.index, 'accept');
|
|
|
|
$httpBackend.expectPOST(`/ticket/api/Sales/reserve`).respond();
|
|
|
|
controller.setReserved(true);
|
2018-05-08 07:54:14 +00:00
|
|
|
$httpBackend.flush();
|
2018-07-03 13:23:10 +00:00
|
|
|
|
|
|
|
expect(controller.$.index.accept).toHaveBeenCalledWith();
|
|
|
|
expect(controller.getCheckedLines).toHaveBeenCalledWith();
|
2018-05-08 07:54:14 +00:00
|
|
|
});
|
|
|
|
});
|
2018-05-08 07:25:15 +00:00
|
|
|
});
|
|
|
|
});
|