diff --git a/package.json b/package.json index 45752c0..fbff799 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ }, "devDependencies": { "angular": "^1.7.5", - "angular-mocks": "^1.7.7", + "angular-mocks": "^1.7.8", "angular-route": "^1.7.7", "bootstrap": "^4.1.3", "foca-modal": "git+http://git.focasoftware.com/npm/foca-modal.git", diff --git a/spec/controllerSpec.js b/spec/controllerSpec.js index ba240c6..c6f3475 100644 --- a/spec/controllerSpec.js +++ b/spec/controllerSpec.js @@ -29,6 +29,7 @@ describe('Controladores abm vehículo', function() { showGuardar: function() { return; }, addCustomButton: function() { return; } }, + $localStorage: {}, $timeout: {} }); @@ -38,7 +39,9 @@ describe('Controladores abm vehículo', function() { it('Crea fecha nueva', function() { //arrange - var scope = {}; + var scope = { + $watch: function() {} + }; var controller = $controller('focaAbmVehiculosController', { $scope: scope, focaAbmVehiculoService: { @@ -55,6 +58,7 @@ describe('Controladores abm vehículo', function() { showGuardar: function() { return; }, addCustomButton: function() { return; } }, + $localStorage: {}, $timeout: {} }); @@ -67,7 +71,9 @@ describe('Controladores abm vehículo', function() { it('$scope setea botonera lateral', function() { //arrange - var scope = {}; + var scope = { + $watch: function() {} + }; var controller = $controller('focaAbmVehiculosController', { $scope: scope, focaAbmVehiculoService: { @@ -84,7 +90,8 @@ describe('Controladores abm vehículo', function() { showGuardar: function() { return; }, addCustomButton: function() { return; } }, - $timeout: {} + $timeout: {}, + $localStorage: {} }); //act @@ -97,7 +104,9 @@ describe('Controladores abm vehículo', function() { it('$scope.editar lleva a la ruta correcta', function() { inject(function($location) { //arrange - var scope = {}; + var scope = { + $watch: function() {} + }; var controller = $controller('focaAbmVehiculosController', { $scope: scope, focaAbmVehiculoService: { @@ -114,7 +123,8 @@ describe('Controladores abm vehículo', function() { showGuardar: function() { return; }, addCustomButton: function() { return; } }, - $timeout: {} + $timeout: {}, + $localStorage: {} }); //act @@ -128,7 +138,9 @@ describe('Controladores abm vehículo', function() { it('Solicita confirmacion', function() { //arrange - var scope = {}; + var scope = { + $watch: function() {} + }; var focaModalService = { confirm: function() {} }; @@ -148,7 +160,8 @@ describe('Controladores abm vehículo', function() { showGuardar: function() { return; }, addCustomButton: function() { return; } }, - $timeout: {} + $timeout: {}, + $localStorage: {} }); //act @@ -186,7 +199,8 @@ describe('Controladores abm vehículo', function() { showGuardar: function() { return; }, addCustomButton: function() { return; } }, - $timeout: {} + $timeout: {}, + $localStorage: {} }); var promesa = Promise.resolve(true); @@ -206,7 +220,9 @@ describe('Controladores abm vehículo', function() { it('Se selecciona transportista', function() { //arrange - var scope = {}; + var scope = { + $watch: function() {} + }; var focaModalService = { modal: function() {} }; @@ -226,7 +242,8 @@ describe('Controladores abm vehículo', function() { showGuardar: function() { return; }, addCustomButton: function() { return; } }, - $timeout: {} + $timeout: {}, + $localStorage: {} }); //act @@ -241,7 +258,9 @@ describe('Controladores abm vehículo', function() { inject(function($timeout) { //arrange - var scope = {}; + var scope = { + $watch: function() {} + }; var focaModalService = { modal: function() { return; } }; @@ -268,6 +287,7 @@ describe('Controladores abm vehículo', function() { showGuardar: function() { return; }, addCustomButton: function() { return; } }, + $localStorage: {}, $timeout: $timeout }); var promesa = Promise.resolve({COD: '', NOM: ''}); @@ -301,7 +321,9 @@ describe('Controladores abm vehículo', function() { //arrange var controller = $controller('focaAbmVehiculoController', { - $scope: {}, + $scope: { + $watch: function() {} + }, focaAbmVehiculoService: { getVehiculo: function() { return { @@ -321,6 +343,7 @@ describe('Controladores abm vehículo', function() { showGuardar: function() { return; }, addCustomButton: function() { return; } }, + $localStorage: {}, $window: {} }); @@ -332,7 +355,9 @@ describe('Controladores abm vehículo', function() { it('Se busca el transportista cuando es nuevo', function() { //arrange - var scope = {}; + var scope = { + $watch: function() {} + }; var focaAbmVehiculoService = { getVehiculo: function() { return { @@ -363,6 +388,7 @@ describe('Controladores abm vehículo', function() { showGuardar: function() { return; }, addCustomButton: function() { return; } }, + $localStorage: {}, $window: {} }); @@ -373,7 +399,9 @@ describe('Controladores abm vehículo', function() { it('No se busca el transportista cuando es nuevo', function() { //arrange - var scope = {}; + var scope = { + $watch: function() {} + }; var focaAbmVehiculoService = { getVehiculo: function() { return { @@ -402,6 +430,7 @@ describe('Controladores abm vehículo', function() { showGuardar: function() { return; }, addCustomButton: function() { return; } }, + $localStorage: {}, $window: {} }); @@ -413,7 +442,13 @@ describe('Controladores abm vehículo', function() { inject(function($location) { //arrange - var scope = {}; + var scope = { + $watch: function() {}, + cancelar: function() {}, + formVehiculo: { + $pristine: true + } + }; var controller = $controller('focaAbmVehiculoController', { $scope: scope, focaAbmVehiculoService: { @@ -435,11 +470,13 @@ describe('Controladores abm vehículo', function() { showGuardar: function() { return; }, addCustomButton: function() { return; } }, - $window: {} + $localStorage: {}, + $window: {}, + }); //act - scope.cancelar(); + scope.salir(); //assert expect($location.url()).toEqual('/vehiculo'); @@ -450,7 +487,9 @@ describe('Controladores abm vehículo', function() { inject(function($location) { //arrange - var scope = {}; + var scope = { + $watch: function() {} + }; var controller = $controller('focaAbmVehiculoController', { $scope: scope, focaAbmVehiculoService: { @@ -474,6 +513,7 @@ describe('Controladores abm vehículo', function() { showGuardar: function() { return; }, addCustomButton: function() { return; } }, + $localStorage: {}, $window: {} }); @@ -490,7 +530,9 @@ describe('Controladores abm vehículo', function() { inject(function($location) { //arrange - var scope = {}; + var scope = { + $watch: function() {} + }; var controller = $controller('focaAbmVehiculoController', { $scope: scope, focaAbmVehiculoService: { @@ -514,6 +556,7 @@ describe('Controladores abm vehículo', function() { showGuardar: function() { return; }, addCustomButton: function() { return; } }, + $localStorage: {}, $window: {} }); @@ -532,7 +575,9 @@ describe('Controladores abm vehículo', function() { var focaModalService = { confirm: function() {} }; - var scope = {}; + var scope = { + $watch: function() {} + }; var controller = $controller('focaAbmVehiculoController', { $scope: scope, focaAbmVehiculoService: { @@ -556,6 +601,7 @@ describe('Controladores abm vehículo', function() { showGuardar: function() { return; }, addCustomButton: function() { return; } }, + $localStorage: {}, $window: {} }); @@ -570,7 +616,9 @@ describe('Controladores abm vehículo', function() { it('Elimina y obtiene cisternas al dar confirmar', function(done) { //arrange - var scope = {}; + var scope = { + $watch: function() {} + }; var focaModalService = { confirm: function() {} }; @@ -598,6 +646,7 @@ describe('Controladores abm vehículo', function() { showGuardar: function() { return; }, addCustomButton: function() { return; } }, + $localStorage: {}, $window: {} }); var promesa = Promise.resolve(true); diff --git a/src/js/controller.js b/src/js/controller.js index 804fadd..8756337 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -107,7 +107,7 @@ angular.module('focaAbmVehiculo') focaBotoneraLateralService.showPausar(true); focaBotoneraLateralService.showCancelar(false); focaBotoneraLateralService.showGuardar(true, $scope.guardar); - focaBotoneraLateralService.addCustomButton('Salir', salir); + focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); }); $timeout(function() {getLSVehiculo();}); @@ -153,7 +153,7 @@ angular.module('focaAbmVehiculo') if (key === 13) $scope.focused++; }; - function salir() { + $scope.salir = function() { if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { focaModalService.confirm( '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' @@ -182,7 +182,7 @@ angular.module('focaAbmVehiculo') if (key === 13) { if ($scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { - salir(); + $scope.salir(); return; }