karma test

This commit is contained in:
gerard 2018-07-13 15:57:19 +02:00
parent 2737bc0b0b
commit d1cf22bc65
2 changed files with 71 additions and 12 deletions

View File

@ -1,6 +1,6 @@
import './index.js';
fdescribe('ticket', () => {
describe('ticket', () => {
describe('Component vnTicketDataStepOne', () => {
let $componentController;
let $state;

View File

@ -44,6 +44,48 @@ describe('Ticket', () => {
}}};
}));
describe('getSales()', () => {
it('should make a query and call getTaxes()', () => {
spyOn(controller, 'getTaxes');
$httpBackend.expectGET(`/api/Tickets/1/getSales`).respond();
controller.getSales();
$httpBackend.flush();
expect(controller.getTaxes).toHaveBeenCalledWith();
});
});
describe('$onChanges()', () => {
it('should call getSales and getVAT', () => {
spyOn(controller, 'getSubTotal');
spyOn(controller, 'getVAT');
controller.getTaxes();
expect(controller.getSubTotal).toHaveBeenCalledWith();
expect(controller.getVAT).toHaveBeenCalledWith();
});
});
describe('getSubTotal()', () => {
it('should calculate SubTotal', () => {
controller.sales = [{quantity: 2, price: 10, discount: 10}];
controller.getSubTotal();
expect(controller.subTotal).toEqual(18);
});
});
describe('getVAT()', () => {
it('should make a query, set vat and calculate total', () => {
controller.subTotal = 10;
$httpBackend.expectGET(`/ticket/api/Tickets/1/getVAT`).respond();
controller.getVAT();
$httpBackend.flush();
expect(controller.total).toEqual(10);
});
});
describe('isChecked() setter/getter', () => {
it('should set isChecked value to true when one of the instances has the value checked to true', () => {
let lines = [
@ -56,6 +98,14 @@ describe('Ticket', () => {
});
});
describe('getCheckedLines()', () => {
it('should make an array of the instances with the property checked true()', () => {
controller.sales = [{id: 1, checked: true}, {id: 2, checked: false}, {id: 3, checked: true}];
expect(controller.getCheckedLines()).toEqual([{id: 1, instance: 0}, {id: 3, instance: 2}]);
});
});
describe('onStateOkClick()', () => {
it('should perform a get and then call a function', () => {
let filter = {where: {code: "OK"}, fields: ["id"]};
@ -72,6 +122,26 @@ describe('Ticket', () => {
});
});
describe('showAddTurnDialog()', () => {
it('should call contrtoller.$.addTurn.show()', () => {
controller.$.addTurn = {show: () => {}};
spyOn(controller.$.addTurn, 'show');
controller.showAddTurnDialog();
expect(controller.$.addTurn.show).toHaveBeenCalledWith();
});
});
xdescribe('addTurn(day)', () => {
it('should make a query and call $.addTurn.hide() and vnApp.showSuccess()', () => {
controller.$.addTurn = {hide: () => {}};
spyOn(controller.$.addTurn, 'hide');
controller.showAddTurnDialog();
expect(controller.$.addTurn.show).toHaveBeenCalledWith();
});
});
describe('onStateChange()', () => {
it('should perform a post and then call a function', () => {
$httpBackend.expectPOST(`/ticket/api/TicketTrackings/changeState`).respond();
@ -81,17 +151,6 @@ describe('Ticket', () => {
});
});
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');