diff --git a/gulpfile.js b/gulpfile.js
index 8016f71..52da8c0 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -9,6 +9,8 @@ const pump = require('pump');
const jshint = require('gulp-jshint');
const replace = require('gulp-replace');
const connect = require('gulp-connect');
+const header = require('gulp-header');
+const footer = require('gulp-footer');
var paths = {
srcJS: 'src/js/*.js',
@@ -32,7 +34,7 @@ gulp.task('templates', ['clean'], function() {
);
});
-gulp.task('uglify', ['templates'], function() {
+gulp.task('uglify', ['templates', 'uglify-spec'], function() {
return pump(
[
gulp.src([
@@ -49,6 +51,17 @@ gulp.task('uglify', ['templates'], function() {
);
});
+gulp.task('uglify-spec', function() {
+ return pump([
+ gulp.src(paths.specs),
+ concat('foca-crear-nota-pedido.spec.js'),
+ replace("src/views/", ''),
+ header("describe('Módulo foca-crear-nota-pedido', function() { \n"),
+ footer("});"),
+ gulp.dest(paths.dist)
+ ]);
+});
+
gulp.task('clean', function() {
return gulp.src(['tmp', 'dist'], {read: false})
.pipe(clean());
@@ -75,7 +88,7 @@ gulp.task('webserver', function() {
gulp.task('clean-post-install', function() {
return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js',
- 'index.html'], {read: false})
+ 'index.html', 'test.html', 'spec'], {read: false})
.pipe(clean());
});
diff --git a/spec/controllerSpec.js b/spec/controllerSpec.js
new file mode 100644
index 0000000..06fbc68
--- /dev/null
+++ b/spec/controllerSpec.js
@@ -0,0 +1,1491 @@
+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 = {};
+ var uibModal = {
+ open: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: uibModal,
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: {},
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ 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 = {};
+ var uibModal = {
+ open: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: uibModal,
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: {},
+ notaPedidoBusinessService: {
+ plazoToString: function() { },
+ calcularArticulos: function() { }
+ },
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ 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 = {};
+ var focaModalService = {
+ alert: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+
+ //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 = {};
+ var uibModal = {
+ open: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: uibModal,
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: {},
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ 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 = {};
+ var focaModalService = {
+ alert: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ 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 = {};
+ var uibModal = {
+ open: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: uibModal,
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: {},
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ 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 = {};
+ var uibModal = {
+ open: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: uibModal,
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: {},
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ scope.idLista = true;
+ scope.notaPedido = {
+ cliente: { COD: true },
+ domicilio: { id: true }
+ };
+ 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 = {};
+ var focaModalService = {
+ modal: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ 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 = {};
+ var focaModalService = {
+ modal: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ 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 = {};
+ var focaModalService = {
+ modal: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ 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 = {};
+ var focaModalService = {
+ modal: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+
+ 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 alerta cuando no se elije vendedor', function() {
+ //arrange
+ var scope = {};
+ var focaModalService = {
+ alert: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ scope.notaPedido = {
+ vendedor: { NUM: false }
+ };
+
+ //act
+ spyOn(focaModalService, 'alert');
+ scope.seleccionarCliente();
+
+ //assert
+ expect(focaModalService.alert).toHaveBeenCalledWith('Primero seleccione un vendedor');
+ });
+
+ it('función seleccionarCliente abre modal', function() {
+ //arrange
+ var scope = {};
+ var uibModal = {
+ open: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: uibModal,
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: {},
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ 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 = {};
+ var uibModal = {
+ open: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: uibModal,
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: {},
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ 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 = {};
+ var uibModal = {
+ open: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: uibModal,
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: {},
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+
+ 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 = {};
+ var uibModal = {
+ open: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: uibModal,
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ },
+ getPuntosDescargaByClienDom: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: {},
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ 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
+ };
+
+ //act
+ spyOn(uibModal, 'open').and.returnValue(promesaRespuesta);
+ spyOn(scope, '$broadcast');
+ scope.abrirModalDomicilios({ });
+
+ //assert
+ promesaRespuesta.result.then(function() {
+ 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 = {};
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: {},
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ scope.idLista = true;
+ scope.notaPedido = {
+ vendedor: { NUM: true }
+ };
+
+ //act
+ scope.articulosTabla = [{ 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 = {};
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: {},
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ 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 = {};
+ var uibModal = {
+ open: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: uibModal,
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: {},
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+
+ scope.notaPedido = {};
+
+ 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 = {};
+ var uibModal = {
+ open: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: uibModal,
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: {},
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ scope.idLista = true;
+ scope.notaPedido = {
+ vendedor: { NUM: 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.articulosTabla.length).toEqual(0);
+ expect(scope.$broadcast).toHaveBeenCalled();
+ done();
+ });
+ });
+
+ it('función seleccionarFlete abre modal', function() {
+
+ //arrange
+ var scope = {};
+ var uibModal = {
+ open: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: uibModal,
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: {},
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+
+ scope.notaPedido = {};
+
+ var respuesta = { result: {then: function() { } } };
+
+ //act
+ spyOn(uibModal, 'open').and.returnValue(respuesta);
+ scope.seleccionarFlete();
+
+ //assert
+ expect(uibModal.open).toHaveBeenCalled();
+ });
+
+ it('función seleccionarFlete setea flete y cabecera', function(done) {
+
+ //arrange
+ var scope = {};
+ var uibModal = {
+ open: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: uibModal,
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: {},
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ scope.idLista = true;
+ scope.notaPedido = {
+ vendedor: { NUM: true }
+ };
+ var respuesta = { flete: 1, FOB: 2, bomba: 3, kilometros: 4 };
+ var promesaRespuesta = { result: Promise.resolve(respuesta) };
+ scope.$broadcast = function() { };
+
+ //act
+ spyOn(uibModal, 'open').and.returnValue(promesaRespuesta);
+ spyOn(scope, '$broadcast');
+ scope.seleccionarFlete();
+
+ //assert
+
+ promesaRespuesta.result.then(function() {
+ expect(scope.notaPedido.flete).toEqual(respuesta.flete);
+ expect(scope.notaPedido.fob).toEqual(respuesta.FOB);
+ expect(scope.notaPedido.bomba).toEqual(respuesta.bomba);
+ expect(scope.notaPedido.kilometros).toEqual(respuesta.kilometros);
+ expect(scope.$broadcast).toHaveBeenCalled();
+ done();
+ });
+ });
+
+ it('función seleccionarMoneda abre modal', function() {
+ //arrange
+ var scope = {};
+ var focaModalService = {
+ modal: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ 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 = {};
+ var focaModalService = {
+ modal: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+
+ 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 = {};
+ var focaModalService = {
+ prompt: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ 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 = {};
+ var focaModalService = {
+ prompt: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ 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 = {};
+ var uibModal = {
+ open: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: uibModal,
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: {},
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+
+ 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 = {};
+ var uibModal = {
+ open: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: uibModal,
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: {},
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+
+ 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.moneda).toEqual(moneda);
+ expect(scope.monedaDefecto).toEqual(moneda);
+ expect(scope.cotizacionDefecto).toEqual(cotizacion);
+ expect(scope.notaPedido.cotizacion).toEqual(cotizacion);
+ done();
+ });
+ });
+
+ it('función agregarATabla muestra alerta cuando a cargar undefined', function() {
+
+ //arrange
+ var scope = {};
+ var focaModalService = {
+ alert: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ 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 = {};
+ var focaModalService = {
+ alert: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+ 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 = {};
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: $location,
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: {},
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+
+ //act
+ scope.salir();
+
+ //assert
+ expect($location.url()).toEqual('/');
+ });
+ });
+ });
+});
diff --git a/spec/controllerSpecCrearPedido.js b/spec/controllerSpecCrearPedido.js
new file mode 100644
index 0000000..3a31139
--- /dev/null
+++ b/spec/controllerSpecCrearPedido.js
@@ -0,0 +1,738 @@
+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: {},
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() {}
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: {},
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+
+ //expect
+ expect(typeof controlador).toEqual('object');
+ });
+
+ it('la funcion $scope.crearNotaPedido muestra alerta cuando vendedor es null', function() {
+
+ //arrange
+ var scope = {};
+ var focaModalService = {
+ alert: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() {}
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+
+ //act
+ scope.notaPedido = {
+ vendedor: {
+ id: null
+ }
+ };
+ spyOn(focaModalService, 'alert');
+ scope.crearNotaPedido();
+
+ //expect
+ expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Vendedor');
+ });
+
+ it('la funcion $scope.crearNotaPedido muestra alerta cuando cliente es null', function() {
+
+ //arrange
+ var scope = {};
+ var focaModalService = {
+ alert: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() {}
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+
+ 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 = {};
+ var focaModalService = {
+ alert: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() {}
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+
+ 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 = {};
+ var focaModalService = {
+ alert: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() {}
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+
+ scope.notaPedido = {
+ vendedor: {
+ id: true
+ },
+ cliente:{
+ COD: true
+ },
+ proveedor:{
+ COD: 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 = {};
+ var focaModalService = {
+ alert: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() {}
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+
+ scope.notaPedido = {
+ vendedor: {
+ id: true
+ },
+ cliente:{
+ COD: true
+ },
+ proveedor:{
+ COD: true
+ },
+ moneda:{
+ ID: true
+ },
+ cotizacion:{
+ ID: null
+ }
+ };
+
+ //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 = {};
+ var focaModalService = {
+ alert: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() {}
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+
+ scope.notaPedido = {
+ vendedor: {
+ id: true
+ },
+ cliente:{
+ COD: true
+ },
+ proveedor:{
+ COD: true
+ },
+ moneda:{
+ ID: true
+ },
+ cotizacion:{
+ 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 = {};
+ var focaModalService = {
+ alert: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() {}
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+
+ scope.notaPedido = {
+ vendedor: {
+ id: true
+ },
+ cliente:{
+ COD: true
+ },
+ proveedor:{
+ COD: true
+ },
+ moneda:{
+ ID: true
+ },
+ cotizacion:{
+ ID: true
+ },
+ flete: null
+ };
+
+ 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 = {};
+ var focaModalService = {
+ alert: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() {}
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+
+ scope.notaPedido = {
+ vendedor: {
+ id: true
+ },
+ cliente:{
+ COD: true
+ },
+ proveedor:{
+ COD: true
+ },
+ moneda:{
+ ID: true
+ },
+ cotizacion:{
+ ID: true
+ },
+ flete: true,
+ domicilioStamp: null
+ };
+
+ 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 = {};
+ var focaModalService = {
+ alert: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() {}
+ };
+ }
+ },
+ focaBotoneraLateralService: {},
+ focaModalService: focaModalService,
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+
+ scope.notaPedido = {
+ vendedor: {
+ id: true
+ },
+ cliente:{
+ COD: true
+ },
+ proveedor:{
+ COD: true
+ },
+ moneda:{
+ ID: true
+ },
+ cotizacion:{
+ ID: true
+ },
+ flete: true,
+ domicilioStamp: true,
+ };
+
+ scope.plazosPagos = 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 = {};
+ var focaBotoneraLateralService = {
+ startGuardar: function() { }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: {
+ getBotonera: function() { },
+ getCotizacionByIdMoneda: function() {
+ return {
+ then: function() {}
+ };
+ },
+ crearNotaPedido: function() {
+ return {
+ then: function() { }
+ };
+ }
+ },
+ focaBotoneraLateralService: focaBotoneraLateralService,
+ focaModalService: {},
+ notaPedidoBusinessService: {},
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: {},
+ APP: {},
+ focaLoginService: {}
+ });
+
+ scope.notaPedido = {
+ vendedor: {
+ id: true
+ },
+ cliente:{
+ COD: true
+ },
+ proveedor:{
+ COD: true
+ },
+ moneda:{
+ ID: true
+ },
+ cotizacion:{
+ ID: true
+ },
+ flete: true,
+ domicilioStamp: true,
+ domicilio: {
+ id: true
+ }
+ };
+
+ scope.plazosPagos = true;
+ scope.articulosTabla = [1];
+
+ //act
+ spyOn(focaBotoneraLateralService, 'startGuardar');
+ scope.crearNotaPedido();
+
+ //expect
+ expect(focaBotoneraLateralService.startGuardar).toHaveBeenCalled();
+ });
+
+ it('funcion $scope.crearNotaPedido llama funciones al guardar', function(done) {
+
+ //arrange
+ var scope = {};
+ 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() { },
+ getNumeroNotaPedido: function() {
+ return {
+ then: function() { }
+ };
+ }
+ };
+
+ $controler('notaPedidoCtrl', {
+ $scope: scope,
+ $uibModal: {},
+ $location: {},
+ $filter: filter,
+ $timeout: timeout,
+ crearNotaPedidoService: crearNotaPedidoService,
+ focaBotoneraLateralService: focaBotoneraLateralService,
+ focaModalService: {},
+ notaPedidoBusinessService: notaPedidoBusinessService,
+ $rootScope: {
+ $on: function() { }
+ },
+ focaSeguimientoService: focaSeguimientoService,
+ APP: {},
+ focaLoginService: {}
+ });
+
+ scope.notaPedido = {
+ vendedor: {
+ id: true
+ },
+ cliente:{
+ COD: true
+ },
+ proveedor:{
+ COD: true
+ },
+ moneda:{
+ ID: true
+ },
+ cotizacion:{
+ ID: true
+ },
+ flete: true,
+ domicilioStamp: true,
+ domicilio: {
+ id: 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();
+ });
+ });
+ });
+});
\ No newline at end of file
diff --git a/src/js/service.js b/src/js/service.js
index 5d9adbf..3f5e412 100644
--- a/src/js/service.js
+++ b/src/js/service.js
@@ -1,5 +1,5 @@
angular.module('focaCrearNotaPedido')
- .service('crearNotaPedidoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) {
+ .factory('crearNotaPedidoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) {
var route = API_ENDPOINT.URL;
return {
crearNotaPedido: function(notaPedido) {
@@ -86,7 +86,7 @@ angular.module('focaCrearNotaPedido')
image: 'productos.png'
}
];
-
+
if(!vendedor) {
var botonVendedor = {
label: 'Vendedor',
diff --git a/test.html b/test.html
index 6c50ce2..c7f6198 100644
--- a/test.html
+++ b/test.html
@@ -15,6 +15,7 @@
+