import './index'; describe('Supplier Component vnNewBankEntity', () => { let controller; let $httpBackend; let $scope; let $element; let vnApp; beforeEach(ngModule('supplier')); beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _vnApp_) => { $httpBackend = _$httpBackend_; vnApp = _vnApp_; jest.spyOn(vnApp, 'showError'); $scope = $rootScope.$new(); $element = angular.element(''); controller = $componentController('vnNewBankEntity', {$element, $scope}); })); describe('resetLocation()', () => { it('should reset the location in the controller', () => { expect(controller.location).toBeUndefined(); controller.resetLocation(); expect(controller.location).toEqual({}); }); }); describe('onAccept()', () => { it('should throw an error if there is no country id in the location', () => { jest.spyOn(controller.vnApp, 'showMessage'); controller.location = {}; controller.onAccept(); expect(controller.vnApp.showError).toHaveBeenCalledWith(`The country can't be empty`); }); it('should do add the new bank entity', () => { controller.location = { countryFk: 1 }; $httpBackend.expectPOST('Bankentities', controller.location).respond(200, controller.location); controller.onAccept(); $httpBackend.flush(); }); }); });