import './index.js'; describe('Order', () => { describe('Component vnOrderBasicData', () => { let $httpBackend; let $httpParamSerializer; let controller; let $scope; beforeEach(ngModule('order')); beforeEach(inject(($compile, _$httpBackend_, $rootScope, _$httpParamSerializer_) => { $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; $scope = $rootScope.$new(); $httpBackend.whenRoute('GET', 'Addresses') .respond([{id: 2, nickname: 'address 2'}]); $httpBackend.whenRoute('GET', 'Clients') .respond([{id: 1, defaultAddressFk: 1}]); $scope.order = {clientFk: 1, addressFk: 1}; let $element = $compile('')($scope); $httpBackend.flush(); controller = $element.controller('vnOrderBasicData'); })); afterAll(() => { $scope.$destroy(); $element.remove(); }); describe('constructor()', () => { it('should update the address after the client changes', async() => { const addressId = 999; const id = 444; controller.selection = {id: id, defaultAddressFk: addressId}; $scope.$digest(); expect(controller.order.addressFk).toEqual(addressId); }); }); describe('getAvailableAgencies()', () => { it('should set agencyModeFk to null and get the available agencies if the order has landed and client', async() => { controller.order.agencyModeFk = 999; controller.order.addressFk = 999; controller.order.landed = new Date(); const expectedAgencies = [{id: 1}, {id: 2}]; const paramsObj = { addressFk: controller.order.addressFk, landed: controller.order.landed }; const serializedParams = $httpParamSerializer(paramsObj); $httpBackend.expect('GET', `Agencies/landsThatDay?${serializedParams}`).respond(expectedAgencies); controller.getAvailableAgencies(); $httpBackend.flush(); expect(controller.order.agencyModeFk).toBeDefined(); expect(controller._availableAgencies).toEqual(expectedAgencies); }); }); }); });