describe('Controladores módulo crear nota de pedido', function() { var $controler; beforeEach(function() { module('focaCrearNotaPedido'); inject(function(_$controller_) { $controler = _$controller_; }); }); describe('Controlador notaPedidoCtrl', function() { var filter = function() { return function() { }; }; var timeout; beforeEach(function() { inject(function($timeout) { timeout = $timeout; }); }); it('La función seleccionarNotaPedido levanta modal', function() { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var uibModal = { open: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: uibModal, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: {}, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); var respuesta = { result: { then: function() { } } }; //act spyOn(uibModal, 'open').and.returnValue(respuesta); scope.seleccionarNotaPedido(); //assert expect(uibModal.open).toHaveBeenCalled(); }); it('La función seleccionarNotaPedido llama a broadCast en promesa', function(done) { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var uibModal = { open: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: uibModal, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: {}, notaPedidoBusinessService: { plazoToString: function() { }, calcularArticulos: function() { } }, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); var notaPedido = { cotizacion: { moneda: {} }, cliente: {}, vendedor: {}, proveedor: {}, notaPedidoPlazo: [], notaPedidoPuntoDescarga: [] }; var respuesta = { result: Promise.resolve(notaPedido) }; //act scope.notaPedido = {}; scope.$broadcast = function() { }; spyOn(uibModal, 'open').and.returnValue(respuesta); spyOn(scope, '$broadcast'); scope.seleccionarNotaPedido(); //assert respuesta.result.then(function() { expect(scope.$broadcast).toHaveBeenCalledWith('removeCabecera', 'Bomba:'); expect(scope.$broadcast).toHaveBeenCalledWith('removeCabecera', 'Kilometros:'); done(); }); }); it('función seleccionarProductos muestra alerta cuando idLista undefined', function() { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var focaModalService = { alert: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: focaModalService, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); //act spyOn(focaModalService, 'alert'); scope.idLista = undefined; scope.seleccionarProductos(); //assert expect(focaModalService.alert) .toHaveBeenCalledWith('Primero seleccione una lista de precio y condicion'); }); it('función seleccionarProductos abre modal', function() { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var uibModal = { open: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: uibModal, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: {}, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); scope.idLista = true; scope.notaPedido = { cotizacion: { moneda: {} }, }; var respuesta = { result: {then: function() { } } }; //act spyOn(uibModal, 'open').and.returnValue(respuesta); scope.seleccionarProductos(); //assert expect(uibModal.open).toHaveBeenCalled(); }); it('función seleccionarPuntosDeDescarga muestra alerta cuando cliente y domicilio son' + 'undefined', function() { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var focaModalService = { alert: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: focaModalService, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); scope.idLista = true; scope.notaPedido = { cliente: { COD: false }, domicilio: { id: false} }; //act spyOn(focaModalService, 'alert'); scope.seleccionarPuntosDeDescarga(); //assert expect(focaModalService.alert).toHaveBeenCalled(); }); it('función seleccionarPuntosDeDescarga abre modal', function() { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var uibModal = { open: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: uibModal, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: {}, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); scope.idLista = true; scope.notaPedido = { cliente: { COD: true }, domicilio: { id: true } }; var respuesta = { result: { then: function() { } } }; //act spyOn(uibModal, 'open').and.returnValue(respuesta); scope.seleccionarPuntosDeDescarga(); //assert expect(uibModal.open).toHaveBeenCalled(); }); it('función seleccionarPuntosDeDescarga setea punto elegido', function(done) { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var uibModal = { open: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: uibModal, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: {}, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); scope.idLista = true; scope.notaPedido = { cliente: { COD: true }, domicilio: { id: true }, puntosDescarga: [] }; var respuesta = []; var promiseRespuesta = { result: Promise.resolve(respuesta) }; scope.$broadcast = function() { }; //act spyOn(uibModal, 'open').and.returnValue(promiseRespuesta); scope.seleccionarPuntosDeDescarga(); //assert promiseRespuesta.result.then(function() { expect(scope.notaPedido.puntosDescarga).toEqual(respuesta); done(); }); }); it('función seleccionarVendedor abre modal', function() { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var focaModalService = { modal: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: focaModalService, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); scope.idLista = true; scope.notaPedido = { cliente: { COD: true }, domicilio: { id: true } }; var respuesta = { then: function() { } }; //act spyOn(focaModalService, 'modal').and.returnValue(respuesta); scope.seleccionarVendedor(); //assert expect(focaModalService.modal).toHaveBeenCalled(); }); it('función seleccionarVendedor setea vendedor y cabecera', function(done) { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var focaModalService = { modal: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: focaModalService, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); scope.idLista = true; scope.notaPedido = { cliente: { COD: true }, domicilio: { id: true } }; var respuesta = {}; var promesaRespuesta = Promise.resolve(respuesta); scope.$broadcast = function() { }; //act spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta); spyOn(scope, '$broadcast'); scope.seleccionarVendedor(); //assert promesaRespuesta.then(function() { expect(scope.notaPedido.vendedor).toEqual(respuesta); expect(scope.$broadcast).toHaveBeenCalled(); done(); }); }); it('función seleccionarProveedor abre modal', function() { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var focaModalService = { modal: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: focaModalService, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); scope.notaPedido = {}; var respuesta = { then: function() { } }; //act spyOn(focaModalService, 'modal').and.returnValue(respuesta); scope.seleccionarProveedor(); //assert expect(focaModalService.modal).toHaveBeenCalled(); }); it('función seleccionarProveedor setea vendedor y cabecera', function(done) { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var focaModalService = { modal: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: focaModalService, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); scope.notaPedido = {}; var respuesta = {}; var promesaRespuesta = Promise.resolve(respuesta); scope.$broadcast = function() { }; //act spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta); spyOn(scope, '$broadcast'); scope.seleccionarProveedor(); //assert promesaRespuesta.then(function() { expect(scope.notaPedido.proveedor).toEqual(respuesta); expect(scope.$broadcast).toHaveBeenCalled(); done(); }); }); it('función seleccionarCliente abre modal', function() { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var uibModal = { open: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: uibModal, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; }, getVendedorById: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: { modal: function() { return { then: function() {} }; } }, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: 'distribuidor', focaLoginService: { getLoginData: function() { return { vendedorCorbrador: true }; } }, $localStorage: {} }); scope.notaPedido = { vendedor: { NUM: true } }; var respuesta = { result: {then: function() { } } }; //act spyOn(uibModal, 'open').and.returnValue(respuesta); scope.seleccionarCliente(); //assert expect(uibModal.open).toHaveBeenCalled(); }); it('función seleccionarCliente setea vendedor y llama a domicilios', function(done) { //arrange var scope = { $watch: function() { }, $broadcast: function() { }, seleccionarVendedor: function() { }, notaPedido: {} }; var uibModal = { open: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: uibModal, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; }, getVendedorById : function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: { modal: function() { return { then: function() { } }; } }, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: 'distribuidor', focaLoginService: { getLoginData: function() { return { vendedorCorbrador: true }; } }, $localStorage: {} }); scope.idLista = true; scope.notaPedido = { vendedor: { NUM: true } }; var respuesta = {}; var promesaRespuesta = { result: Promise.resolve(respuesta) }; //act spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); spyOn(scope, 'abrirModalDomicilios'); scope.seleccionarCliente(); //assert promesaRespuesta.result.then(function() { expect(scope.cliente).toEqual(respuesta); expect(scope.abrirModalDomicilios).toHaveBeenCalled(); done(); }); }); it('función abrirModalDomicilios abre modal', function() { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var uibModal = { open: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: uibModal, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: {}, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); var respuesta = { result: {then: function() { } } }; //act spyOn(uibModal, 'open').and.returnValue(respuesta); scope.abrirModalDomicilios(); //assert expect(uibModal.open).toHaveBeenCalled(); }); it('función abrirModalDomicilios setea domicilio, cliente y cabeceras', function(done) { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var uibModal = { open: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: uibModal, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; }, getPuntosDescargaByClienDom: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: {}, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); scope.idLista = true; scope.notaPedido = { vendedor: { NUM: true } }; var respuesta = {}; var promesaRespuesta = { result: Promise.resolve(respuesta) }; scope.$broadcast = function() { }; var cliente = { COD: undefined, CUIT: undefined, NOM: undefined, MOD: undefined }; //act spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); spyOn(scope, '$broadcast'); scope.abrirModalDomicilios(cliente); //assert promesaRespuesta.result.then(function() { //scope.notaPedido.domicilio sea vacio expect(scope.notaPedido.domicilio).toEqual(respuesta); expect(scope.notaPedido.cliente).toEqual(cliente); expect(scope.$broadcast).toHaveBeenCalled(); done(); }); }); it('función getTotal devulve correctamente', function() { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: {}, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); scope.idLista = true; scope.notaPedido = { vendedor: { NUM: true } }; //act scope.notaPedido.articulosNotaPedido = [{ precio: 2, cantidad: 1}]; var esperado = 2; var resultado = scope.getTotal(); //assert expect(resultado).toEqual(esperado); }); it('función getSubTotal devulve correctamente', function() { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: {}, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); scope.idLista = true; scope.notaPedido = { vendedor: { NUM: true } }; //act scope.articuloACargar = { precio: 2, cantidad: 1}; var esperado = 2; var resultado = scope.getSubTotal(); //assert expect(resultado).toEqual(esperado); }); it('función seleccionarPreciosYCondiciones abre modal', function() { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var uibModal = { open: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: uibModal, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: {}, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); scope.notaPedido = { cliente: { COD: true } }; var respuesta = { result: {then: function() { } } }; //act spyOn(uibModal, 'open').and.returnValue(respuesta); scope.seleccionarPreciosYCondiciones(); //assert expect(uibModal.open).toHaveBeenCalled(); }); it('función seleccionarPreciosYCondiciones setea articulos y cabecera', function(done) { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var uibModal = { open: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: uibModal, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: {}, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); scope.idLista = true; scope.notaPedido = { vendedor: { NUM: true }, cliente: { COD: true } }; var respuesta = { plazoPago: { } }; var promesaRespuesta = { result: Promise.resolve(respuesta) }; scope.$broadcast = function() { }; //act spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); spyOn(scope, '$broadcast'); scope.seleccionarPreciosYCondiciones(); //assert promesaRespuesta.result.then(function() { expect(scope.notaPedido.articulosNotaPedido.length).toEqual(0); expect(scope.$broadcast).toHaveBeenCalled(); done(); }); }); it('función seleccionarMoneda abre modal', function() { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var focaModalService = { modal: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: focaModalService, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); scope.notaPedido = {}; var respuesta = { then: function() { } }; //act spyOn(focaModalService, 'modal').and.returnValue(respuesta); scope.seleccionarMoneda(); //assert expect(focaModalService.modal).toHaveBeenCalled(); }); it('función seleccionarMoneda llama Modal Cotizacion', function(done) { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var focaModalService = { modal: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: focaModalService, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); scope.notaPedido = {}; var respuesta = 'test'; var promesaRespuesta = Promise.resolve(respuesta); //act spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta); spyOn(scope, 'abrirModalCotizacion'); scope.seleccionarMoneda(); //assert promesaRespuesta.then(function() { expect(scope.abrirModalCotizacion).toHaveBeenCalledWith('test'); done(); }); }); it('función seleccionarObservaciones llama a prompt', function() { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var focaModalService = { prompt: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: focaModalService, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); var respuesta = { then: function() { } }; scope.notaPedido = {}; //act spyOn(focaModalService, 'prompt').and.returnValue(respuesta); scope.seleccionarObservaciones(); //assert expect(focaModalService.prompt).toHaveBeenCalled(); }); it('función seleccionarObservaciones setea observaciones', function(done) { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var focaModalService = { prompt: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: focaModalService, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); var respuesta = 'unit test'; var promesa = Promise.resolve(respuesta); scope.notaPedido = {}; //act spyOn(focaModalService, 'prompt').and.returnValue(promesa); scope.seleccionarObservaciones(); //assert promesa.then(function() { expect(scope.notaPedido.observaciones).toEqual(respuesta); done(); }); }); it('función abrirModalCotizacion abre modal', function() { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var uibModal = { open: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: uibModal, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: {}, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); scope.notaPedido = {}; var respuesta = { result: {then: function() { } } }; //act spyOn(uibModal, 'open').and.returnValue(respuesta); scope.abrirModalCotizacion(); //assert expect(uibModal.open).toHaveBeenCalled(); }); it('función abrirModalCotizacion setea datos y cabecera', function(done) { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var uibModal = { open: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: uibModal, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: {}, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {}, articulosNotaPedido: [] }); scope.notaPedido = {}; scope.articulosTabla = []; scope.$broadcast = function() { }; var moneda = 'moneda'; var cotizacion = 'test'; var promesaRespuesta = { result: Promise.resolve(cotizacion) }; //act spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); spyOn(scope, '$broadcast'); scope.abrirModalCotizacion(moneda); //assert promesaRespuesta.result.then(function() { expect(scope.$broadcast).toHaveBeenCalled(); expect(scope.notaPedido.cotizacion).toEqual(cotizacion); done(); }); }); it('función agregarATabla muestra alerta cuando a cargar undefined', function() { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var focaModalService = { alert: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: focaModalService, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); scope.articuloACargar = {}; //act spyOn(focaModalService, 'alert'); scope.agregarATabla(13); //assert expect(focaModalService.alert).toHaveBeenCalledWith('El valor debe ser al menos 1'); }); it('función editarArticulo muestra alerta cuando a cargar es undefined', function() { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; var focaModalService = { alert: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: focaModalService, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {} }); scope.articuloACargar = {}; //act spyOn(focaModalService, 'alert'); scope.agregarATabla(13); //assert expect(focaModalService.alert).toHaveBeenCalledWith('El valor debe ser al menos 1'); }); it('función salir lleva a ruta correcta', function() { inject(function($location) { //arrange var scope = { $watch: function() { }, $broadcast: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: {}, $location: $location, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() { } }; } }, focaBotoneraLateralService: {}, focaModalService: {}, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {}, }); //act scope.salir(); //assert expect($location.url()).toEqual('/'); }); }); }); });