diff --git a/spec/controllerSpec.js b/spec/controllerSpec.js index 8318d39..501395d 100644 --- a/spec/controllerSpec.js +++ b/spec/controllerSpec.js @@ -25,7 +25,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('La función seleccionarNotaPedido levanta modal', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var uibModal = { open: function() { } }; @@ -37,6 +40,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -53,8 +61,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); var respuesta = { result: { then: function() { } } }; @@ -68,7 +75,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('La función seleccionarNotaPedido llama a broadCast en promesa', function(done) { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var uibModal = { open: function() { } }; @@ -80,6 +90,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -99,8 +114,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); var notaPedido = { cotizacion: { @@ -109,7 +123,7 @@ describe('Controladores módulo crear nota de pedido', function() { cliente: {}, vendedor: {}, proveedor: {}, - notaPedidoPlazo: {}, + notaPedidoPlazo: [], notaPedidoPuntoDescarga: [] }; var respuesta = { result: Promise.resolve(notaPedido) }; @@ -131,7 +145,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función seleccionarProductos muestra alerta cuando idLista undefined', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var focaModalService = { alert: function() { } }; @@ -143,6 +160,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -159,8 +181,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); //act @@ -175,7 +196,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función seleccionarProductos abre modal', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var uibModal = { open: function() { } }; @@ -187,6 +211,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -203,13 +232,14 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.idLista = true; scope.notaPedido = { - cotizacion: {}, - moneda: {} + cotizacion: { + moneda: {} + }, + }; var respuesta = { result: {then: function() { } } }; @@ -225,7 +255,10 @@ describe('Controladores módulo crear nota de pedido', function() { 'undefined', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var focaModalService = { alert: function() { } }; @@ -237,6 +270,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -253,8 +291,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.idLista = true; scope.notaPedido = { @@ -272,7 +309,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función seleccionarPuntosDeDescarga abre modal', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var uibModal = { open: function() { } }; @@ -284,6 +324,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -300,8 +345,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.idLista = true; scope.notaPedido = { @@ -320,7 +364,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función seleccionarPuntosDeDescarga setea punto elegido', function(done) { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var uibModal = { open: function() { } }; @@ -332,6 +379,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -348,13 +400,13 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.idLista = true; scope.notaPedido = { cliente: { COD: true }, - domicilio: { id: true } + domicilio: { id: true }, + puntosDescarga: [] }; var respuesta = []; var promiseRespuesta = { result: Promise.resolve(respuesta) }; @@ -373,7 +425,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función seleccionarVendedor abre modal', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var focaModalService = { modal: function() { } }; @@ -385,6 +440,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -401,8 +461,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.idLista = true; scope.notaPedido = { @@ -422,7 +481,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función seleccionarVendedor setea vendedor y cabecera', function(done) { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var focaModalService = { modal: function() { } }; @@ -434,6 +496,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -450,8 +517,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.idLista = true; scope.notaPedido = { @@ -477,7 +543,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función seleccionarProveedor abre modal', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var focaModalService = { modal: function() { } }; @@ -489,6 +558,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -505,8 +579,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.notaPedido = {}; @@ -522,7 +595,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función seleccionarProveedor setea vendedor y cabecera', function(done) { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var focaModalService = { modal: function() { } }; @@ -534,6 +610,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -550,8 +631,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.notaPedido = {}; @@ -574,7 +654,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función seleccionarCliente abre alerta cuando no se elije vendedor', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var focaModalService = { alert: function() { } }; @@ -586,6 +669,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -602,8 +690,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.notaPedido = { vendedor: { NUM: false } @@ -619,7 +706,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función seleccionarCliente abre modal', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var uibModal = { open: function() { } }; @@ -631,6 +721,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -647,8 +742,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.notaPedido = { vendedor: { NUM: true } @@ -667,7 +761,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función seleccionarCliente setea vendedor y llama a domicilios', function(done) { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var uibModal = { open: function() { } }; @@ -679,6 +776,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -695,8 +797,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.idLista = true; scope.notaPedido = { @@ -720,7 +821,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función abrirModalDomicilios abre modal', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var uibModal = { open: function() { } }; @@ -732,6 +836,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -748,8 +857,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); var respuesta = { result: {then: function() { } } }; @@ -765,7 +873,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función abrirModalDomicilios setea domicilio, cliente y cabeceras', function(done) { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var uibModal = { open: function() { } }; @@ -777,6 +888,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -798,8 +914,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.idLista = true; scope.notaPedido = { @@ -831,7 +946,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función getTotal devulve correctamente', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; $controler('notaPedidoCtrl', { $scope: scope, @@ -840,6 +958,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -856,8 +979,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.idLista = true; scope.notaPedido = { @@ -865,9 +987,10 @@ describe('Controladores módulo crear nota de pedido', function() { }; //act - scope.articulosTabla = [{ precio: 2, cantidad: 1}]; + scope.notaPedido.articulosNotaPedido = [{ precio: 2, cantidad: 1}]; var esperado = 2; var resultado = scope.getTotal(); + console.log('resultado', resultado); //assert expect(resultado).toEqual(esperado); @@ -876,7 +999,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función getSubTotal devulve correctamente', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; $controler('notaPedidoCtrl', { $scope: scope, @@ -885,6 +1011,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -901,8 +1032,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.idLista = true; scope.notaPedido = { @@ -921,7 +1051,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función seleccionarPreciosYCondiciones abre modal', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var uibModal = { open: function() { } }; @@ -933,6 +1066,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -949,8 +1087,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.notaPedido = {}; @@ -968,7 +1105,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función seleccionarPreciosYCondiciones setea articulos y cabecera', function(done) { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var uibModal = { open: function() { } }; @@ -980,6 +1120,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -996,8 +1141,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.idLista = true; scope.notaPedido = { @@ -1014,7 +1158,7 @@ describe('Controladores módulo crear nota de pedido', function() { //assert promesaRespuesta.result.then(function() { - expect(scope.articulosTabla.length).toEqual(0); + expect(scope.notaPedido.articulosNotaPedido.length).toEqual(0); expect(scope.$broadcast).toHaveBeenCalled(); done(); }); @@ -1023,7 +1167,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función seleccionarFlete abre modal', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var uibModal = { open: function() { } }; @@ -1035,6 +1182,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -1051,8 +1203,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.notaPedido = {}; @@ -1070,7 +1221,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función seleccionarFlete setea flete y cabecera', function(done) { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var uibModal = { open: function() { } }; @@ -1082,6 +1236,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -1098,8 +1257,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.idLista = true; scope.notaPedido = { @@ -1128,7 +1286,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función seleccionarMoneda abre modal', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var focaModalService = { modal: function() { } }; @@ -1140,6 +1301,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -1156,8 +1322,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.notaPedido = {}; @@ -1173,7 +1338,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función seleccionarMoneda llama Modal Cotizacion', function(done) { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var focaModalService = { modal: function() { } }; @@ -1185,6 +1353,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -1201,8 +1374,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.notaPedido = {}; @@ -1224,7 +1396,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función seleccionarObservaciones llama a prompt', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var focaModalService = { prompt: function() { } }; @@ -1236,6 +1411,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -1252,8 +1432,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); var respuesta = { then: function() { } }; scope.notaPedido = {}; @@ -1269,7 +1448,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función seleccionarObservaciones setea observaciones', function(done) { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var focaModalService = { prompt: function() { } }; @@ -1281,6 +1463,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -1297,8 +1484,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); var respuesta = 'unit test'; var promesa = Promise.resolve(respuesta); @@ -1318,7 +1504,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función abrirModalCotizacion abre modal', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var uibModal = { open: function() { } }; @@ -1330,6 +1519,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -1346,8 +1540,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.notaPedido = {}; @@ -1364,7 +1557,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función abrirModalCotizacion setea datos y cabecera', function(done) { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var uibModal = { open: function() { } }; @@ -1376,6 +1572,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -1393,7 +1594,7 @@ describe('Controladores módulo crear nota de pedido', function() { APP: {}, focaLoginService: {}, $localStorage: {}, - $watch: function() { } + articulosNotaPedido: [] }); scope.notaPedido = {}; @@ -1412,9 +1613,6 @@ describe('Controladores módulo crear nota de pedido', function() { promesaRespuesta.result.then(function() { expect(scope.$broadcast).toHaveBeenCalled(); - expect(scope.notaPedido.moneda).toEqual(moneda); - expect(scope.monedaDefecto).toEqual(moneda); - expect(scope.cotizacionDefecto).toEqual(cotizacion); expect(scope.notaPedido.cotizacion).toEqual(cotizacion); done(); }); @@ -1423,7 +1621,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función agregarATabla muestra alerta cuando a cargar undefined', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var focaModalService = { alert: function() { } }; @@ -1435,6 +1636,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -1451,8 +1657,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.articuloACargar = {}; @@ -1467,7 +1672,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('función editarArticulo muestra alerta cuando a cargar es undefined', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; var focaModalService = { alert: function() { } }; @@ -1479,6 +1687,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -1495,8 +1708,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); scope.articuloACargar = {}; @@ -1513,7 +1725,10 @@ describe('Controladores módulo crear nota de pedido', function() { inject(function($location) { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() { } + }; $controler('notaPedidoCtrl', { $scope: scope, @@ -1522,6 +1737,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -1539,7 +1759,6 @@ describe('Controladores módulo crear nota de pedido', function() { APP: {}, focaLoginService: {}, $localStorage: {}, - $watch: function() { } }); //act diff --git a/spec/controllerSpecCrearPedido.js b/spec/controllerSpecCrearPedido.js index 88f92fa..9b351d7 100644 --- a/spec/controllerSpecCrearPedido.js +++ b/spec/controllerSpecCrearPedido.js @@ -27,12 +27,20 @@ describe('Controladores módulo crear nota de pedido', function() { //act var controlador = $controler('notaPedidoCtrl', { - $scope: {}, + $scope: { + $watch: function() { }, + $broadcast: function() {} + }, $uibModal: {}, $location: {}, $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -49,8 +57,7 @@ describe('Controladores módulo crear nota de pedido', function() { focaSeguimientoService: {}, APP: {}, focaLoginService: {}, - $localStorage: {}, - $watch: function() { } + $localStorage: {} }); //expect @@ -60,7 +67,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('la funcion $scope.crearNotaPedido muestra alerta cuando vendedor es null', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() {} + }; var focaModalService = { alert: function() { } }; @@ -72,6 +82,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -89,7 +104,8 @@ describe('Controladores módulo crear nota de pedido', function() { APP: {}, focaLoginService: {}, $localStorage: {}, - $watch: function() { } + $watch: function() { }, + $broadcast: function() {} }); //act @@ -108,7 +124,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('la funcion $scope.crearNotaPedido muestra alerta cuando cliente es null', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() {} + }; var focaModalService = { alert: function() { } }; @@ -120,6 +139,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -137,7 +161,8 @@ describe('Controladores módulo crear nota de pedido', function() { APP: {}, focaLoginService: {}, $localStorage: {}, - $watch: function() { } + $watch: function() { }, + $broadcast: function() {} }); scope.notaPedido = { @@ -160,7 +185,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('funcion $scope.crearNotaPedido muestra alerta cuando proveedor es null', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() {} + }; var focaModalService = { alert: function() { } }; @@ -172,6 +200,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -189,7 +222,8 @@ describe('Controladores módulo crear nota de pedido', function() { APP: {}, focaLoginService: {}, $localStorage: {}, - $watch: function() { } + $watch: function() { }, + $broadcast: function() {} }); scope.notaPedido = { @@ -215,7 +249,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('funcion $scope.crearNotaPedido muestra alerta cuando Moneda es null', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() {} + }; var focaModalService = { alert: function() { } }; @@ -227,6 +264,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -244,7 +286,8 @@ describe('Controladores módulo crear nota de pedido', function() { APP: {}, focaLoginService: {}, $localStorage: {}, - $watch: function() { } + $watch: function() { }, + $broadcast: function() {} }); scope.notaPedido = { @@ -257,8 +300,11 @@ describe('Controladores módulo crear nota de pedido', function() { proveedor:{ COD: true }, - moneda:{ - ID: null + cotizacion: { + ID: true, + moneda:{ + ID: null + } } }; @@ -273,7 +319,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('funcion $scope.crearNotaPedido muestra alerta cuando cotizacion es null', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() {} + }; var focaModalService = { alert: function() { } }; @@ -285,6 +334,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -302,7 +356,8 @@ describe('Controladores módulo crear nota de pedido', function() { APP: {}, focaLoginService: {}, $localStorage: {}, - $watch: function() { } + $watch: function() { }, + $broadcast: function() {} }); scope.notaPedido = { @@ -315,11 +370,11 @@ describe('Controladores módulo crear nota de pedido', function() { proveedor:{ COD: true }, - moneda:{ - ID: true - }, cotizacion:{ - ID: null + ID: null, + moneda: { + ID: true + } } }; @@ -334,7 +389,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('funcion $scope.crearNotaPedido muestra alerta cuando plazos es null', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() {} + }; var focaModalService = { alert: function() { } }; @@ -346,6 +404,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -363,7 +426,8 @@ describe('Controladores módulo crear nota de pedido', function() { APP: {}, focaLoginService: {}, $localStorage: {}, - $watch: function() { } + $watch: function() { }, + $broadcast: function() {} }); scope.notaPedido = { @@ -376,11 +440,11 @@ describe('Controladores módulo crear nota de pedido', function() { proveedor:{ COD: true }, - moneda:{ - ID: true - }, cotizacion:{ - ID: true + ID: true, + moneda:{ + ID: true + } } }; @@ -397,7 +461,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('funcion $scope.crearNotaPedido muestra alerta cuando flete es null', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() {} + }; var focaModalService = { alert: function() { } }; @@ -409,6 +476,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -426,7 +498,8 @@ describe('Controladores módulo crear nota de pedido', function() { APP: {}, focaLoginService: {}, $localStorage: {}, - $watch: function() { } + $watch: function() { }, + $broadcast: function() {} }); scope.notaPedido = { @@ -439,13 +512,14 @@ describe('Controladores módulo crear nota de pedido', function() { proveedor:{ COD: true }, - moneda:{ - ID: true - }, cotizacion:{ - ID: true + ID: true, + moneda:{ + ID: true + } }, - flete: null + flete: null, + notaPedidoPlazo: [] }; scope.plazosPagos = true; @@ -461,7 +535,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('funcion $scope.crearNotaPedido muestra alerta cuando domicilio es null', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() {} + }; var focaModalService = { alert: function() { } }; @@ -473,6 +550,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -490,7 +572,8 @@ describe('Controladores módulo crear nota de pedido', function() { APP: {}, focaLoginService: {}, $localStorage: {}, - $watch: function() { } + $watch: function() { }, + $broadcast: function() {} }); scope.notaPedido = { @@ -503,14 +586,15 @@ describe('Controladores módulo crear nota de pedido', function() { proveedor:{ COD: true }, - moneda:{ - ID: true - }, cotizacion:{ - ID: true + ID: true, + moneda:{ + ID: true + } }, flete: true, - domicilioStamp: null + domicilioStamp: null, + notaPedidoPlazo: [] }; scope.plazosPagos = true; @@ -528,7 +612,10 @@ describe('Controladores módulo crear nota de pedido', function() { { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() {} + }; var focaModalService = { alert: function() { } }; @@ -540,14 +627,26 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() {} + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { then: function() {} }; + }, + crearNotaPedido: function() { + return { + then: function() { } + }; } }, - focaBotoneraLateralService: {}, + focaBotoneraLateralService: { + startGuardar: function() {} + }, focaModalService: focaModalService, notaPedidoBusinessService: {}, $rootScope: { @@ -557,7 +656,8 @@ describe('Controladores módulo crear nota de pedido', function() { APP: {}, focaLoginService: {}, $localStorage: {}, - $watch: function() { } + $watch: function() { }, + $broadcast: function() {} }); scope.notaPedido = { @@ -570,17 +670,25 @@ describe('Controladores módulo crear nota de pedido', function() { proveedor:{ COD: true }, - moneda:{ - ID: true - }, cotizacion:{ - ID: true + ID: true, + moneda:{ + ID: true + } + }, + precioCondicion: { + id: true + }, + domicilio: { + id: true }, flete: true, domicilioStamp: true, + notaPedidoPlazo: [], + articulosNotaPedido: [], + fechaCarga: true }; - scope.plazosPagos = true; scope.articulosTabla = []; //act @@ -595,7 +703,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('funcion $scope.crearNotaPedido llama startGuardar', function() { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() {} + }; var focaBotoneraLateralService = { startGuardar: function() { } }; @@ -607,6 +718,11 @@ describe('Controladores módulo crear nota de pedido', function() { $filter: filter, $timeout: timeout, crearNotaPedidoService: { + getNumeroNotaPedido: function() { + return { + then: function() { } + }; + }, getBotonera: function() { }, getCotizacionByIdMoneda: function() { return { @@ -620,7 +736,9 @@ describe('Controladores módulo crear nota de pedido', function() { } }, focaBotoneraLateralService: focaBotoneraLateralService, - focaModalService: {}, + focaModalService: { + alert: function() {} + }, notaPedidoBusinessService: {}, $rootScope: { $on: function() { } @@ -629,7 +747,8 @@ describe('Controladores módulo crear nota de pedido', function() { APP: {}, focaLoginService: {}, $localStorage: {}, - $watch: function() { } + $watch: function() { }, + $broadcast: function() {} }); scope.notaPedido = { @@ -642,17 +761,20 @@ describe('Controladores módulo crear nota de pedido', function() { proveedor:{ COD: true }, - moneda:{ - ID: true - }, cotizacion:{ - ID: true + ID: true, + moneda:{ + ID: true + } }, flete: true, domicilioStamp: true, domicilio: { id: true - } + }, + notaPedidoPlazo: [], + articulosNotaPedido: true, + fechaCarga: true }; scope.plazosPagos = true; @@ -660,7 +782,7 @@ describe('Controladores módulo crear nota de pedido', function() { //act spyOn(focaBotoneraLateralService, 'startGuardar'); - scope.crearNotaPedido(); + scope.crearNotaPedido(scope.notaPedido); //expect expect(focaBotoneraLateralService.startGuardar).toHaveBeenCalled(); @@ -669,7 +791,10 @@ describe('Controladores módulo crear nota de pedido', function() { it('funcion $scope.crearNotaPedido llama funciones al guardar', function(done) { //arrange - var scope = {}; + var scope = { + $watch: function() { }, + $broadcast: function() {} + }; var focaBotoneraLateralService = { startGuardar: function() { }, endGuardar: function() { } @@ -688,7 +813,11 @@ describe('Controladores módulo crear nota de pedido', function() { then: function() {} }; }, - crearNotaPedido: function() { }, + crearNotaPedido: function() { + return { + then: function() { } + }; + }, getNumeroNotaPedido: function() { return { then: function() { } @@ -704,7 +833,9 @@ describe('Controladores módulo crear nota de pedido', function() { $timeout: timeout, crearNotaPedidoService: crearNotaPedidoService, focaBotoneraLateralService: focaBotoneraLateralService, - focaModalService: {}, + focaModalService: { + alert: function() {} + }, notaPedidoBusinessService: notaPedidoBusinessService, $rootScope: { $on: function() { } @@ -713,7 +844,8 @@ describe('Controladores módulo crear nota de pedido', function() { APP: {}, focaLoginService: {}, $localStorage: {}, - $watch: function() { } + $watch: function() { }, + $broadcast: function() {} }); scope.notaPedido = { @@ -726,17 +858,20 @@ describe('Controladores módulo crear nota de pedido', function() { proveedor:{ COD: true }, - moneda:{ - ID: true - }, cotizacion:{ - ID: true + ID: true, + moneda:{ + ID: true + } }, flete: true, domicilioStamp: true, domicilio: { id: true - } + }, + notaPedidoPlazo: [], + articulosNotaPedido: [1], + fechaCarga: true }; scope.plazosPagos = []; @@ -750,13 +885,13 @@ describe('Controladores módulo crear nota de pedido', function() { spyOn(focaSeguimientoService, 'guardarPosicion'); spyOn(notaPedidoBusinessService, 'addArticulos'); scope.crearNotaPedido(); - //expect - promesa.then(function() { + crearNotaPedidoService.crearNotaPedido().then(function() { expect(focaSeguimientoService.guardarPosicion).toHaveBeenCalled(); expect(notaPedidoBusinessService.addArticulos).toHaveBeenCalled(); done(); - }); + }).catch(done); + }); }); }); diff --git a/src/js/controller.js b/src/js/controller.js index a50f511..4dc7655 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -55,15 +55,17 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { var monedaPorDefecto = res.data[0]; - $scope.cotizacionPorDefecto = Object.assign( + $scope.notaPedido.cotizacion = Object.assign( {moneda: monedaPorDefecto}, monedaPorDefecto.cotizaciones[0] ); - init(); - getLSNotaPedido(); + $scope.inicial.cotizacion = $scope.notaPedido.cotizacion; + }); - + + init(); + $timeout(function() {getLSNotaPedido();}); } @@ -77,8 +79,9 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', domicilio: {dom: ''}, vendedor: {}, fechaCarga: new Date(), - cotizacion: $scope.cotizacionPorDefecto, - articulosNotaPedido: [] + cotizacion: {}, + articulosNotaPedido: [], + notaPedidoPlazo: [] }; $scope.idLista = undefined; @@ -135,12 +138,12 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', } else if(!$scope.notaPedido.proveedor.COD) { focaModalService.alert('Ingrese Proveedor'); return; - } else if(!$scope.notaPedido.cotizacion.moneda.ID) { - focaModalService.alert('Ingrese Moneda'); - return; } else if(!$scope.notaPedido.cotizacion.ID) { focaModalService.alert('Ingrese Cotización'); return; + } else if(!$scope.notaPedido.cotizacion.moneda.ID) { + focaModalService.alert('Ingrese Moneda'); + return; } else if(!$scope.notaPedido.notaPedidoPlazo) { focaModalService.alert('Ingrese Precios y Condiciones'); return; @@ -674,7 +677,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', ); modalInstance.result.then( function(cotizacion) { - var articulosTablaTemp = $scope.notaPedido.articulosNotaPedido; + var articulosTablaTemp = $scope.notaPedido.articulosNotaPedido || []; for(var i = 0; i < articulosTablaTemp.length; i++) { articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * $scope.notaPedido.cotizacion.VENDEDOR; @@ -824,7 +827,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', ' - ' + notaPedido.proveedor.NOM }); } - if (notaPedido.notaPedidoPlazo) { + if (notaPedido.notaPedidoPlazo.length) { cabeceras.push({ label: 'Precios y condiciones:', valor: valorPrecioCondicion() + ' ' +