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() { }, $watch: 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: {}, $localStorage: true }); //assert expect(typeof controlador).toEqual('object'); }); it('function crearCobranza muestra alerta cuando no hay cliente', function() { //arrange var scope = { $broadcast: function() { }, $watch: 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: {}, $localStorage: true }); //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() { }, $watch: 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: {}, $localStorage: true }); scope.cobranza = { cliente: { COD: true }, cobrador: {} }; //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() { }, $watch: 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: {}, $localStorage: true }); scope.cobranza = { cliente: { COD: true }, cobrador: { NUM: true }, facturas: [] }; //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() { }, $watch: 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: {}, $localStorage: true }); scope.cobranza = { cliente: { COD: true }, cobrador: { NUM: true }, moneda: { SIMBOLO: '' }, facturas: [1] }; 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() { }, $watch: 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: { alert: function() {} }, $filter: $filter, focaSeguimientoService: {}, focaBotoneraLateralService: focaBotoneraLateralService, APP: {}, focaLoginService: {}, $localStorage: true }); scope.cobranza = { cliente: { COD: true }, cobrador: { NUM: true }, moneda: { cotizacion: {} }, facturas: [1], cobros: [{ FEC: new Date(), fechaPresentacion: new Date(), fechaEmision: new Date(), tipo: true, banco: { ID: true }, localidad: { ID: true, NOMBRE: true }, provincia: { ID: true } }], FEC: new Date() }; //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() { }, $watch: 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: {}, $localStorage: true }); //act scope.seleccionarCobros(); //assert expect(scope.cobroDeuda).toEqual(false); }); it('seleccionarComprobantes seatea cobroDeuda en true', function() { //arrange var scope = { $broadcast: function() { }, $watch: 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: {}, $localStorage: true }); //act scope.seleccionarComprobantes(); //assert expect(scope.cobroDeuda).toEqual(true); }); it('seleccionarCliente levanta modal y setea datos', function(done) { //arrange var scope = { $broadcast: function() { }, $watch: 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() { } }; }, getCobradorById: function() { return { then: function() { } }; } }, focaModalService: { modal: function() { return { then: function() {} }; } }, $filter: $filter, focaSeguimientoService: {}, focaBotoneraLateralService: {}, APP: 'cobranza', focaLoginService: { getLoginData: function() { return { vendedorCobrador: true }; } }, $localStorage: true }); 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() { }, $watch: function() { } }; var focaModalService = { alert: function() { } }; $controller('cobranzaController', { $scope: scope, $timeout: $timeout, $uibModal: { open: function() { return { result: { then: function() { } } }; } }, $location: {}, focaCrearCobranzaService: { getCotizacionByIdMoneda: function() { return { then: function() { } }; }, getBotonera: function() { }, getNumeroRecibo: function() { return { then: function() { } }; } }, focaModalService: focaModalService, $filter: $filter, focaSeguimientoService: {}, focaBotoneraLateralService: {}, APP: {}, focaLoginService: {}, $localStorage: true }); //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() { }, $watch: 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: { alert: function() {} }, $filter: $filter, focaSeguimientoService: {}, focaBotoneraLateralService: {}, APP: {}, focaLoginService: {}, $localStorage: true }); scope.cobranza = { cliente: { COD: true } }; 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() { }, $watch: 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: {}, $localStorage: true }); scope.cobranza = { cliente: { }, facturas: [], cobros: [] }; 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() { }, $watch: 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: {}, $localStorage: true }); scope.cobranza = { cliente: { }, cobros: [] }; 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() { }, $watch: 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: {}, $localStorage: true }); scope.cobranza = { cliente: { }, facturas: [], cobros: [] }; 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() { }, $watch: 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: {}, $localStorage: true }); 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() { }, $watch: 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: {}, $localStorage: true }); 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('getTotalDeuda devuelve correcto', function() { //arrange var scope = { $broadcast: function() { }, $watch: 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: {}, $localStorage: true }); scope.cobranza = { facturas: [{ 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() { }, $watch: 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: {}, $localStorage: true }); scope.cobranza = { cobros: [{ IMP: 1 }] }; //act var esperado = 1; var resultado = scope.getTotalCobrado(); //assert expect(resultado).toEqual(esperado); }); it('getSubTotal devuelve correcto', function() { //arrange var scope = { $broadcast: function() { }, $watch: 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: {}, $localStorage: true }); 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() { }, $watch: 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: {}, $localStorage: true }); //act scope.salir(); //assert expect($location.url()).toEqual('/'); }); }); it('parsearATexto parsea correctamente', function() { //arrange var scope = { $broadcast: function() { }, $watch: 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: {}, $localStorage: true }); var parametro = { cantidad: '1', precio: '2' }; //act scope.parsearATexto(parametro); //assert expect(typeof parametro.cantidad).toEqual('number'); expect(typeof parametro.precio).toEqual('number'); }); }); });