2019-05-16 12:07:16 +00:00
|
|
|
import './index.js';
|
|
|
|
|
2019-10-18 19:36:30 +00:00
|
|
|
describe('Ticket component vnTicketService', () => {
|
2019-05-16 12:07:16 +00:00
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
let $httpParamSerializer;
|
|
|
|
let $scope;
|
|
|
|
let $element;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('ticket'));
|
2019-05-16 12:07:16 +00:00
|
|
|
|
|
|
|
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', () => {
|
|
|
|
const config = {
|
|
|
|
filter: {
|
|
|
|
where: {
|
|
|
|
code: 'G'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let serializedParams = $httpParamSerializer(config);
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('GET', `TaxClasses/findOne?${serializedParams}`).respond({id: 4000, name: 'Whatever', code: 'GG'});
|
|
|
|
$httpBackend.expect('GET', `TaxClasses/findOne?${serializedParams}`);
|
2019-05-16 12:07:16 +00:00
|
|
|
controller.getDefaultTaxClass();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.defaultTaxClass.code).toEqual('GG');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onNewServiceTypeResponse', () => {
|
2019-05-29 11:06:42 +00:00
|
|
|
it(`should throw an error if the new service description is empty`, () => {
|
2019-05-16 12:07:16 +00:00
|
|
|
controller.newServiceType = {name: undefined};
|
|
|
|
|
2019-05-29 11:06:42 +00:00
|
|
|
let error;
|
|
|
|
try {
|
2019-10-30 15:57:14 +00:00
|
|
|
controller.onNewServiceTypeResponse('accept');
|
2019-05-29 11:06:42 +00:00
|
|
|
} catch (e) {
|
|
|
|
error = e.message;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error).toBe(`Name can't be empty`);
|
2019-05-16 12:07:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('POST', 'TicketServiceTypes').respond({id: 4001, name: 'great service!'});
|
2019-10-30 15:57:14 +00:00
|
|
|
controller.onNewServiceTypeResponse('accept');
|
2019-05-16 12:07:16 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.services[0].description).toEqual('great service!');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|