This commit is contained in:
gerard 2018-07-03 15:23:10 +02:00
parent 237c2afecd
commit 5a6baa646f
1 changed files with 85 additions and 16 deletions

View File

@ -1,6 +1,6 @@
import './index.js';
xdescribe('Ticket', () => {
describe('Ticket', () => {
describe('Component vnTicketSale', () => {
let $componentController;
let controller;
@ -17,14 +17,30 @@ xdescribe('Ticket', () => {
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
$scope = $rootScope.$new();
$scope.index = {model: {instances: [{id: 1}, {id: 2}]}, accept: () => {
return {
then: () => {}
};
}};
$state = _$state_;
$state.params.id = 1;
controller = $componentController('vnTicketSale', {$scope: $scope}, {$state: $state});
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: () => {}
};
}}};
}));
describe('isChecked() setter/getter', () => {
@ -33,7 +49,7 @@ xdescribe('Ticket', () => {
{checked: false},
{checked: true}
];
$scope.index.model.instances = lines;
controller.$.index.model.instances = lines;
expect(controller.isChecked).toBeTruthy();
});
@ -64,19 +80,72 @@ xdescribe('Ticket', () => {
});
});
describe('onRemoveLinesClick()', () => {
it('should remove an object of the model if has the attribute cheched true', () => {
$scope.index.model.instances = [{id: 1, checked: true}, {id: 2, checked: false}];
controller.onRemoveLinesClick();
describe('getTaxes()', () => {
it('should call getSubTotal and getVAT', () => {
spyOn(controller, 'getSubTotal');
spyOn(controller, 'getVAT');
controller.getTaxes();
expect($scope.index.model.instances).toEqual([{id: 2, checked: false}]);
expect(controller.getSubTotal).toHaveBeenCalledWith();
expect(controller.getVAT).toHaveBeenCalledWith();
});
});
it('should make a post if an object the model has the attribute cheched true', () => {
$scope.index.model.instances = [{id: 1, checked: false}, {id: 2, checked: false}];
$httpBackend.expectPOST(`/ticket/api/Sales/crudSale`).respond();
controller.onRemoveLinesClick();
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');
controller.markAsReserved(true);
expect(controller.setReserved).toHaveBeenCalledWith(true);
});
});
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);
$httpBackend.flush();
expect(controller.$.index.accept).toHaveBeenCalledWith();
expect(controller.getCheckedLines).toHaveBeenCalledWith();
});
});
});