From 2fe4fad28a982c6a25c9641e5695c234fb0b69f3 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 8 Sep 2021 09:44:46 +0200 Subject: [PATCH] test front ok --- modules/invoiceIn/front/tax/index.spec.js | 4 +- modules/supplier/front/account/index.js | 10 +--- modules/supplier/front/account/index.spec.js | 62 +++++++++++++++++++- 3 files changed, 63 insertions(+), 13 deletions(-) diff --git a/modules/invoiceIn/front/tax/index.spec.js b/modules/invoiceIn/front/tax/index.spec.js index f4064530a..20d5d40d8 100644 --- a/modules/invoiceIn/front/tax/index.spec.js +++ b/modules/invoiceIn/front/tax/index.spec.js @@ -10,13 +10,13 @@ describe('InvoiceIn', () => { beforeEach(ngModule('invoiceIn')); - beforeEach(inject(($componentController, _$httpBackend_, $rootScope, _vnApp_) => { + beforeEach(inject(($componentController, $rootScope, _vnApp_) => { vnApp = _vnApp_; jest.spyOn(vnApp, 'showError'); $scope = $rootScope.$new(); $scope.model = crudModel; - $scope.watcher = watcher; + const $element = angular.element(''); controller = $componentController('vnInvoiceInTax', {$element, $scope}); controller.invoiceIn = {id: 1}; diff --git a/modules/supplier/front/account/index.js b/modules/supplier/front/account/index.js index aa7b40727..1b1871f9b 100644 --- a/modules/supplier/front/account/index.js +++ b/modules/supplier/front/account/index.js @@ -39,13 +39,7 @@ class Controller extends Section { this.$.bankEntity.open(); } - onBankEntityAccept() { - const query = `SupplierAccounts/${this.$params.id}/createBankEntity`; - return this.$http.patch(query, this.newBankEntity) - .then(res => this.supplierAccount.bankEntityFk = res.data.id); - } - - onAddSave() { + setWireTransfer() { const values = { id: this.$params.id, payMethodFk: this.wireTransferFk @@ -57,7 +51,7 @@ class Controller extends Section { onSubmit() { this.$.watcher.check(); - this.$.model.save() + return this.$.model.save() .then(() => { this.$.watcher.notifySaved(); this.$.watcher.updateOriginalData(); diff --git a/modules/supplier/front/account/index.spec.js b/modules/supplier/front/account/index.spec.js index fad53b629..6491da7d0 100644 --- a/modules/supplier/front/account/index.spec.js +++ b/modules/supplier/front/account/index.spec.js @@ -1,23 +1,32 @@ import './index.js'; +import watcher from 'core/mocks/watcher'; +import crudModel from 'core/mocks/crud-model'; describe('Supplier Component vnSupplierAccount', () => { let $scope; - let $element; let controller; let $httpBackend; let $httpParamSerializer; + let vnApp; + beforeEach(ngModule('supplier')); - beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { + beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_, _vnApp_) => { + vnApp = _vnApp_; $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; + jest.spyOn(vnApp, 'showError'); $scope = $rootScope.$new(); + $scope.model = crudModel; + $scope.watcher = watcher; + $scope.bankEntity = { open: () => {} }; $httpBackend.whenRoute('GET', 'PayMethods') .respond([{id: 1}]); - $element = angular.element(''); + + const $element = angular.element(''); controller = $componentController('vnSupplierAccount', {$element, $scope}); controller.supplierAccount = { supplierFk: 442, @@ -79,5 +88,52 @@ describe('Supplier Component vnSupplierAccount', () => { expect(controller.supplierAccount.bankEntityFk).toEqual(controller.bankEntity.id); }); }); + + describe('onSubmit__()', () => { + it(`should reload the card`, () => { + controller.card = {reload: () => {}}; + jest.spyOn($scope.watcher, 'check'); + jest.spyOn($scope.watcher, 'notifySaved'); + jest.spyOn($scope.watcher, 'updateOriginalData'); + jest.spyOn(controller.card, 'reload'); + jest.spyOn($scope.model, 'save'); + console.log($scope.model); + controller.onSubmit(); + + expect($scope.model.save).toHaveBeenCalledWith(); + expect($scope.watcher.updateOriginalData).toHaveBeenCalledWith(); + expect($scope.watcher.check).toHaveBeenCalledWith(); + expect($scope.watcher.notifySaved).toHaveBeenCalledWith(); + expect(controller.card.reload).toHaveBeenCalledWith(); + + expect(controller.$.payMethodToTransfer.show).toHaveBeenCalled(); + }); + }); + + fdescribe('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); + }); + }); });