describe('Controladores módulo crear nota de pedido', function() { var $controler; beforeEach(function() { module('focaCrearNotaPedido'); inject(function(_$controller_) { $controler = _$controller_; }); }); describe('Controlador notaPedidoCtrl crear nota de pedido', function() { var filter = function() { return function() { }; }; var timeout; beforeEach(function() { inject(function($timeout) { timeout = $timeout; }); }); it('Existe el controlador notaPedidoCtrl', function() { //act var controlador = $controler('notaPedidoCtrl', { $scope: { $watch: function() { }, $broadcast: function() {} }, $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: {} }); //expect expect(typeof controlador).toEqual('object'); }); it('la funcion $scope.crearNotaPedido muestra alerta cuando cliente es null', 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: {}, $watch: function() { }, $broadcast: function() {} }); scope.notaPedido = { vendedor: { id: true }, cliente:{ COD: false } }; //act spyOn(focaModalService, 'alert'); scope.crearNotaPedido(); //expect expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cliente'); }); it('funcion $scope.crearNotaPedido muestra alerta cuando proveedor es null', 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: {}, $watch: function() { }, $broadcast: function() {} }); scope.notaPedido = { vendedor: { id: true }, cliente:{ COD: true }, proveedor:{ COD: null } }; //act spyOn(focaModalService, 'alert'); scope.crearNotaPedido(); //expect expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Proveedor'); }); it('funcion $scope.crearNotaPedido muestra alerta cuando Moneda es null', 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: {}, $watch: function() { }, $broadcast: function() {} }); scope.notaPedido = { vendedor: { id: true }, cliente:{ COD: true }, proveedor:{ COD: true }, cotizacion: { ID: true, moneda:{ ID: null } } }; //act spyOn(focaModalService, 'alert'); scope.crearNotaPedido(); //expect expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Moneda'); }); it('funcion $scope.crearNotaPedido muestra alerta cuando cotizacion es null', 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: {}, $watch: function() { }, $broadcast: function() {} }); scope.notaPedido = { vendedor: { id: true }, cliente:{ COD: true }, proveedor:{ COD: true }, cotizacion:{ ID: null, moneda: { ID: true } } }; //act spyOn(focaModalService, 'alert'); scope.crearNotaPedido(); //expect expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cotización'); }); it('funcion $scope.crearNotaPedido muestra alerta cuando plazos es null', 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: {}, $watch: function() { }, $broadcast: function() {} }); scope.notaPedido = { vendedor: { id: true }, cliente:{ COD: true }, proveedor:{ COD: true }, cotizacion:{ ID: true, moneda:{ ID: true } } }; scope.plazosPagos = null; //act spyOn(focaModalService, 'alert'); scope.crearNotaPedido(); //expect expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Precios y Condiciones'); }); it('funcion $scope.crearNotaPedido muestra alerta cuando flete es null', 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: {}, $watch: function() { }, $broadcast: function() {} }); scope.notaPedido = { vendedor: { id: true }, cliente:{ COD: true }, proveedor:{ COD: true }, cotizacion:{ ID: true, moneda:{ ID: true } }, flete: null, notaPedidoPlazo: [] }; scope.plazosPagos = true; //act spyOn(focaModalService, 'alert'); scope.crearNotaPedido(); //expect expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Flete'); }); it('funcion $scope.crearNotaPedido muestra alerta cuando domicilio es null', 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: {}, $watch: function() { }, $broadcast: function() {} }); scope.notaPedido = { vendedor: { id: true }, cliente:{ COD: true }, proveedor:{ COD: true }, cotizacion:{ ID: true, moneda:{ ID: true } }, flete: true, domicilioStamp: null, notaPedidoPlazo: [] }; scope.plazosPagos = true; //act spyOn(focaModalService, 'alert'); scope.crearNotaPedido(); //expect expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Domicilio'); }); it('funcion $scope.crearNotaPedido muestra alerta cuando no se cargaron articulos', 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() {} }; }, crearNotaPedido: function() { return { then: function() { } }; } }, focaBotoneraLateralService: { startGuardar: function() {} }, focaModalService: focaModalService, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {}, $watch: function() { }, $broadcast: function() {} }); scope.notaPedido = { vendedor: { id: true }, cliente:{ COD: true }, proveedor:{ COD: true }, cotizacion:{ ID: true, moneda:{ ID: true } }, precioCondicion: { id: true }, domicilio: { id: true }, flete: true, domicilioStamp: true, notaPedidoPlazo: [], articulosNotaPedido: [], fechaCarga: true }; scope.articulosTabla = []; //act spyOn(focaModalService, 'alert'); scope.crearNotaPedido(); //expect expect(focaModalService.alert) .toHaveBeenCalledWith('Debe cargar al menos un articulo'); }); it('funcion $scope.crearNotaPedido llama startGuardar', function() { //arrange var scope = { $watch: function() { }, $broadcast: function() {} }; var focaBotoneraLateralService = { startGuardar: function() { } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { getNumeroNotaPedido: function() { return { then: function() { } }; }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() {} }; }, crearNotaPedido: function() { return { then: function() { } }; } }, focaBotoneraLateralService: focaBotoneraLateralService, focaModalService: { alert: function() {} }, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } }, focaSeguimientoService: {}, APP: {}, focaLoginService: {}, $localStorage: {}, $watch: function() { }, $broadcast: function() {} }); scope.notaPedido = { vendedor: { id: true }, cliente:{ COD: true }, proveedor:{ COD: true }, cotizacion:{ ID: true, moneda:{ ID: true } }, flete: true, domicilioStamp: true, domicilio: { id: true }, notaPedidoPlazo: [], articulosNotaPedido: true, fechaCarga: true }; scope.plazosPagos = true; scope.articulosTabla = [1]; //act spyOn(focaBotoneraLateralService, 'startGuardar'); scope.crearNotaPedido(scope.notaPedido); //expect expect(focaBotoneraLateralService.startGuardar).toHaveBeenCalled(); }); it('funcion $scope.crearNotaPedido llama funciones al guardar', function(done) { //arrange var scope = { $watch: function() { }, $broadcast: function() {} }; var focaBotoneraLateralService = { startGuardar: function() { }, endGuardar: function() { } }; var focaSeguimientoService = { guardarPosicion: function() { } }; var notaPedidoBusinessService = { addArticulos: function() { }, addEstado: function() { } }; var crearNotaPedidoService = { getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() {} }; }, crearNotaPedido: function() { return { then: function() { } }; }, getNumeroNotaPedido: function() { return { then: function() { } }; } }; $controler('notaPedidoCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: crearNotaPedidoService, focaBotoneraLateralService: focaBotoneraLateralService, focaModalService: { alert: function() {} }, notaPedidoBusinessService: notaPedidoBusinessService, $rootScope: { $on: function() { } }, focaSeguimientoService: focaSeguimientoService, APP: {}, focaLoginService: {}, $localStorage: {}, $watch: function() { }, $broadcast: function() {} }); scope.notaPedido = { vendedor: { id: true }, cliente:{ COD: true }, proveedor:{ COD: true }, cotizacion:{ ID: true, moneda:{ ID: true } }, flete: true, domicilioStamp: true, domicilio: { id: true }, notaPedidoPlazo: [], articulosNotaPedido: [1], fechaCarga: true }; scope.plazosPagos = []; scope.articulosTabla = [1]; var promesa = Promise.resolve({ data: 1 }); scope.$broadcast = function() { }; //act spyOn(crearNotaPedidoService, 'crearNotaPedido').and.returnValue(promesa); spyOn(focaSeguimientoService, 'guardarPosicion'); spyOn(notaPedidoBusinessService, 'addArticulos'); scope.crearNotaPedido(); //expect promesa.then(function() { expect(focaSeguimientoService.guardarPosicion).toHaveBeenCalled(); expect(notaPedidoBusinessService.addArticulos).toHaveBeenCalled(); done(); }); }); }); });