From e90468fd7f94ffcc1c0e6be93c6380cb8f1f9b18 Mon Sep 17 00:00:00 2001 From: efernandez Date: Mon, 11 Feb 2019 15:18:48 -0300 Subject: [PATCH] archivos testing --- spec/controllerSpec.js | 412 +++++++++++++++++++++++++++++++++++++++++++++++++ spec/routeSpec.js | 27 ++++ spec/serviceSpec.js | 157 +++++++++++++++++++ test.html | 21 +++ 4 files changed, 617 insertions(+) create mode 100644 spec/controllerSpec.js create mode 100644 spec/routeSpec.js create mode 100644 spec/serviceSpec.js create mode 100644 test.html diff --git a/spec/controllerSpec.js b/spec/controllerSpec.js new file mode 100644 index 0000000..ed0a311 --- /dev/null +++ b/spec/controllerSpec.js @@ -0,0 +1,412 @@ +describe('Controladores abm precios condiciones', function() { + + var $controller; + var timeout; + + beforeEach(function() { + module('focaAbmPreciosCondiciones'); + inject(function(_$controller_) { + $controller = _$controller_; + }); + }); + + beforeEach(function() { + inject(function($timeout) { + timeout = $timeout; + }); + }); + + describe('Controlador focaAbmPreciosCondiciones', function() { + + it('Existe el controlador', function() { + //act + var controlador = $controller('focaAbmPreciosCondicionesController', { + $scope: {}, + focaAbmPreciosCondicionesService: {}, + $location: {}, + focaModalService: {}, + focaBotoneraLateralService: {}, + $timeout: timeout + }); + + //assert + expect(typeof controlador).toEqual('object'); + }); + + it('$scope.editar lleva a la ruta correcta', function() { + inject(function($location) { + //arrange + var scope = {}; + var paramFake = 1; + $controller('focaAbmPreciosCondicionesController', { + $scope: scope, + focaAbmPreciosCondicionesService: {}, + $location: $location, + focaModalService: {}, + focaBotoneraLateralService: {}, + $timeout: timeout + }); + + + //act + scope.editar(paramFake); + + //assert + expect($location.url()).toEqual('/precio-condicion/' + paramFake); + }); + }); + + it('$scope.solicitarConfirmacion levanta modal confirm', function() { + //arrange + var scope = {}; + var paramFake = 1; + var focaModalService = { + confirm: function() { } + }; + $controller('focaAbmPreciosCondicionesController', { + $scope: scope, + focaAbmPreciosCondicionesService: {}, + $location: {}, + focaModalService: focaModalService, + focaBotoneraLateralService: {}, + $timeout: timeout + }); + + //act + spyOn(focaModalService, 'confirm').and.returnValue({ then: function() { }}); + scope.solicitarConfirmacion(paramFake); + + //assert + expect(focaModalService.confirm).toHaveBeenCalled(); + }); + + it('$scope.solicitarConfirmacion elimina al confirmar ok', function(done) { + //arrange + var scope = {}; + var paramFake = 1; + var focaModalService = { + confirm: function() { } + }; + var focaAbmPreciosCondicionesService = { + borrarPrecioCondicion: function() { } + }; + $controller('focaAbmPreciosCondicionesController', { + $scope: scope, + focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, + $location: {}, + focaModalService: focaModalService, + focaBotoneraLateralService: {}, + $timeout: timeout + }); + var promesaConfirm = Promise.resolve(true); + scope.preciosCondiciones = []; + + //act + spyOn(focaModalService, 'confirm').and.returnValue(promesaConfirm); + spyOn(focaAbmPreciosCondicionesService, 'borrarPrecioCondicion'); + scope.solicitarConfirmacion(paramFake); + + //assert + promesaConfirm.then(function() { + expect(focaAbmPreciosCondicionesService.borrarPrecioCondicion).toHaveBeenCalled(); + done(); + }); + }); + + it('$scope.buscar llama a obtenerPreciosCondiciones', function() { + //arrange + var scope = {}; + var focaAbmPreciosCondicionesService = { + obtenerPreciosCondiciones: function() { } + }; + $controller('focaAbmPreciosCondicionesController', { + $scope: scope, + focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, + $location: {}, + focaModalService: {}, + focaBotoneraLateralService: {}, + $timeout: timeout + }); + + //act + spyOn(focaAbmPreciosCondicionesService, 'obtenerPreciosCondiciones') + .and.returnValue({ then: function() { }}); + scope.buscar(13); + + //assert + expect(focaAbmPreciosCondicionesService.obtenerPreciosCondiciones).toHaveBeenCalled(); + }); + }); + + describe('Controlador focaAbmPrecioCondicionController', function() { + + it('Existe el controlador focaAbmPrecioCondicionController', function() { + //act + var controlador = $controller('focaAbmPrecioCondicionController', { + $scope: {}, + focaAbmPreciosCondicionesService: { + obtenerPrecioCondicion: function() { + return { + then: function() { } + }; + } + }, + focaBotoneraLateralService: {}, + $routeParams: {}, + $location: {}, + focaModalService: {}, + $timeout: timeout, + $uibModal: {}, + $window: {} + }); + + //assert + expect(typeof controlador).toEqual('object'); + }); + + it('La funcion $scope.cancelar lleva a la ruta correcta', function() { + inject(function($location) { + //arrange + var scope = {}; + $controller('focaAbmPrecioCondicionController', { + $scope: scope, + focaAbmPreciosCondicionesService: { + obtenerPrecioCondicion: function() { + return { + then: function() { } + }; + } + }, + focaBotoneraLateralService: {}, + $routeParams: {}, + $location: $location, + focaModalService: {}, + $timeout: timeout, + $uibModal: {}, + $window: {} + }); + + //act + scope.cancelar(); + + //assert + expect($location.url()).toEqual('/precio-condicion'); + }); + }); + + it('La funcion $scope.guardar llama a servicio.guardarPrecioCondicion', function() { + inject(function($location) { + //arrange + var scope = {}; + var focaAbmPreciosCondicionesService = { + obtenerPrecioCondicion: function() { + return { + then: function() { } + }; + }, + guardarPrecioCondicion: function() { } + }; + var window = { + location: { + assign: function() { } + } + }; + $controller('focaAbmPrecioCondicionController', { + $scope: scope, + focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, + focaBotoneraLateralService: {}, + $routeParams: {}, + $location: $location, + focaModalService: {}, + $timeout: timeout, + $uibModal: {}, + $window: window + }); + var promesaGuardarPrecioCondicion = Promise.resolve(true); + scope.precioCondicion = { listaPrecio: {} }; + + //act + //spyOn(window, 'location').and.returnValue({ assign: function() {} }); + spyOn(focaAbmPreciosCondicionesService, 'guardarPrecioCondicion') + .and.returnValue(promesaGuardarPrecioCondicion); + scope.guardar(); + + //assert + expect(focaAbmPreciosCondicionesService.guardarPrecioCondicion).toHaveBeenCalled(); + }); + }); + + it('La funcion $scope.solicitarConfirmacionPlazoPago levanta modal confirm', function() { + //act + var scope = {}; + var focaModalService = { + confirm: function() { } + }; + $controller('focaAbmPrecioCondicionController', { + $scope: scope, + focaAbmPreciosCondicionesService: { + obtenerPrecioCondicion: function() { + return { + then:function() { } + }; + } + }, + focaBotoneraLateralService: {}, + $routeParams: {}, + $location: {}, + focaModalService: focaModalService, + $timeout: timeout, + $uibModal: {}, + $window: {} + }); + + //act + spyOn(focaModalService, 'confirm') + .and.returnValue({ then: function() {} }); + scope.solicitarConfirmacionPlazoPago({ data: 'test' }); + + //assert + expect(focaModalService.confirm).toHaveBeenCalled(); + }); + + it('La funcion $scope.solicitarConfirmacionPlazoPago borra al dar ok', function(done) { + //act + var scope = {}; + var focaModalService = { + confirm: function() { } + }; + var focaAbmPreciosCondicionesService = { + obtenerPrecioCondicion: function() { + return { + then:function() { } + }; + }, + borrarPlazoPago: function() { } + }; + $controller('focaAbmPrecioCondicionController', { + $scope: scope, + focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, + focaBotoneraLateralService: {}, + $routeParams: {}, + $location: {}, + focaModalService: focaModalService, + $timeout: timeout, + $uibModal: {}, + $window: {} + }); + var promesaConfirm = Promise.resolve(true); + scope.precioCondicion = { + plazos: [] + }; + + //act + spyOn(focaModalService, 'confirm').and.returnValue(promesaConfirm); + spyOn(focaAbmPreciosCondicionesService, 'borrarPlazoPago'); + scope.solicitarConfirmacionPlazoPago({ data: 'test' }); + + //assert + promesaConfirm.then(function() { + expect(focaAbmPreciosCondicionesService.borrarPlazoPago).toHaveBeenCalled(); + done(); + }); + }); + + it('La funcion $scope.seleccionarListaPrecio levanta modal', function() { + //arrange + var scope = {}; + var uibModal = { + open: function() { } + }; + var focaAbmPreciosCondicionesService = { + obtenerPrecioCondicion: function() { + return { + then:function() { } + }; + } + }; + $controller('focaAbmPrecioCondicionController', { + $scope: scope, + focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, + focaBotoneraLateralService: {}, + $routeParams: {}, + $location: {}, + focaModalService: {}, + $timeout: timeout, + $uibModal: uibModal, + $window: {} + }); + + //act + spyOn(uibModal, 'open').and.returnValue({ result: { then: function() { } } }); + scope.seleccionarListaPrecio(13); + + //assert + expect(uibModal.open).toHaveBeenCalled(); + }); + + it('La funcion $scope.verProductosListaPrecio levanta modal', function() { + //arrange + var scope = {}; + var uibModal = { + open: function() { } + }; + var focaAbmPreciosCondicionesService = { + obtenerPrecioCondicion: function() { + return { + then:function() { } + }; + } + }; + $controller('focaAbmPrecioCondicionController', { + $scope: scope, + focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, + focaBotoneraLateralService: {}, + $routeParams: {}, + $location: {}, + focaModalService: {}, + $timeout: timeout, + $uibModal: uibModal, + $window: {} + }); + scope.precioCondicion = { + listaPrecio: {} + }; + //act + spyOn(uibModal, 'open'); + scope.verProductosListaPrecio(); + + //assert + expect(uibModal.open).toHaveBeenCalled(); + }); + + it('la función next suma uno a $scope.focused', function() { + //arrange + var scope = {}; + var focaAbmPreciosCondicionesService = { + obtenerPrecioCondicion: function() { + return { + then:function() { } + }; + } + }; + $controller('focaAbmPrecioCondicionController', { + $scope: scope, + focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, + focaBotoneraLateralService: {}, + $routeParams: {}, + $location: {}, + focaModalService: {}, + $timeout: timeout, + $uibModal: {}, + $window: {} + }); + + //act + var esperado = scope.focused + 1; + scope.next(13); + + //assert + expect(scope.focused).toEqual(esperado); + }); + }); +}); diff --git a/spec/routeSpec.js b/spec/routeSpec.js new file mode 100644 index 0000000..39f2d85 --- /dev/null +++ b/spec/routeSpec.js @@ -0,0 +1,27 @@ +describe('Rutas de abm precios condiciones', function() { + + var route; + + beforeEach(function() { + module('focaAbmPreciosCondiciones'); + inject(function($route) { + route = $route; + }); + }); + + it('Ruta /precio-condicion dirije correctamente', function() { + //assert + expect(route.routes['/precio-condicion'].controller) + .toBe('focaAbmPreciosCondicionesController'); + expect(route.routes['/precio-condicion'].templateUrl) + .toBe('src/views/foca-abm-precios-condiciones-listado.html'); + }); + + it('Ruta /precio-condicion/:id dirije correctamente', function() { + //assert + expect(route.routes['/precio-condicion/:id'].controller) + .toBe('focaAbmPrecioCondicionController'); + expect(route.routes['/precio-condicion/:id'].templateUrl) + .toBe('src/views/foca-abm-precios-condiciones-item.html'); + }); +}); diff --git a/spec/serviceSpec.js b/spec/serviceSpec.js new file mode 100644 index 0000000..a71a6af --- /dev/null +++ b/spec/serviceSpec.js @@ -0,0 +1,157 @@ +describe('Servicios abm precios condiciones', function() { + + var httpBackend; + + beforeEach(function() { + module('focaAbmPreciosCondiciones'); + + inject(module(function($provide) { + $provide.value('API_ENDPOINT', { + URL: 'localhost' + }); + })); + }); + + describe('servicio focaAbmPreciosCondicionesService', function() { + + var servicio; + + beforeEach(function() { + inject(function(focaAbmPreciosCondicionesService, $httpBackend) { + servicio = focaAbmPreciosCondicionesService; + httpBackend = $httpBackend; + }); + }); + + it('existe el servicio focaAbmPreciosCondicionesService', function() { + //assert + expect(typeof servicio).toEqual('object'); + }); + + it('la función obtenerPreciosCondiciones llama ruta correcta', function() { + //arrange + var responseFake = { data: 'test'}; + var result; + var bodyFake = 1; + httpBackend.expectPOST('localhost/precios-condiciones', { nombre: bodyFake }) + .respond(responseFake); + + //act + servicio.obtenerPreciosCondiciones(bodyFake).then(function(data) { + result = data.data; + }); + httpBackend.flush(); + + //assert + expect(result).toEqual(responseFake); + }); + + it('la función obtenerPrecioCondicion llama ruta correcta', function() { + //arrange + var responseFake = { data: 'test'}; + var result; + var paramFake = 1; + httpBackend.expectGET('localhost/precio-condicion/' + paramFake) + .respond(responseFake); + + //act + servicio.obtenerPrecioCondicion(paramFake).then(function(data) { + result = data.data; + }); + httpBackend.flush(); + + //assert + expect(result).toEqual(responseFake); + }); + + it('la función guardarPrecioCondicion llama ruta correcta', function() { + //arrange + var responseFake = { data: 'test'}; + var result; + var bodyFake = 1; + httpBackend.expectPOST('localhost/precio-condicion', { precioCondicion: bodyFake }) + .respond(responseFake); + + //act + servicio.guardarPrecioCondicion(bodyFake).then(function(data) { + result = data.data; + }); + httpBackend.flush(); + + //assert + expect(result).toEqual(responseFake); + }); + + it('la función borrarPrecioCondicion llama ruta correcta', function() { + //arrange + var responseFake = { data: 'test'}; + var result; + var paramFake = 1; + httpBackend.expectDELETE('localhost/precio-condicion/' + paramFake) + .respond(responseFake); + + //act + servicio.borrarPrecioCondicion(paramFake).then(function(data) { + result = data.data; + }); + httpBackend.flush(); + + //assert + expect(result).toEqual(responseFake); + }); + + it('la función obtenerPlazoPago llama ruta correcta', function() { + //arrange + var responseFake = { data: 'test'}; + var result; + var paramFake = 1; + httpBackend.expectGET('localhost/plazo-pago/precio-condicion/' + paramFake) + .respond(responseFake); + + //act + servicio.obtenerPlazoPago(paramFake).then(function(data) { + result = data.data; + }); + httpBackend.flush(); + + //assert + expect(result).toEqual(responseFake); + }); + + it('la función borrarPlazoPago llama ruta correcta', function() { + //arrange + var responseFake = { data: 'test'}; + var result; + var paramFake = 1; + httpBackend.expectDELETE('localhost/plazo-pago/' + paramFake) + .respond(responseFake); + + //act + servicio.borrarPlazoPago(paramFake).then(function(data) { + result = data.data; + }); + httpBackend.flush(); + + //assert + expect(result).toEqual(responseFake); + }); + + it('la función guardarPlazosPago llama ruta correcta', function() { + //arrange + var responseFake = { data: 'test'}; + var result; + var bodyFake = 1; + httpBackend.expectPOST('localhost/plazos-pago', { plazosPago: bodyFake}) + .respond(responseFake); + + //act + servicio.guardarPlazosPago(bodyFake).then(function(data) { + result = data.data; + }); + httpBackend.flush(); + + //assert + expect(result).toEqual(responseFake); + }); + }); +}); diff --git a/test.html b/test.html new file mode 100644 index 0000000..6c50ce2 --- /dev/null +++ b/test.html @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + -- 1.9.1