salix/modules/ticket/front/services/index.spec.js

69 lines
2.1 KiB
JavaScript
Raw Normal View History

import './index.js';
2021-01-18 08:08:50 +00:00
import crudModel from 'core/mocks/crud-model';
2019-10-18 19:36:30 +00:00
describe('Ticket component vnTicketService', () => {
let controller;
let $httpBackend;
let $scope;
let $element;
beforeEach(ngModule('ticket'));
2020-07-23 14:46:16 +00:00
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
$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>`);
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'
});
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 = {};
let error;
try {
2020-03-30 15:30:03 +00:00
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', () => {
2020-03-30 15:30:03 +00:00
const service = {
id: 1,
quantity: 10
};
$scope.newServiceType = {
name: 'Totally new stuff'
};
2020-03-30 15:30:03 +00:00
$httpBackend.when('POST', 'TicketServiceTypes').respond({
id: 4001,
name: 'Totally new stuff'
});
controller.onNewServiceTypeAccept(service);
$httpBackend.flush();
2020-03-30 15:30:03 +00:00
expect(service.ticketServiceTypeFk).toEqual(4001);
});
});
});