describe('Controladores módulo crear hoja de ruta', function() { var $controller; beforeEach(function() { module('focaCrearHojaRuta'); inject(function(_$controller_) { $controller = _$controller_; }); }); describe('controlador focaModalDatosHojaRutaCtrl', function() { it('Existe el controlador focaModalDatosHojaRutaCtrl', function() { //act var controlador = $controller('focaModalDatosHojaRutaCtrl', { $filter: {}, $scope: {}, $uibModalInstance: {}, focaModalService: {}, parametrosDatos: {} }); //assert expect(typeof controlador).toEqual('object'); }); it('función $scope.aceptar muestra alerta cuando el formulario es inválido', function() { //arrange var scope = {}; var focaModalService = { alert: function() { } }; $controller('focaModalDatosHojaRutaCtrl', { $filter: {}, $scope: scope, $uibModalInstance: {}, focaModalService: focaModalService, parametrosDatos: {} }); //act scope.formDatosHojaRuta = { $valid: false }; spyOn(focaModalService, 'alert'); scope.aceptar(13); //assert expect(focaModalService.alert).toHaveBeenCalledWith('Formulario inválido'); }); it('función $scope.aceptar llama a uibModalInstance.close', function() { //arrange var scope = {}; var uibModalInstance = { close: function() { } }; $controller('focaModalDatosHojaRutaCtrl', { $filter: {}, $scope: scope, $uibModalInstance: uibModalInstance, focaModalService: {}, parametrosDatos: {} }); //act scope.formDatosHojaRuta = { $valid: true }; spyOn(uibModalInstance, 'close'); scope.aceptar(13); //assert expect(uibModalInstance.close).toHaveBeenCalled(); }); it('función $scope.next suma uno a focused', function() { //arrange var scope = {}; $controller('focaModalDatosHojaRutaCtrl', { $filter: {}, $scope: scope, $uibModalInstance: {}, focaModalService: {}, parametrosDatos: {} }); scope.focused = 1; //act var esperado = scope.focused + 1; scope.next(13); //assert expect(scope.focused).toEqual(esperado); }); it('función $scope.cancel llama a dismiss', function() { //arrange var scope = {}; var uibModalInstance = { dismiss: function() { } }; $controller('focaModalDatosHojaRutaCtrl', { $filter: {}, $scope: scope, $uibModalInstance: uibModalInstance, focaModalService: {}, parametrosDatos: {} }); //act spyOn(uibModalInstance, 'dismiss'); scope.cancel(); //assert expect(uibModalInstance.dismiss).toHaveBeenCalledWith('cancel'); }); }); describe('controlador hojaRutaCtrl', function() { var $filter = function() { return function() { }; }; var $timeout = function() { }; it('existe el controlador hojaRutaCtrl', function() { //act var controlador = $controller('hojaRutaCtrl', { $scope: { $broadcast: function() { }, $watch: function() {} }, $uibModal: {}, $location: {}, $filter: $filter, $timeout: $timeout, focaCrearHojaRutaService: { getBotonera: function() { }, getNumeroHojaRuta: function() { return { then: function() { } }; } }, focaModalService: {}, focaBotoneraLateralService: {}, focaLoginService: {}, $localStorage: function() {} }); //assert expect(typeof controlador).toEqual('object'); }); it('guardar hoja ruta valida que tenga al menos un remito', function() { //arrange var scope = { $broadcast: function() { }, $watch: function() {} }; var focaModalService = { alert: function() { } }; $controller('hojaRutaCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: $filter, $timeout: $timeout, focaCrearHojaRutaService: { getBotonera: function() { }, getNumeroHojaRuta: function() { return { then: function() { } }; } }, focaModalService: focaModalService, focaBotoneraLateralService: {}, focaLoginService: {}, $localStorage: function() {} }); scope.remitosTabla = []; //act spyOn(focaModalService, 'alert'); scope.crearHojaRuta(); //assert expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Remitos'); }); it('guardar hoja ruta valida que tenga chofer', function() { //arrange var scope = { $broadcast: function() { }, $watch: function() {} }; var focaModalService = { alert: function() { } }; $controller('hojaRutaCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: $filter, $timeout: $timeout, focaCrearHojaRutaService: { getBotonera: function() { }, getNumeroHojaRuta: function() { return { then: function() { } }; } }, focaModalService: focaModalService, focaBotoneraLateralService: {}, focaLoginService: {}, $localStorage: function() {} }); scope.hojaRuta = { chofer: { }, remitosTabla: [1] }; //act spyOn(focaModalService, 'alert'); scope.crearHojaRuta(); //assert expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Chofer'); }); it('guardar hoja ruta valida que tenga vehiculo', function() { //arrange var scope = { $broadcast: function() { }, $watch: function() {} }; var focaModalService = { alert: function() { } }; $controller('hojaRutaCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: $filter, $timeout: $timeout, focaCrearHojaRutaService: { getBotonera: function() { }, getNumeroHojaRuta: function() { return { then: function() { } }; } }, focaModalService: focaModalService, focaBotoneraLateralService: {}, focaLoginService: {}, $localStorage: function() {} }); scope.hojaRuta = { chofer: { id: true }, vehiculo: { }, remitosTabla: [1] }; //act spyOn(focaModalService, 'alert'); scope.crearHojaRuta(); //assert expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Vehiculo'); }); it('guardar hoja ruta valida que tenga transportista', function() { //arrange var scope = { $broadcast: function() { }, $watch: function() {} }; var focaModalService = { alert: function() { } }; $controller('hojaRutaCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: $filter, $timeout: $timeout, focaCrearHojaRutaService: { getBotonera: function() { }, getNumeroHojaRuta: function() { return { then: function() { } }; } }, focaModalService: focaModalService, focaBotoneraLateralService: {}, focaLoginService: {}, $localStorage: function() {} }); scope.hojaRuta = { chofer: { id: true }, vehiculo: { id: true }, transportista: { }, remitosTabla: [1] }; //act spyOn(focaModalService, 'alert'); scope.crearHojaRuta(); //assert expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Transportista'); }); it('guardar hoja ruta valida que tenga tarifario', function() { //arrange var scope = { $broadcast: function() { }, $watch: function() {} }; var focaModalService = { alert: function() { } }; $controller('hojaRutaCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: $filter, $timeout: $timeout, focaCrearHojaRutaService: { getBotonera: function() { }, getNumeroHojaRuta: function() { return { then: function() { } }; } }, focaModalService: focaModalService, focaBotoneraLateralService: {}, focaLoginService: {}, $localStorage: function() {} }); scope.hojaRuta = { chofer: { id: true }, vehiculo: { id: true }, transportista: { COD: true }, tarifario: { }, remitosTabla: [1] }; //act spyOn(focaModalService, 'alert'); scope.crearHojaRuta(); //assert expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Tarifario'); }); it('guardar hoja ruta valida que tenga datosExtra', function() { //arrange var scope = { $broadcast: function() { }, $watch: function() {} }; var focaModalService = { alert: function() { } }; $controller('hojaRutaCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: $filter, $timeout: $timeout, focaCrearHojaRutaService: { getBotonera: function() { }, getNumeroHojaRuta: function() { return { then: function() { } }; } }, focaModalService: focaModalService, focaBotoneraLateralService: {}, focaLoginService: {}, $localStorage: function() {} }); scope.hojaRuta = { chofer: { id: true }, vehiculo: { id: true }, transportista: { COD: true }, tarifario: { costo: true }, remitosTabla: [1] }; //act spyOn(focaModalService, 'alert'); scope.crearHojaRuta(); //assert expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Datos extra'); }); it('guardar hoja ruta llama focaCrearHojaRutaService.crearHojaRuta', function() { //arrange var scope = { $broadcast: function() { }, $watch: function() {} }; var focaCrearHojaRutaService = { getBotonera: function() { }, getNumeroHojaRuta: function() { return { then: function() { } }; }, crearHojaRuta: function() { } }; $controller('hojaRutaCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: $filter, $timeout: $timeout, focaCrearHojaRutaService: focaCrearHojaRutaService, focaModalService: {}, focaBotoneraLateralService: {}, focaLoginService: {}, $localStorage: function() {} }); scope.hojaRuta = { chofer: { id: true }, vehiculo: { id: true }, transportista: { COD: true }, tarifario: { costo: true }, datosExtra: { }, fechaReparto: new Date(), remitosTabla: [1] }; var respuesta = { then: function() { } }; //act spyOn(focaCrearHojaRutaService, 'crearHojaRuta').and.returnValue(respuesta); scope.crearHojaRuta(); //assert expect(focaCrearHojaRutaService.crearHojaRuta).toHaveBeenCalled(); }); it('seleccionarTransportista levanta modal y setea datos', function(done) { //arrange var scope = { $broadcast: function() { }, $watch: function() {} }; var focaModalService = { modal: function() { } }; $controller('hojaRutaCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: $filter, $timeout: $timeout, focaCrearHojaRutaService: { getBotonera: function() { }, getNumeroHojaRuta: function() { return { then: function() { } }; } }, focaModalService: focaModalService, focaBotoneraLateralService: {}, focaLoginService: {}, $localStorage: function() {} }); var respuesta = 1; var promesa = Promise.resolve(respuesta); //act spyOn(focaModalService, 'modal').and.returnValue(promesa); spyOn(scope, '$broadcast'); scope.seleccionarTransportista(); //assert promesa.then(function() { expect(focaModalService.modal).toHaveBeenCalled(); expect(scope.$broadcast).toHaveBeenCalled(); expect(scope.hojaRuta.transportista).toEqual(respuesta); done(); }); }); it('seleccionarChofer levanta modal y setea datos', function(done) { //arrange var scope = { $broadcast: function() { }, $watch: function() {} }; var focaModalService = { modal: function() { } }; $controller('hojaRutaCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: $filter, $timeout: $timeout, focaCrearHojaRutaService: { getBotonera: function() { }, getNumeroHojaRuta: function() { return { then: function() { } }; } }, focaModalService: focaModalService, focaBotoneraLateralService: {}, focaLoginService: {}, $localStorage: function() {} }); var respuesta = 1; var promesa = Promise.resolve(respuesta); //act spyOn(focaModalService, 'modal').and.returnValue(promesa); spyOn(scope, '$broadcast'); scope.seleccionarChofer(); //assert promesa.then(function() { expect(focaModalService.modal).toHaveBeenCalled(); expect(scope.$broadcast).toHaveBeenCalled(); expect(scope.hojaRuta.chofer).toEqual(respuesta); done(); }); }); it('seleccionarTarifario levanta modal y setea datos', function(done) { //arrange var scope = { $broadcast: function() { }, $watch: function() {} }; var uibModal = { open: function() { } }; $controller('hojaRutaCtrl', { $scope: scope, $uibModal: uibModal, $location: {}, $filter: $filter, $timeout: $timeout, focaCrearHojaRutaService: { getBotonera: function() { }, getNumeroHojaRuta: function() { return { then: function() { } }; } }, focaModalService: {}, focaBotoneraLateralService: {}, focaLoginService: {}, $localStorage: function() {} }); var respuesta = 1; var promesa = { result: Promise.resolve(respuesta) }; //act spyOn(uibModal, 'open').and.returnValue(promesa); spyOn(scope, '$broadcast'); scope.seleccionarTarifario(); //assert promesa.result.then(function() { expect(uibModal.open).toHaveBeenCalled(); expect(scope.$broadcast).toHaveBeenCalled(); expect(scope.hojaRuta.tarifario).toEqual(respuesta); done(); }); }); it('seleccionarRemitos levanta modal y setea datos', function(done) { //arrange var scope = { $broadcast: function() { }, $watch: function() {} }; var uibModal = { open: function() { } }; $controller('hojaRutaCtrl', { $scope: scope, $uibModal: uibModal, $location: {}, $filter: $filter, $timeout: $timeout, focaCrearHojaRutaService: { getBotonera: function() { }, getNumeroHojaRuta: function() { return { then: function() { } }; } }, focaModalService: { alert: function() {} }, focaBotoneraLateralService: {}, focaLoginService: {}, $localStorage: function() {} }); scope.eligioPreConfirmado = false; scope.hojaRuta = { vehiculo: { id: true }, fechaReparto: true }; var respuesta = 1; var promesa = { result: Promise.resolve(respuesta) }; //act spyOn(uibModal, 'open').and.returnValue(promesa); scope.seleccionarRemitos(); //assert promesa.result.then(function() { expect(uibModal.open).toHaveBeenCalled(); done(); }); }); it('seleccionarVehiculosPrecargados levanta modal y setea datos', function(done) { //arrange var scope = { $broadcast: function() { }, $watch: function() {} }; var focaModalService = { modal: function() { }, alert: function() { } }; var focaCrearHojaRutaService = { getBotonera: function() { }, getNumeroHojaRuta: function() { return { then: function() { } }; }, getRemitosByIdVehiculo: function() { return { then: function() { } }; } }; $controller('hojaRutaCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: $filter, $timeout: $timeout, focaCrearHojaRutaService: focaCrearHojaRutaService, focaModalService: focaModalService, focaBotoneraLateralService: {}, focaLoginService: {}, $localStorage: function() {} }); scope.eligioPreConfirmado = false; scope.hojaRuta = { fechaReparto: new Date() } var respuesta = { transportista: { } }; var promesa = Promise.resolve(respuesta); //act spyOn(focaModalService, 'modal') .and.returnValue(promesa); spyOn(focaCrearHojaRutaService, 'getRemitosByIdVehiculo') .and.returnValue( { then: function() { } } ); spyOn(scope, '$broadcast'); scope.seleccionarVehiculosPrecargados(); //assert promesa.then(function() { expect(focaModalService.modal).toHaveBeenCalled(); expect(focaCrearHojaRutaService.getRemitosByIdVehiculo).toHaveBeenCalled(); expect(scope.$broadcast).toHaveBeenCalled(); done(); }); }); it('cargarCisterna levanta modal y devuelve promesa', function(done) { //arrange var scope = { $broadcast: function() { }, $watch: function() {} }; var uibModal = { open: function() { } }; $controller('hojaRutaCtrl', { $scope: scope, $uibModal: uibModal, $location: {}, $filter: $filter, $timeout: $timeout, focaCrearHojaRutaService: { getBotonera: function() { }, getNumeroHojaRuta: function() { return { then: function() { } }; } }, focaModalService: { alert: function() {} }, focaBotoneraLateralService: {}, focaLoginService: {}, $localStorage: function() {} }); scope.eligioPreConfirmado = false; scope.hojaRuta = { vehiculo: { id: true }, fechaReparto: true }; var respuesta = 1; var promesa = { result: Promise.resolve(respuesta) }; //act spyOn(uibModal, 'open').and.returnValue(promesa); var resultado = scope.cargarCisterna(); //assert promesa.result.then(function() { expect(uibModal.open).toHaveBeenCalled(); expect(typeof resultado).toEqual('object'); done(); }); }); it('seleccionarFechaEntrega levanta modal', function(done) { //arrange var scope = { $broadcast: function() { }, $watch: function() {} }; var focaModalService = { modalFecha: function() { } }; $controller('hojaRutaCtrl', { $scope: scope, $uibModal: {}, $location: {}, $filter: $filter, $timeout: $timeout, focaCrearHojaRutaService: { getBotonera: function() { }, getNumeroHojaRuta: function() { return { then: function() { } }; } }, focaModalService: focaModalService, focaBotoneraLateralService: {}, focaLoginService: {}, $localStorage: function() {} }); var respuesta = new Date(); var promesa = Promise.resolve(respuesta); //act spyOn(focaModalService, 'modalFecha').and.returnValue(promesa); spyOn(scope, '$broadcast'); scope.seleccionarFechaEntrega(); //assert promesa.then(function() { expect(focaModalService.modalFecha).toHaveBeenCalled(); expect(scope.$broadcast).toHaveBeenCalled(); done(); }); }); }); });