diff --git a/spec/controllerSpec.js b/spec/controllerSpec.js index e69de29..3f4a7ca 100644 --- a/spec/controllerSpec.js +++ b/spec/controllerSpec.js @@ -0,0 +1,1111 @@ +describe('controladores módulo crear cobranza', function() { + + var $controller; + + beforeEach(function() { + + module('focaCrearCobranza'); + + inject(function(_$controller_) { + + $controller = _$controller_; + }); + }); + + describe('Controlador cobranzaController', function() { + + var $filter = function() { + return function() { }; + }; + + var $timeout = function() { }; + + it('existe el controlador cobranzaController', function() { + + //act + var controlador = $controller('cobranzaController', { + $scope: { + $broadcast: function() { } + }, + $timeout: $timeout, + $uibModal: {}, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: {}, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + + //assert + expect(typeof controlador).toEqual('object'); + }); + + it('function crearCobranza muestra alerta cuando no hay cliente', function() { + + //arrange + var scope = { + $broadcast: function() { } + }; + var focaModalService = { + alert: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: {}, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: focaModalService, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + + //act + spyOn(focaModalService, 'alert'); + scope.crearCobranza(); + + //assert + expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cliente'); + }); + + it('function crearCobranza muestra alerta cuando no hay cobrador', function() { + + //arrange + var scope = { + $broadcast: function() { } + }; + var focaModalService = { + alert: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: {}, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: focaModalService, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + scope.cobranza = { + cliente: { } + }; + + //act + spyOn(focaModalService, 'alert'); + scope.crearCobranza(); + + //assert + expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cobrador'); + }); + + it('function crearCobranza muestra alerta cuando no hay facturas', function() { + + //arrange + var scope = { + $broadcast: function() { } + }; + var focaModalService = { + alert: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: {}, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: focaModalService, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + scope.cobranza = { + cliente: { }, + cobrador: { } + }; + + //act + spyOn(focaModalService, 'alert'); + scope.crearCobranza(); + + //assert + expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese al menos una factura'); + }); + + it('crearCobranza muestra alerta cuando la diferencia no es 0', function() { + + //arrange + var scope = { + $broadcast: function() { } + }; + var focaModalService = { + alert: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: {}, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: focaModalService, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + scope.cobranza = { + cliente: {}, + cobrador: {}, + moneda: { SIMBOLO: '' } + }; + scope.facturaTabla = [1]; + + //act + spyOn(focaModalService, 'alert'); + spyOn(scope, 'getTotalCobrado').and.returnValue(1); + spyOn(scope, 'getTotalDeuda').and.returnValue(1); + scope.crearCobranza(); + + //assert + expect(focaModalService.alert).toHaveBeenCalledWith('La diferencia debe ser 0,00'); + }); + + it('crearCobranza llama a startGuardar y guardarCobranza', function() { + + //arrange + var scope = { + $broadcast: function() { } + }; + var focaBotoneraLateralService = { + startGuardar: function() { } + }; + var focaCrearCobranzaService = { + guardarCobranza: function() { }, + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: {}, + $location: {}, + focaCrearCobranzaService: focaCrearCobranzaService, + focaModalService: {}, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: focaBotoneraLateralService, + APP: {}, + focaLoginService: {} + }); + scope.cobranza = { + cliente: {}, + cobrador: {}, + moneda: { SIMBOLO: '' }, + cotizacion: {} + }; + scope.facturaTabla = [1]; + + //act + spyOn(focaBotoneraLateralService, 'startGuardar'); + spyOn(focaCrearCobranzaService, 'guardarCobranza') + .and.returnValue({ then: function() { } }); + spyOn(scope, 'getTotalCobrado').and.returnValue(0); + spyOn(scope, 'getTotalDeuda').and.returnValue(0); + scope.crearCobranza(); + + //assert + expect(focaBotoneraLateralService.startGuardar).toHaveBeenCalled(); + expect(focaCrearCobranzaService.guardarCobranza).toHaveBeenCalled(); + }); + + it('seleccionarCobros seatea cobroDeuda en false', function() { + + //arrange + var scope = { + $broadcast: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: {}, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: {}, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + + //act + scope.seleccionarCobros(); + + //assert + expect(scope.cobroDeuda).toEqual(false); + }); + + it('seleccionarComprobantes seatea cobroDeuda en true', function() { + + //arrange + var scope = { + $broadcast: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: {}, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: {}, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + + //act + scope.seleccionarComprobantes(); + + //assert + expect(scope.cobroDeuda).toEqual(true); + }); + + it('seleccionarCobranza levanta modal y setea datos', function(done) { + + //arrange + var scope = { + $broadcast: function() { } + }; + var uibModal = { + open: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: uibModal, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: {}, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + var respuesta = { facturas: 1, cobros: 2, cliente: { } }; + var promesa = { result: Promise.resolve(respuesta) }; + + //act + spyOn(uibModal, 'open').and.returnValue(promesa); + spyOn(scope, '$broadcast'); + scope.seleccionarCobranza(); + + //assert + promesa.result.then(function() { + expect(uibModal.open).toHaveBeenCalled(); + expect(scope.$broadcast).toHaveBeenCalledWith('cleanCabecera'); + expect(scope.facturaTabla).toEqual(respuesta.facturas); + expect(scope.cobrosTabla).toEqual(respuesta.cobros); + done(); + }); + }); + + it('seleccionarCliente levanta modal y setea datos', function(done) { + + //arrange + var scope = { + $broadcast: function() { } + }; + var uibModal = { + open: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: uibModal, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: {}, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + scope.cobranza = { + cobrador: {} + }; + var respuesta = { facturas: 1, cobros: 2, cliente: { } }; + var promesa = { result: Promise.resolve(respuesta) }; + + //act + spyOn(uibModal, 'open').and.returnValue(promesa); + spyOn(scope, '$broadcast'); + scope.seleccionarCliente(); + + //assert + promesa.result.then(function() { + expect(uibModal.open).toHaveBeenCalled(); + expect(scope.$broadcast).toHaveBeenCalled(); + done(); + }); + }); + + it('seleccionarFactura muestra alerta cuando no se seteo cliente', function() { + + //arrange + var scope = { + $broadcast: function() { } + }; + var focaModalService = { + alert: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: {}, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: focaModalService, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + + //act + spyOn(focaModalService, 'alert'); + scope.seleccionarFactura(); + + //assert + expect(focaModalService.alert).toHaveBeenCalledWith('Seleccione primero un cliente'); + }); + + it('seleccionarFactura levanta modal', function() { + + //arrange + var scope = { + $broadcast: function() { } + }; + var uibModal = { + open: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: uibModal, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: {}, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + scope.cobranza = { + cliente: { } + }; + + var respuesta = { result: { then: function() { } } }; + + //act + spyOn(uibModal, 'open').and.returnValue(respuesta); + scope.seleccionarFactura(); + + //assert + expect(uibModal.open).toHaveBeenCalled(); + }); + + it('seleccionarCheque levanta modal', function() { + + //arrange + var scope = { + $broadcast: function() { } + }; + var uibModal = { + open: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: uibModal, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: {}, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + scope.cobranza = { + cliente: { } + }; + + var respuesta = { result: { then: function() { } } }; + + //act + spyOn(uibModal, 'open').and.returnValue(respuesta); + scope.seleccionarCheque(); + + //assert + expect(uibModal.open).toHaveBeenCalled(); + }); + + it('seleccionarEfectivo levanta modal', function() { + + //arrange + var scope = { + $broadcast: function() { } + }; + var uibModal = { + open: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: uibModal, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: {}, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + scope.cobranza = { + cliente: { } + }; + + var respuesta = { result: { then: function() { } } }; + + //act + spyOn(uibModal, 'open').and.returnValue(respuesta); + scope.seleccionarEfectivo(); + + //assert + expect(uibModal.open).toHaveBeenCalled(); + }); + + it('seleccionarDetalles levanta modal', function() { + + //arrange + var scope = { + $broadcast: function() { } + }; + var uibModal = { + open: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: uibModal, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: {}, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + scope.cobranza = { + cliente: { } + }; + + var respuesta = { result: { then: function() { } } }; + + //act + spyOn(uibModal, 'open').and.returnValue(respuesta); + scope.seleccionarDetalles(); + + //assert + expect(uibModal.open).toHaveBeenCalled(); + }); + + it('seleccionarMoneda levanta modal', function(done) { + + //arrange + var scope = { + $broadcast: function() { } + }; + var focaModalService = { + modal: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: {}, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: focaModalService, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + + var respuesta = 1; + var promesa = Promise.resolve(respuesta); + + //act + spyOn(focaModalService, 'modal').and.returnValue(promesa); + spyOn(scope, 'seleccionarCotizacion'); + scope.seleccionarMoneda(); + + //assert + expect(focaModalService.modal).toHaveBeenCalled(); + promesa.then(function() { + expect(scope.seleccionarCotizacion).toHaveBeenCalled(); + done(); + }); + }); + + it('seleccionarCotizacion levanta modal', function(done) { + + //arrange + var scope = { + $broadcast: function() { } + }; + var uibModal = { + open: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: uibModal, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: {}, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + + var respuesta = 1; + var promesa = { result: Promise.resolve(respuesta) }; + + //act + spyOn(uibModal, 'open').and.returnValue(promesa); + spyOn(scope, '$broadcast'); + scope.seleccionarCotizacion({ }); + + //assert + promesa.result.then(function() { + expect(uibModal.open).toHaveBeenCalled(); + expect(scope.$broadcast).toHaveBeenCalled(); + scope.cobranza.cotizacion = respuesta; + done(); + }); + }); + + it('seleccionarCobrador levanta modal', function(done) { + + //arrange + var scope = { + $broadcast: function() { } + }; + var focaModalService = { + modal: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: {}, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: focaModalService, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + + var respuesta = 1; + var promesa = Promise.resolve(respuesta); + + //act + spyOn(focaModalService, 'modal').and.returnValue(promesa); + spyOn(scope, '$broadcast'); + scope.seleccionarCobrador({ }); + + //assert + promesa.then(function() { + expect(focaModalService.modal).toHaveBeenCalled(); + expect(scope.$broadcast).toHaveBeenCalled(); + scope.cobranza.cobrador = respuesta; + done(); + }); + }); + + it('getTotalDeuda devuelve correcto', function() { + + //arrange + var scope = { + $broadcast: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: {}, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: {}, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + scope.facturaTabla = [{ IPA: 1 }]; + + //act + var esperado = 1; + var resultado = scope.getTotalDeuda(); + + //assert + expect(resultado).toEqual(esperado); + }); + + it('getTotalCobrado devuelve correcto', function() { + + //arrange + var scope = { + $broadcast: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: {}, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: {}, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + scope.cobrosTabla = [{ importe: 1 }]; + + //act + var esperado = 1; + var resultado = scope.getTotalCobrado(); + + //assert + expect(resultado).toEqual(esperado); + }); + + it('getSubTotal devuelve correcto', function() { + + //arrange + var scope = { + $broadcast: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: {}, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: {}, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + scope.articuloACargar = { + precio: 2, + cantidad: 5 + }; + + //act + var esperado = 10; + var resultado = scope.getSubTotal(); + + //assert + expect(resultado).toEqual(esperado); + }); + + it('salir lleva a la ruta correcta', function() { + + inject(function($location) { + + //arrange + var scope = { + $broadcast: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: {}, + $location: $location, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: {}, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + + //act + scope.salir(); + + //assert + expect($location.url()).toEqual('/'); + }); + }); + + it('parsearATexto parsea correctamente', function() { + + //arrange + var scope = { + $broadcast: function() { } + }; + + $controller('cobranzaController', { + $scope: scope, + $timeout: $timeout, + $uibModal: {}, + $location: {}, + focaCrearCobranzaService: { + getCotizacionByIdMoneda: function() { + return { + then: function() { } + }; + }, + getBotonera: function() { }, + getNumeroRecibo: function() { + return { + then: function() { } + }; + } + }, + focaModalService: {}, + $filter: $filter, + focaSeguimientoService: {}, + focaBotoneraLateralService: {}, + APP: {}, + focaLoginService: {} + }); + + var parametro = { + cantidad: '1', + precio: '2' + }; + + //act + scope.parsearATexto(parametro); + + //assert + expect(typeof parametro.cantidad).toEqual('number'); + expect(typeof parametro.precio).toEqual('number'); + }); + + }); +});