2019-05-16 12:07:16 +00:00
|
|
|
import './index.js';
|
2021-01-18 08:08:50 +00:00
|
|
|
import crudModel from 'core/mocks/crud-model';
|
2019-05-16 12:07:16 +00:00
|
|
|
|
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 $scope;
|
|
|
|
let $element;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('ticket'));
|
2019-05-16 12:07:16 +00:00
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
|
2019-05-16 12:07:16 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$scope = $rootScope.$new();
|
2021-01-18 08:08:50 +00:00
|
|
|
$scope.typesModel = crudModel;
|
2020-03-30 15:30:03 +00:00
|
|
|
$element = angular.element(`<div></div>`);
|
2019-05-16 12:07:16 +00:00
|
|
|
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'
|
|
|
|
});
|
2019-05-16 12:07:16 +00:00
|
|
|
controller.getDefaultTaxClass();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.defaultTaxClass.code).toEqual('GG');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-03-30 15:30:03 +00:00
|
|
|
describe('onNewServiceTypeAccept', () => {
|
|
|
|
it(`should throw an error if the new service type name is empty`, () => {
|
|
|
|
$scope.newServiceType = {};
|
2019-05-16 12:07:16 +00:00
|
|
|
|
2019-05-29 11:06:42 +00:00
|
|
|
let error;
|
|
|
|
try {
|
2020-03-30 15:30:03 +00:00
|
|
|
controller.onNewServiceTypeAccept({});
|
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', () => {
|
2020-03-30 15:30:03 +00:00
|
|
|
const service = {
|
|
|
|
id: 1,
|
|
|
|
quantity: 10
|
|
|
|
};
|
|
|
|
$scope.newServiceType = {
|
|
|
|
name: 'Totally new stuff'
|
|
|
|
};
|
2019-05-16 12:07:16 +00:00
|
|
|
|
2020-03-30 15:30:03 +00:00
|
|
|
$httpBackend.when('POST', 'TicketServiceTypes').respond({
|
|
|
|
id: 4001,
|
|
|
|
name: 'Totally new stuff'
|
|
|
|
});
|
|
|
|
controller.onNewServiceTypeAccept(service);
|
2019-05-16 12:07:16 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
2020-03-30 15:30:03 +00:00
|
|
|
expect(service.ticketServiceTypeFk).toEqual(4001);
|
2019-05-16 12:07:16 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|