69 lines
2.1 KiB
JavaScript
69 lines
2.1 KiB
JavaScript
import './index.js';
|
|
import crudModel from 'core/mocks/crud-model';
|
|
|
|
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();
|
|
$scope.typesModel = crudModel;
|
|
$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);
|
|
});
|
|
});
|
|
});
|