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', () => {
|
2023-08-01 10:33:56 +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,
|
2023-08-01 10:33:56 +00:00
|
|
|
quantity: 10,
|
2020-03-30 15:30:03 +00:00
|
|
|
};
|
|
|
|
$scope.newServiceType = {
|
2023-08-01 10:33:56 +00:00
|
|
|
name: 'Totally new stuff',
|
2020-03-30 15:30:03 +00:00
|
|
|
};
|
2019-05-16 12:07:16 +00:00
|
|
|
|
2020-03-30 15:30:03 +00:00
|
|
|
$httpBackend.when('POST', 'TicketServiceTypes').respond({
|
|
|
|
id: 4001,
|
2023-08-01 10:33:56 +00:00
|
|
|
name: 'Totally new stuff',
|
2020-03-30 15:30:03 +00:00
|
|
|
});
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|
2023-08-01 10:33:56 +00:00
|
|
|
|
|
|
|
describe('addChecked', () => {
|
|
|
|
it('should add an item to the checkeds array', () => {
|
|
|
|
controller.checkeds = [];
|
|
|
|
controller.addChecked(1);
|
|
|
|
|
|
|
|
expect(controller.checkeds).toEqual([1]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove an item if it is already in the checkeds array', () => {
|
|
|
|
controller.checkeds = [1, 2, 3];
|
|
|
|
controller.addChecked(2);
|
|
|
|
|
|
|
|
expect(controller.checkeds).toEqual([1, 3]);
|
|
|
|
});
|
|
|
|
});
|
2019-05-16 12:07:16 +00:00
|
|
|
});
|