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(`
`); 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); }); }); 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]); }); }); });