65 lines
2.3 KiB
JavaScript
65 lines
2.3 KiB
JavaScript
|
import './index.js';
|
||
|
|
||
|
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', () => {
|
||
|
const config = {
|
||
|
filter: {
|
||
|
where: {
|
||
|
code: 'G'
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
let serializedParams = $httpParamSerializer(config);
|
||
|
|
||
|
$httpBackend.when('GET', `/api/TaxClasses/findOne?${serializedParams}`).respond({id: 4000, name: 'Whatever', code: 'GG'});
|
||
|
$httpBackend.expect('GET', `/api/TaxClasses/findOne?${serializedParams}`);
|
||
|
controller.getDefaultTaxClass();
|
||
|
$httpBackend.flush();
|
||
|
|
||
|
expect(controller.defaultTaxClass.code).toEqual('GG');
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('onNewServiceTypeResponse', () => {
|
||
|
it(`should throw an error`, () => {
|
||
|
controller.newServiceType = {name: undefined};
|
||
|
let error = controller.onNewServiceTypeResponse('ACCEPT');
|
||
|
|
||
|
expect(error.message).toEqual(`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;
|
||
|
|
||
|
$httpBackend.when('POST', '/api/TicketServiceTypes').respond({id: 4001, name: 'great service!'});
|
||
|
$httpBackend.expect('POST', '/api/TicketServiceTypes');
|
||
|
controller.onNewServiceTypeResponse('ACCEPT');
|
||
|
$httpBackend.flush();
|
||
|
|
||
|
expect(controller.services[0].description).toEqual('great service!');
|
||
|
});
|
||
|
});
|
||
|
});
|