68 lines
2.0 KiB
JavaScript
68 lines
2.0 KiB
JavaScript
import './index.js';
|
|
|
|
describe('Ticket component vnTicketService', () => {
|
|
let controller;
|
|
let $httpBackend;
|
|
let $scope;
|
|
let $element;
|
|
|
|
beforeEach(ngModule('ticket'));
|
|
|
|
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
|
|
$httpBackend = _$httpBackend_;
|
|
$scope = $rootScope.$new();
|
|
|
|
$element = angular.element(`<div></div>`);
|
|
controller = $componentController('vnTicketService', {$scope, $element});
|
|
}));
|
|
|
|
describe('getDefaultTaxClass', () => {
|
|
it('should set the default tax class in the controller', () => {
|
|
$httpBackend.whenRoute('GET', `TaxClasses/findOne`)
|
|
.respond({
|
|
id: 4000,
|
|
name: 'Whatever',
|
|
code: 'GG'
|
|
});
|
|
controller.getDefaultTaxClass();
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.defaultTaxClass.code).toEqual('GG');
|
|
});
|
|
});
|
|
|
|
describe('onNewServiceTypeAccept', () => {
|
|
it(`should throw an error if the new service type name is empty`, () => {
|
|
$scope.newServiceType = {};
|
|
|
|
let error;
|
|
try {
|
|
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', () => {
|
|
const service = {
|
|
id: 1,
|
|
quantity: 10
|
|
};
|
|
$scope.newServiceType = {
|
|
name: 'Totally new stuff'
|
|
};
|
|
|
|
$httpBackend.when('POST', 'TicketServiceTypes').respond({
|
|
id: 4001,
|
|
name: 'Totally new stuff'
|
|
});
|
|
controller.onNewServiceTypeAccept(service);
|
|
$httpBackend.flush();
|
|
|
|
expect(service.ticketServiceTypeFk).toEqual(4001);
|
|
});
|
|
});
|
|
});
|