import './index'; describe('ticket', () => { describe('Component vnTicketVolume', () => { let controller; let $httpBackend; let $state; let $scope; beforeEach(ngModule('ticket')); beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, $rootScope) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); $scope.model = {data: [{id: 1}, {id: 2}], accept: () => { return { then: () => {} }; }}; $state = _$state_; $state.params.id = 101; controller = $componentController('vnTicketVolume', {$scope, $httpBackend, $state}); })); describe('sales() setter', () => { it('should set sales property on controller an then call applyVolumes() method', () => { jest.spyOn(controller, 'applyVolumes'); controller.sales = [{id: 1}]; expect(controller.applyVolumes).toHaveBeenCalledWith(); }); }); describe('volumes() setter', () => { it('should set volumes property on controller an then call applyVolumes() method', () => { jest.spyOn(controller, 'applyVolumes'); controller.volumes = [{id: 1}]; expect(controller.applyVolumes).toHaveBeenCalledWith(); }); }); describe('applyVolumes()', () => { it(`should not apply volumes to the sales if sales property is not defined on controller`, () => { controller.sales = [{id: 1, name: 'Sale one'}, {id: 2, name: 'Sale two'}]; expect(controller.sales[0].volume).toBeUndefined(); expect(controller.sales[1].volume).toBeUndefined(); }); it(`should not apply volumes to the sales if sales property is not defined on controller`, () => { controller.volumes = [{saleFk: 1, m3: 0.012}, {saleFk: 2, m3: 0.015}]; expect(controller.sales).toBeUndefined(); }); it(`should apply volumes to the sales if sales and volumes properties are defined on controller`, () => { controller.sales = [{id: 1, name: 'Sale one'}, {id: 2, name: 'Sale two'}]; controller.volumes = [{saleFk: 1, m3: 0.012}, {saleFk: 2, m3: 0.015}]; expect(controller.sales[0].volume.m3).toEqual(0.012); expect(controller.sales[1].volume.m3).toEqual(0.015); }); }); /* it('should join the sale volumes to its respective sale', () => { controller.ticket = {id: 1}; let response = {volumes: [{saleFk: 1, m3: 0.008}, {saleFk: 2, m3: 0.003}]}; $httpBackend.whenGET(`tickets/1/getVolume`).respond(response); $httpBackend.expectGET(`tickets/1/getVolume`); controller.onDataChange(); $httpBackend.flush(); expect($scope.model.data[0].volume.m3).toBe(0.008); expect($scope.model.data[1].volume.m3).toBe(0.003); }); */ }); });