import './index.js'; import watcher from 'core/mocks/watcher'; import crudModel from 'core/mocks/crud-model'; describe('Supplier Component vnSupplierAccount', () => { let $scope; let controller; beforeEach(ngModule('supplier')); beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => { $scope = $rootScope.$new(); $scope.model = crudModel; $scope.watcher = watcher; $scope.bankEntity = { open: () => {} }; const $element = angular.element(''); controller = $componentController('vnSupplierAccount', {$element, $scope}); controller.supplierAccount = { supplierFk: 442, name: 'Verdnatura' }; })); describe('onAccept()', () => { it('should set the created bank entity id into the target account', () => { controller.supplierAccounts = [{}, {}, {}]; const data = { id: 999, index: 1 }; controller.onAccept(data); const targetAccount = controller.supplierAccounts[data.index]; expect(targetAccount.bankEntityFk).toEqual(data.id); }); }); describe('onSubmit()', () => { it(`should reload the card`, done => { controller.card = {reload: () => {}}; controller.$.payMethodToTransfer = {show: () => {}}; jest.spyOn(controller.$.payMethodToTransfer, 'show'); jest.spyOn(controller.$.model, 'save').mockReturnValue(new Promise(resolve => { return resolve({ id: 1234 }); })); jest.spyOn(controller.card, 'reload').mockReturnValue(new Promise(resolve => { return resolve({ id: 1234 }); })); controller.wireTransferFk = 'a'; controller.supplier = {payMethodFk: 'b'}; controller.onSubmit().then(() => { expect(controller.card.reload).toHaveBeenCalledWith(); expect(controller.$.payMethodToTransfer.show).toHaveBeenCalled(); done(); }).catch(done.fail); }); }); });