salix/modules/ticket/front/services/index.spec.js

84 lines
2.5 KiB
JavaScript
Raw Normal View History

import './index.js';
2021-01-18 08:08:50 +00:00
import crudModel from 'core/mocks/crud-model';
2019-10-18 19:36:30 +00:00
describe('Ticket component vnTicketService', () => {
let controller;
let $httpBackend;
let $scope;
let $element;
beforeEach(ngModule('ticket'));
2020-07-23 14:46:16 +00:00
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
2021-01-18 08:08:50 +00:00
$scope.typesModel = crudModel;
2020-03-30 15:30:03 +00:00
$element = angular.element(`<div></div>`);
controller = $componentController('vnTicketService', {$scope, $element});
}));
describe('getDefaultTaxClass', () => {
it('should set the default tax class in the controller', () => {
2023-08-01 10:33:56 +00:00
$httpBackend.whenRoute('GET', `TaxClasses/findOne`).respond({
id: 4000,
name: 'Whatever',
code: 'GG',
});
controller.getDefaultTaxClass();
$httpBackend.flush();
expect(controller.defaultTaxClass.code).toEqual('GG');
});
});
2020-03-30 15:30:03 +00:00
describe('onNewServiceTypeAccept', () => {
it(`should throw an error if the new service type name is empty`, () => {
$scope.newServiceType = {};
let error;
try {
2020-03-30 15:30:03 +00:00
controller.onNewServiceTypeAccept({});
} catch (e) {
error = e.message;
}
expect(error).toBe(`Name can't be empty`);
});
it('should set the description of the selected service upon service type creation', () => {
2020-03-30 15:30:03 +00:00
const service = {
id: 1,
2023-08-01 10:33:56 +00:00
quantity: 10,
2020-03-30 15:30:03 +00:00
};
$scope.newServiceType = {
2023-08-01 10:33:56 +00:00
name: 'Totally new stuff',
2020-03-30 15:30:03 +00:00
};
2020-03-30 15:30:03 +00:00
$httpBackend.when('POST', 'TicketServiceTypes').respond({
id: 4001,
2023-08-01 10:33:56 +00:00
name: 'Totally new stuff',
2020-03-30 15:30:03 +00:00
});
controller.onNewServiceTypeAccept(service);
$httpBackend.flush();
2020-03-30 15:30:03 +00:00
expect(service.ticketServiceTypeFk).toEqual(4001);
});
});
2023-08-01 10:33:56 +00:00
describe('addChecked', () => {
it('should add an item to the checkeds array', () => {
controller.checkeds = [];
controller.addChecked(1);
expect(controller.checkeds).toEqual([1]);
});
it('should remove an item if it is already in the checkeds array', () => {
controller.checkeds = [1, 2, 3];
controller.addChecked(2);
expect(controller.checkeds).toEqual([1, 3]);
});
});
});