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

65 lines
2.1 KiB
JavaScript
Raw Normal View History

import './index.js';
2019-10-18 19:36:30 +00:00
describe('Ticket component vnTicketService', () => {
let controller;
let $httpBackend;
let $httpParamSerializer;
let $scope;
let $element;
beforeEach(ngModule('ticket'));
beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _$httpParamSerializer_, $rootScope) => {
$element = angular.element(`<div></div>`);
$httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
$scope = $rootScope.$new();
controller = $componentController('vnTicketService', {$scope, $element});
}));
describe('getDefaultTaxClass', () => {
it('should set the default tax class in the controller', () => {
2019-11-12 08:24:08 +00:00
$httpBackend.whenRoute('GET', `TaxClasses/findOne`)
.respond({
id: 4000,
name: 'Whatever',
code: 'GG'
});
controller.getDefaultTaxClass();
$httpBackend.flush();
expect(controller.defaultTaxClass.code).toEqual('GG');
});
});
describe('onNewServiceTypeResponse', () => {
it(`should throw an error if the new service description is empty`, () => {
controller.newServiceType = {name: undefined};
let error;
try {
2019-10-30 15:57:14 +00:00
controller.onNewServiceTypeResponse('accept');
} 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', () => {
controller.services = [
{id: 1, description: 'not too great service'}
];
controller.newServiceType = {name: 'totally new stuff'};
controller.currentServiceIndex = 0;
2019-12-13 11:07:36 +00:00
$httpBackend.when('POST', 'TicketServiceTypes').respond({id: 4001, name: 'totally new stuff'});
2019-10-30 15:57:14 +00:00
controller.onNewServiceTypeResponse('accept');
$httpBackend.flush();
2019-12-13 11:07:36 +00:00
expect(controller.services[0].ticketServiceTypeFk).toEqual(4001);
});
});
});