diff --git a/front/core/mocks/crud-model.js b/front/core/mocks/crud-model.js index d2e4c74ce..e86f9d63e 100644 --- a/front/core/mocks/crud-model.js +++ b/front/core/mocks/crud-model.js @@ -4,19 +4,25 @@ module.exports = { order: {}, insert: () => { - return new Promise(accept => { - accept(); - }); + return { + then: callback => { + callback({data: {id: 1234}}); + } + }; }, remove: () => { - return new Promise(accept => { - accept(); - }); + return { + then: callback => { + callback({data: {id: 1234}}); + } + }; }, save: () => { - return new Promise(accept => { - accept(); - }); + return { + then: callback => { + callback({data: {id: 1234}}); + } + }; }, refresh: () => {}, addFilter: () => {}, diff --git a/modules/claim/front/basic-data/index.html b/modules/claim/front/basic-data/index.html index cbd610911..2887e5734 100644 --- a/modules/claim/front/basic-data/index.html +++ b/modules/claim/front/basic-data/index.html @@ -5,7 +5,7 @@ url="/api/Claims/{{$ctrl.$stateParams.id}}/updateClaim" save="post"> -
+ { + this.$state.go('claim.card.detail'); + }); + } } } -Controller.$inject = ['$stateParams']; +Controller.$inject = ['$scope', '$state', 'aclService']; ngModule.component('vnClaimBasicData', { template: require('./index.html'), diff --git a/modules/claim/front/basic-data/index.spec.js b/modules/claim/front/basic-data/index.spec.js new file mode 100644 index 000000000..187fca275 --- /dev/null +++ b/modules/claim/front/basic-data/index.spec.js @@ -0,0 +1,27 @@ +import './index.js'; +import watcher from 'core/mocks/watcher'; + +describe('Claim', () => { + describe('Component vnClaimBasicData', () => { + let controller; + let $scope; + + beforeEach(ngModule('claim')); + + beforeEach(angular.mock.inject(($componentController, $rootScope) => { + $scope = $rootScope.$new(); + $scope.watcher = watcher; + let aclService = {hasAny: () => true}; + controller = $componentController('vnClaimBasicData', {$scope, aclService}); + })); + + describe('onSubmit()', () => { + it(`should redirect to 'claim.card.detail' state`, () => { + spyOn(controller.$state, 'go'); + controller.onSubmit(); + + expect(controller.$state.go).toHaveBeenCalledWith('claim.card.detail'); + }); + }); + }); +}); diff --git a/modules/claim/front/detail/index.js b/modules/claim/front/detail/index.js index 2e8c8ef3c..aeca8946e 100644 --- a/modules/claim/front/detail/index.js +++ b/modules/claim/front/detail/index.js @@ -2,12 +2,13 @@ import ngModule from '../module'; import './style.scss'; class Controller { - constructor($state, $scope, $http, $translate, vnApp) { + constructor($state, $scope, $http, $translate, vnApp, aclService) { this.$state = $state; - this.$ = $scope; + this.$scope = $scope; this.$http = $http; this.$translate = $translate; this.vnApp = vnApp; + this.aclService = aclService; this.filter = { where: {claimFk: $state.params.id}, include: [ @@ -37,7 +38,7 @@ class Controller { openAddSalesDialog() { this.getClaimableFromTicket(); - this.$.addSales.show(); + this.$scope.addSales.show(); } getClaimableFromTicket() { @@ -54,9 +55,12 @@ class Controller { let saleToAdd = {saleFk: sale.saleFk, claimFk: this.claim.id, quantity: sale.quantity}; let query = `claim/api/ClaimBeginnings/`; this.$http.post(query, saleToAdd).then(() => { - this.$.addSales.hide(); - this.$.model.refresh(); + this.$scope.addSales.hide(); + this.$scope.model.refresh(); this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + + if (this.aclService.hasAny(['salesAssistant'])) + this.$state.go('claim.card.development'); }); } @@ -65,7 +69,7 @@ class Controller { let query = `claim/api/ClaimBeginnings/${sale.id}`; this.$http.delete(query).then(() => { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); - this.$.model.remove(index); + this.$scope.model.remove(index); this.calculateTotals(); }); } @@ -108,13 +112,13 @@ class Controller { tooltip: 'Item diary' } }; - this.$.descriptor.itemFk = itemFk; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); + this.$scope.descriptor.itemFk = itemFk; + this.$scope.descriptor.parent = event.target; + this.$scope.descriptor.show(); } } -Controller.$inject = ['$state', '$scope', '$http', '$translate', 'vnApp']; +Controller.$inject = ['$state', '$scope', '$http', '$translate', 'vnApp', 'aclService']; ngModule.component('vnClaimDetail', { template: require('./index.html'), diff --git a/modules/claim/front/detail/index.spec.js b/modules/claim/front/detail/index.spec.js index 312050619..da0735528 100644 --- a/modules/claim/front/detail/index.spec.js +++ b/modules/claim/front/detail/index.spec.js @@ -5,20 +5,22 @@ describe('claim', () => { describe('Component vnClaimDetail', () => { let controller; let $httpBackend; + let $state; + let aclService; beforeEach(ngModule('claim')); - beforeEach(angular.mock.inject(($componentController, $state, _$httpBackend_) => { + beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => { $httpBackend = _$httpBackend_; $httpBackend.when('GET', 'claim/api/Claims/ClaimBeginnings').respond({}); - $state.params.id = 1; - - controller = $componentController('vnClaimDetail', {$state}); + $state = _$state_; + aclService = {hasAny: () => true}; + controller = $componentController('vnClaimDetail', {$state, aclService}); controller.salesToClaim = [{saleFk: 1}, {saleFk: 2}]; controller.salesClaimed = [{id: 1, sale: {}}]; controller.claim = {ticketFk: 1}; - controller.$.model = crudModel; - controller.$.addSales = { + controller.$scope.model = crudModel; + controller.$scope.addSales = { hide: () => {}, show: () => {} }; @@ -28,11 +30,11 @@ describe('claim', () => { it('should call getClaimableFromTicket and $.addSales.show', () => { controller.$ = {addSales: {show: () => {}}}; spyOn(controller, 'getClaimableFromTicket'); - spyOn(controller.$.addSales, 'show'); + spyOn(controller.$scope.addSales, 'show'); controller.openAddSalesDialog(); expect(controller.getClaimableFromTicket).toHaveBeenCalledWith(); - expect(controller.$.addSales.show).toHaveBeenCalledWith(); + expect(controller.$scope.addSales.show).toHaveBeenCalledWith(); }); }); @@ -48,23 +50,25 @@ describe('claim', () => { describe('addClaimedSale(index)', () => { it('should make a post and call refresh, hide and showSuccess', () => { - spyOn(controller.$.addSales, 'hide'); + spyOn(controller.$scope.addSales, 'hide'); + spyOn(controller.$state, 'go'); $httpBackend.expectPOST(`claim/api/ClaimBeginnings/`).respond({}); controller.addClaimedSale(1); $httpBackend.flush(); - expect(controller.$.addSales.hide).toHaveBeenCalledWith(); + expect(controller.$scope.addSales.hide).toHaveBeenCalledWith(); + expect(controller.$state.go).toHaveBeenCalledWith('claim.card.development'); }); }); describe('deleteClaimedSale(index)', () => { it('should make a delete and call refresh and showSuccess', () => { - spyOn(controller.$.model, 'remove'); + spyOn(controller.$scope.model, 'remove'); $httpBackend.expectDELETE(`claim/api/ClaimBeginnings/1`).respond({}); controller.deleteClaimedSale(0); $httpBackend.flush(); - expect(controller.$.model.remove).toHaveBeenCalledWith(0); + expect(controller.$scope.model.remove).toHaveBeenCalledWith(0); }); }); diff --git a/modules/claim/front/development/index.js b/modules/claim/front/development/index.js index 0ddb3f761..d6220fbca 100644 --- a/modules/claim/front/development/index.js +++ b/modules/claim/front/development/index.js @@ -2,21 +2,25 @@ import ngModule from '../module'; import './style.scss'; class Controller { - constructor($state, $scope) { + constructor($state, $scope, aclService) { this.$state = $state; - this.$ = $scope; + this.$scope = $scope; + this.aclService = aclService; } onSubmit() { - this.$.watcher.check(); - this.$.model.save().then(() => { - this.$.watcher.notifySaved(); - this.$.model.refresh(); + this.$scope.watcher.check(); + this.$scope.model.save().then(() => { + this.$scope.watcher.notifySaved(); + this.$scope.watcher.updateOriginalData(); + + if (this.aclService.hasAny(['salesAssistant'])) + this.$state.go('claim.card.action'); }); } } -Controller.$inject = ['$state', '$scope']; +Controller.$inject = ['$state', '$scope', 'aclService']; ngModule.component('vnClaimDevelopment', { template: require('./index.html'), diff --git a/modules/claim/front/development/index.spec.js b/modules/claim/front/development/index.spec.js new file mode 100644 index 000000000..007a977c3 --- /dev/null +++ b/modules/claim/front/development/index.spec.js @@ -0,0 +1,30 @@ +import './index.js'; +import watcher from 'core/mocks/watcher'; +import crudModel from 'core/mocks/crud-model'; + +describe('Claim', () => { + describe('Component vnClaimDevelopment', () => { + let controller; + let $scope; + let aclService; + + beforeEach(ngModule('claim')); + + beforeEach(angular.mock.inject(($componentController, $rootScope) => { + $scope = $rootScope.$new(); + $scope.watcher = watcher; + $scope.model = crudModel; + aclService = {hasAny: () => true}; + controller = $componentController('vnClaimDevelopment', {$scope, aclService}); + })); + + describe('onSubmit()', () => { + it(`should redirect to 'claim.card.action' state`, () => { + spyOn(controller.$state, 'go'); + controller.onSubmit(); + + expect(controller.$state.go).toHaveBeenCalledWith('claim.card.action'); + }); + }); + }); +});