Commit 8028dbc69aa75bea6ca1a4a798b2b9bae92b7f8c
1 parent
c8aa436f17
Exists in
master
scripts testing
Showing
3 changed files
with
843 additions
and
0 deletions
Show diff stats
spec/controllerSpec.js
| ... | ... | @@ -0,0 +1,621 @@ |
| 1 | +describe('Controladores abm vehículo', function() { | |
| 2 | + | |
| 3 | + var $controller; | |
| 4 | + | |
| 5 | + beforeEach(function() { | |
| 6 | + module('focaAbmVehiculo'); | |
| 7 | + inject(function(_$controller_) { | |
| 8 | + $controller = _$controller_; | |
| 9 | + }); | |
| 10 | + }); | |
| 11 | + | |
| 12 | + describe('Controlador focaAbmVehiculosController', function() { | |
| 13 | + | |
| 14 | + it('Existe el controller focaAbmVehiculosController', function() { | |
| 15 | + //arrange | |
| 16 | + var controller = $controller('focaAbmVehiculosController', { | |
| 17 | + $scope: {}, | |
| 18 | + focaAbmVehiculoService: { | |
| 19 | + cleanCisternas: function() { return;}, | |
| 20 | + transportistaSeleccionado: {} | |
| 21 | + }, | |
| 22 | + $location: {}, | |
| 23 | + focaModalService: {}, | |
| 24 | + $uibModal: {}, | |
| 25 | + focaBotoneraLateralService: { | |
| 26 | + showSalir: function() { return; }, | |
| 27 | + showPausar: function() { return; }, | |
| 28 | + showCancelar: function() { return; }, | |
| 29 | + showGuardar: function() { return; }, | |
| 30 | + addCustomButton: function() { return; } | |
| 31 | + }, | |
| 32 | + $timeout: {} | |
| 33 | + }); | |
| 34 | + | |
| 35 | + //assert | |
| 36 | + expect(typeof controller).toEqual('object'); | |
| 37 | + }); | |
| 38 | + | |
| 39 | + it('Crea fecha nueva', function() { | |
| 40 | + //arrange | |
| 41 | + var scope = {}; | |
| 42 | + var controller = $controller('focaAbmVehiculosController', { | |
| 43 | + $scope: scope, | |
| 44 | + focaAbmVehiculoService: { | |
| 45 | + cleanCisternas: function() { return;}, | |
| 46 | + transportistaSeleccionado: {} | |
| 47 | + }, | |
| 48 | + $location: {}, | |
| 49 | + focaModalService: {}, | |
| 50 | + $uibModal: {}, | |
| 51 | + focaBotoneraLateralService: { | |
| 52 | + showSalir: function() { return; }, | |
| 53 | + showPausar: function() { return; }, | |
| 54 | + showCancelar: function() { return; }, | |
| 55 | + showGuardar: function() { return; }, | |
| 56 | + addCustomButton: function() { return; } | |
| 57 | + }, | |
| 58 | + $timeout: {} | |
| 59 | + }); | |
| 60 | + | |
| 61 | + //act | |
| 62 | + var date = scope.now; | |
| 63 | + | |
| 64 | + //assert | |
| 65 | + expect(angular.isDate(date)).toBe(true); | |
| 66 | + }); | |
| 67 | + | |
| 68 | + it('$scope setea botonera lateral', function() { | |
| 69 | + //arrange | |
| 70 | + var scope = {}; | |
| 71 | + var controller = $controller('focaAbmVehiculosController', { | |
| 72 | + $scope: scope, | |
| 73 | + focaAbmVehiculoService: { | |
| 74 | + cleanCisternas: function() { return;}, | |
| 75 | + transportistaSeleccionado: {} | |
| 76 | + }, | |
| 77 | + $location: {}, | |
| 78 | + focaModalService: {}, | |
| 79 | + $uibModal: {}, | |
| 80 | + focaBotoneraLateralService: { | |
| 81 | + showSalir: function() { return; }, | |
| 82 | + showPausar: function() { return; }, | |
| 83 | + showCancelar: function() { return; }, | |
| 84 | + showGuardar: function() { return; }, | |
| 85 | + addCustomButton: function() { return; } | |
| 86 | + }, | |
| 87 | + $timeout: {} | |
| 88 | + }); | |
| 89 | + | |
| 90 | + //act | |
| 91 | + var botonera = scope.botonera; | |
| 92 | + | |
| 93 | + //assert | |
| 94 | + expect(angular.isArray(botonera)).toBe(true); | |
| 95 | + }); | |
| 96 | + | |
| 97 | + it('$scope.editar lleva a la ruta correcta', function() { | |
| 98 | + inject(function($location) { | |
| 99 | + //arrange | |
| 100 | + var scope = {}; | |
| 101 | + var controller = $controller('focaAbmVehiculosController', { | |
| 102 | + $scope: scope, | |
| 103 | + focaAbmVehiculoService: { | |
| 104 | + cleanCisternas: function() { return;}, | |
| 105 | + transportistaSeleccionado: {} | |
| 106 | + }, | |
| 107 | + $location: $location, | |
| 108 | + focaModalService: {}, | |
| 109 | + $uibModal: {}, | |
| 110 | + focaBotoneraLateralService: { | |
| 111 | + showSalir: function() { return; }, | |
| 112 | + showPausar: function() { return; }, | |
| 113 | + showCancelar: function() { return; }, | |
| 114 | + showGuardar: function() { return; }, | |
| 115 | + addCustomButton: function() { return; } | |
| 116 | + }, | |
| 117 | + $timeout: {} | |
| 118 | + }); | |
| 119 | + | |
| 120 | + //act | |
| 121 | + scope.editar(1); | |
| 122 | + var esperado = '/vehiculo/' + 1 + '/' + scope.idTransportista; | |
| 123 | + | |
| 124 | + //assert | |
| 125 | + expect($location.url()).toEqual(esperado); | |
| 126 | + }); | |
| 127 | + }); | |
| 128 | + | |
| 129 | + it('Solicita confirmacion', function() { | |
| 130 | + //arrange | |
| 131 | + var scope = {}; | |
| 132 | + var focaModalService = { | |
| 133 | + confirm: function() {} | |
| 134 | + }; | |
| 135 | + var controller = $controller('focaAbmVehiculosController', { | |
| 136 | + $scope: scope, | |
| 137 | + focaAbmVehiculoService: { | |
| 138 | + cleanCisternas: function() { return;}, | |
| 139 | + transportistaSeleccionado: {} | |
| 140 | + }, | |
| 141 | + $location: {}, | |
| 142 | + focaModalService: focaModalService, | |
| 143 | + $uibModal: {}, | |
| 144 | + focaBotoneraLateralService: { | |
| 145 | + showSalir: function() { return; }, | |
| 146 | + showPausar: function() { return; }, | |
| 147 | + showCancelar: function() { return; }, | |
| 148 | + showGuardar: function() { return; }, | |
| 149 | + addCustomButton: function() { return; } | |
| 150 | + }, | |
| 151 | + $timeout: {} | |
| 152 | + }); | |
| 153 | + | |
| 154 | + //act | |
| 155 | + spyOn(focaModalService, 'confirm').and.returnValue({then: function() {}}); | |
| 156 | + scope.solicitarConfirmacion({id: 1, tractor: 'abc'}); | |
| 157 | + | |
| 158 | + //assert | |
| 159 | + expect(focaModalService.confirm).toHaveBeenCalled(); | |
| 160 | + }); | |
| 161 | + | |
| 162 | + it('Elimina vehículo al confirmar', function(done) { | |
| 163 | + | |
| 164 | + //arrange | |
| 165 | + var scope = { | |
| 166 | + vehiculos: [] | |
| 167 | + }; | |
| 168 | + var focaModalService = { | |
| 169 | + confirm: function() { return; } | |
| 170 | + }; | |
| 171 | + var focaAbmVehiculoService = { | |
| 172 | + cleanCisternas: function() { return;}, | |
| 173 | + transportistaSeleccionado: {}, | |
| 174 | + deleteVehiculo: function() { return; } | |
| 175 | + }; | |
| 176 | + var controller = $controller('focaAbmVehiculosController', { | |
| 177 | + $scope: scope, | |
| 178 | + focaAbmVehiculoService: focaAbmVehiculoService, | |
| 179 | + $location: {}, | |
| 180 | + focaModalService: focaModalService, | |
| 181 | + $uibModal: {}, | |
| 182 | + focaBotoneraLateralService: { | |
| 183 | + showSalir: function() { return; }, | |
| 184 | + showPausar: function() { return; }, | |
| 185 | + showCancelar: function() { return; }, | |
| 186 | + showGuardar: function() { return; }, | |
| 187 | + addCustomButton: function() { return; } | |
| 188 | + }, | |
| 189 | + $timeout: {} | |
| 190 | + }); | |
| 191 | + var promesa = Promise.resolve(true); | |
| 192 | + | |
| 193 | + //act | |
| 194 | + spyOn(focaModalService, 'confirm').and.returnValue(promesa); | |
| 195 | + spyOn(focaAbmVehiculoService, 'deleteVehiculo'); | |
| 196 | + scope.solicitarConfirmacion({id: 1, tractor: 'abc'}); | |
| 197 | + | |
| 198 | + //assert | |
| 199 | + promesa.then( | |
| 200 | + function() { | |
| 201 | + expect(focaAbmVehiculoService.deleteVehiculo).toHaveBeenCalled(); | |
| 202 | + done(); | |
| 203 | + } | |
| 204 | + ); | |
| 205 | + }); | |
| 206 | + | |
| 207 | + it('Se selecciona transportista', function() { | |
| 208 | + //arrange | |
| 209 | + var scope = {}; | |
| 210 | + var focaModalService = { | |
| 211 | + modal: function() {} | |
| 212 | + }; | |
| 213 | + var controller = $controller('focaAbmVehiculosController', { | |
| 214 | + $scope: scope, | |
| 215 | + focaAbmVehiculoService: { | |
| 216 | + cleanCisternas: function() { return;}, | |
| 217 | + transportistaSeleccionado: {} | |
| 218 | + }, | |
| 219 | + $location: {}, | |
| 220 | + focaModalService: focaModalService, | |
| 221 | + $uibModal: {}, | |
| 222 | + focaBotoneraLateralService: { | |
| 223 | + showSalir: function() { return; }, | |
| 224 | + showPausar: function() { return; }, | |
| 225 | + showCancelar: function() { return; }, | |
| 226 | + showGuardar: function() { return; }, | |
| 227 | + addCustomButton: function() { return; } | |
| 228 | + }, | |
| 229 | + $timeout: {} | |
| 230 | + }); | |
| 231 | + | |
| 232 | + //act | |
| 233 | + spyOn(focaModalService, 'modal').and.returnValue({then: function() {}}); | |
| 234 | + scope.seleccionarTransportista(); | |
| 235 | + | |
| 236 | + //assert | |
| 237 | + expect(focaModalService.modal).toHaveBeenCalled(); | |
| 238 | + }); | |
| 239 | + | |
| 240 | + it('Se setea el transportista seleccionado al service', function(done) { | |
| 241 | + inject(function($timeout) { | |
| 242 | + | |
| 243 | + //arrange | |
| 244 | + var scope = {}; | |
| 245 | + var focaModalService = { | |
| 246 | + modal: function() { return; } | |
| 247 | + }; | |
| 248 | + var focaAbmVehiculoService = { | |
| 249 | + cleanCisternas: function() { return;}, | |
| 250 | + transportistaSeleccionado: {}, | |
| 251 | + deleteVehiculo: function() { return; }, | |
| 252 | + getVehiculosPorTransportista: function() { | |
| 253 | + return { | |
| 254 | + then: function() { return; } | |
| 255 | + }; | |
| 256 | + } | |
| 257 | + }; | |
| 258 | + var controller = $controller('focaAbmVehiculosController', { | |
| 259 | + $scope: scope, | |
| 260 | + focaAbmVehiculoService: focaAbmVehiculoService, | |
| 261 | + $location: {}, | |
| 262 | + focaModalService: focaModalService, | |
| 263 | + $uibModal: {}, | |
| 264 | + focaBotoneraLateralService: { | |
| 265 | + showSalir: function() { return; }, | |
| 266 | + showPausar: function() { return; }, | |
| 267 | + showCancelar: function() { return; }, | |
| 268 | + showGuardar: function() { return; }, | |
| 269 | + addCustomButton: function() { return; } | |
| 270 | + }, | |
| 271 | + $timeout: $timeout | |
| 272 | + }); | |
| 273 | + var promesa = Promise.resolve({COD: '', NOM: ''}); | |
| 274 | + | |
| 275 | + //act | |
| 276 | + spyOn(focaModalService, 'modal').and.returnValue(promesa); | |
| 277 | + scope.seleccionarTransportista(); | |
| 278 | + | |
| 279 | + //assert | |
| 280 | + promesa.then( | |
| 281 | + function() { | |
| 282 | + expect(focaAbmVehiculoService.transportistaSeleccionado) | |
| 283 | + .toEqual(jasmine.objectContaining({ | |
| 284 | + COD: '', NOM: '' | |
| 285 | + })); | |
| 286 | + done(); | |
| 287 | + } | |
| 288 | + ); | |
| 289 | + }); | |
| 290 | + }); | |
| 291 | + }); | |
| 292 | + | |
| 293 | + describe('Controlador focaAbmVehiculoController', function() { | |
| 294 | + | |
| 295 | + var $timeout; | |
| 296 | + beforeEach(inject(function(_$timeout_) { | |
| 297 | + $timeout = _$timeout_; | |
| 298 | + })); | |
| 299 | + | |
| 300 | + it('Existe el controller focaAbmVehiculoController', function() { | |
| 301 | + | |
| 302 | + //arrange | |
| 303 | + var controller = $controller('focaAbmVehiculoController', { | |
| 304 | + $scope: {}, | |
| 305 | + focaAbmVehiculoService: { | |
| 306 | + getVehiculo: function() { | |
| 307 | + return { | |
| 308 | + then: function() { return; } | |
| 309 | + }; | |
| 310 | + } | |
| 311 | + }, | |
| 312 | + $routeParams: {}, | |
| 313 | + $location: {}, | |
| 314 | + $uibModal: {}, | |
| 315 | + focaModalService: {}, | |
| 316 | + $timeout: $timeout, | |
| 317 | + focaBotoneraLateralService: { | |
| 318 | + showSalir: function() { return; }, | |
| 319 | + showPausar: function() { return; }, | |
| 320 | + showCancelar: function() { return; }, | |
| 321 | + showGuardar: function() { return; }, | |
| 322 | + addCustomButton: function() { return; } | |
| 323 | + }, | |
| 324 | + $window: {} | |
| 325 | + }); | |
| 326 | + | |
| 327 | + //assert | |
| 328 | + expect(typeof controller).toEqual('object'); | |
| 329 | + | |
| 330 | + }); | |
| 331 | + | |
| 332 | + it('Se busca el transportista cuando es nuevo', function() { | |
| 333 | + | |
| 334 | + //arrange | |
| 335 | + var scope = {}; | |
| 336 | + var focaAbmVehiculoService = { | |
| 337 | + getVehiculo: function() { | |
| 338 | + return { | |
| 339 | + then: function() { return; } | |
| 340 | + }; | |
| 341 | + }, | |
| 342 | + getTransportistaPorId: function() { return; } | |
| 343 | + }; | |
| 344 | + | |
| 345 | + spyOn(focaAbmVehiculoService, 'getTransportistaPorId') | |
| 346 | + .and.returnValue({then: function() { return; }}); | |
| 347 | + | |
| 348 | + //act | |
| 349 | + var controller = $controller('focaAbmVehiculoController', { | |
| 350 | + $scope: scope, | |
| 351 | + focaAbmVehiculoService: focaAbmVehiculoService, | |
| 352 | + $routeParams: { | |
| 353 | + idVehiculo: '0' | |
| 354 | + }, | |
| 355 | + $location: {}, | |
| 356 | + $uibModal: {}, | |
| 357 | + focaModalService: {}, | |
| 358 | + $timeout: $timeout, | |
| 359 | + focaBotoneraLateralService: { | |
| 360 | + showSalir: function() { return; }, | |
| 361 | + showPausar: function() { return; }, | |
| 362 | + showCancelar: function() { return; }, | |
| 363 | + showGuardar: function() { return; }, | |
| 364 | + addCustomButton: function() { return; } | |
| 365 | + }, | |
| 366 | + $window: {} | |
| 367 | + }); | |
| 368 | + | |
| 369 | + //assert | |
| 370 | + expect(focaAbmVehiculoService.getTransportistaPorId).toHaveBeenCalled(); | |
| 371 | + }); | |
| 372 | + | |
| 373 | + it('No se busca el transportista cuando es nuevo', function() { | |
| 374 | + | |
| 375 | + //arrange | |
| 376 | + var scope = {}; | |
| 377 | + var focaAbmVehiculoService = { | |
| 378 | + getVehiculo: function() { | |
| 379 | + return { | |
| 380 | + then: function() { return; } | |
| 381 | + }; | |
| 382 | + }, | |
| 383 | + getTransportistaPorId: function() { return; } | |
| 384 | + }; | |
| 385 | + | |
| 386 | + spyOn(focaAbmVehiculoService, 'getTransportistaPorId') | |
| 387 | + .and.returnValue({then: function() { return; }}); | |
| 388 | + | |
| 389 | + //act | |
| 390 | + var controller = $controller('focaAbmVehiculoController', { | |
| 391 | + $scope: scope, | |
| 392 | + focaAbmVehiculoService: focaAbmVehiculoService, | |
| 393 | + $routeParams: {}, | |
| 394 | + $location: {}, | |
| 395 | + $uibModal: {}, | |
| 396 | + focaModalService: {}, | |
| 397 | + $timeout: $timeout, | |
| 398 | + focaBotoneraLateralService: { | |
| 399 | + showSalir: function() { return; }, | |
| 400 | + showPausar: function() { return; }, | |
| 401 | + showCancelar: function() { return; }, | |
| 402 | + showGuardar: function() { return; }, | |
| 403 | + addCustomButton: function() { return; } | |
| 404 | + }, | |
| 405 | + $window: {} | |
| 406 | + }); | |
| 407 | + | |
| 408 | + //assert | |
| 409 | + expect(focaAbmVehiculoService.getTransportistaPorId).not.toHaveBeenCalled(); | |
| 410 | + }); | |
| 411 | + | |
| 412 | + it('Cancelar lleva a la ruta /vehiculo', function() { | |
| 413 | + | |
| 414 | + inject(function($location) { | |
| 415 | + //arrange | |
| 416 | + var scope = {}; | |
| 417 | + var controller = $controller('focaAbmVehiculoController', { | |
| 418 | + $scope: scope, | |
| 419 | + focaAbmVehiculoService: { | |
| 420 | + getVehiculo: function() { | |
| 421 | + return { | |
| 422 | + then: function() { return; } | |
| 423 | + }; | |
| 424 | + } | |
| 425 | + }, | |
| 426 | + $routeParams: {}, | |
| 427 | + $location: $location, | |
| 428 | + $uibModal: {}, | |
| 429 | + focaModalService: {}, | |
| 430 | + $timeout: $timeout, | |
| 431 | + focaBotoneraLateralService: { | |
| 432 | + showSalir: function() { return; }, | |
| 433 | + showPausar: function() { return; }, | |
| 434 | + showCancelar: function() { return; }, | |
| 435 | + showGuardar: function() { return; }, | |
| 436 | + addCustomButton: function() { return; } | |
| 437 | + }, | |
| 438 | + $window: {} | |
| 439 | + }); | |
| 440 | + | |
| 441 | + //act | |
| 442 | + scope.cancelar(); | |
| 443 | + | |
| 444 | + //assert | |
| 445 | + expect($location.url()).toEqual('/vehiculo'); | |
| 446 | + }); | |
| 447 | + }); | |
| 448 | + | |
| 449 | + it('Editar lleva a la ruta correcta cuando recibe variable key', function() { | |
| 450 | + | |
| 451 | + inject(function($location) { | |
| 452 | + //arrange | |
| 453 | + var scope = {}; | |
| 454 | + var controller = $controller('focaAbmVehiculoController', { | |
| 455 | + $scope: scope, | |
| 456 | + focaAbmVehiculoService: { | |
| 457 | + getVehiculo: function() { | |
| 458 | + return { | |
| 459 | + then: function() { return; } | |
| 460 | + }; | |
| 461 | + } | |
| 462 | + }, | |
| 463 | + $routeParams: { | |
| 464 | + idVehiculo: 1 | |
| 465 | + }, | |
| 466 | + $location: $location, | |
| 467 | + $uibModal: {}, | |
| 468 | + focaModalService: {}, | |
| 469 | + $timeout: $timeout, | |
| 470 | + focaBotoneraLateralService: { | |
| 471 | + showSalir: function() { return; }, | |
| 472 | + showPausar: function() { return; }, | |
| 473 | + showCancelar: function() { return; }, | |
| 474 | + showGuardar: function() { return; }, | |
| 475 | + addCustomButton: function() { return; } | |
| 476 | + }, | |
| 477 | + $window: {} | |
| 478 | + }); | |
| 479 | + | |
| 480 | + //act | |
| 481 | + scope.editar('testing'); | |
| 482 | + var esperado = '/vehiculo/1/cisterna/testing'; | |
| 483 | + | |
| 484 | + //assert | |
| 485 | + expect($location.url()).toEqual(esperado); | |
| 486 | + }); | |
| 487 | + }); | |
| 488 | + | |
| 489 | + it('Editar lleva a la ruta correcta cuando no recibe variable key', function() { | |
| 490 | + | |
| 491 | + inject(function($location) { | |
| 492 | + //arrange | |
| 493 | + var scope = {}; | |
| 494 | + var controller = $controller('focaAbmVehiculoController', { | |
| 495 | + $scope: scope, | |
| 496 | + focaAbmVehiculoService: { | |
| 497 | + getVehiculo: function() { | |
| 498 | + return { | |
| 499 | + then: function() { return; } | |
| 500 | + }; | |
| 501 | + } | |
| 502 | + }, | |
| 503 | + $routeParams: { | |
| 504 | + idVehiculo: 1 | |
| 505 | + }, | |
| 506 | + $location: $location, | |
| 507 | + $uibModal: {}, | |
| 508 | + focaModalService: {}, | |
| 509 | + $timeout: $timeout, | |
| 510 | + focaBotoneraLateralService: { | |
| 511 | + showSalir: function() { return; }, | |
| 512 | + showPausar: function() { return; }, | |
| 513 | + showCancelar: function() { return; }, | |
| 514 | + showGuardar: function() { return; }, | |
| 515 | + addCustomButton: function() { return; } | |
| 516 | + }, | |
| 517 | + $window: {} | |
| 518 | + }); | |
| 519 | + | |
| 520 | + //act | |
| 521 | + scope.editar(); | |
| 522 | + var esperado = '/vehiculo/1/cisterna/0/'; | |
| 523 | + | |
| 524 | + //assert | |
| 525 | + expect($location.url()).toEqual(esperado); | |
| 526 | + }); | |
| 527 | + }); | |
| 528 | + | |
| 529 | + it('$scope.solicitarConfirmacionCisterna ejecuta modal de confirmación', function() { | |
| 530 | + | |
| 531 | + //arrange | |
| 532 | + var focaModalService = { | |
| 533 | + confirm: function() {} | |
| 534 | + }; | |
| 535 | + var scope = {}; | |
| 536 | + var controller = $controller('focaAbmVehiculoController', { | |
| 537 | + $scope: scope, | |
| 538 | + focaAbmVehiculoService: { | |
| 539 | + getVehiculo: function() { | |
| 540 | + return { | |
| 541 | + then: function() { return; } | |
| 542 | + }; | |
| 543 | + } | |
| 544 | + }, | |
| 545 | + $routeParams: { | |
| 546 | + idVehiculo: 1 | |
| 547 | + }, | |
| 548 | + $location: {}, | |
| 549 | + $uibModal: {}, | |
| 550 | + focaModalService: focaModalService, | |
| 551 | + $timeout: $timeout, | |
| 552 | + focaBotoneraLateralService: { | |
| 553 | + showSalir: function() { return; }, | |
| 554 | + showPausar: function() { return; }, | |
| 555 | + showCancelar: function() { return; }, | |
| 556 | + showGuardar: function() { return; }, | |
| 557 | + addCustomButton: function() { return; } | |
| 558 | + }, | |
| 559 | + $window: {} | |
| 560 | + }); | |
| 561 | + | |
| 562 | + //act | |
| 563 | + spyOn(focaModalService, 'confirm').and.returnValue({then: function() {}}); | |
| 564 | + scope.solicitarConfirmacionCisterna({id: 1, codigo: 'abc'}); | |
| 565 | + | |
| 566 | + //assert | |
| 567 | + expect(focaModalService.confirm).toHaveBeenCalled(); | |
| 568 | + }); | |
| 569 | + | |
| 570 | + it('Elimina y obtiene cisternas al dar confirmar', function(done) { | |
| 571 | + | |
| 572 | + //arrange | |
| 573 | + var scope = {}; | |
| 574 | + var focaModalService = { | |
| 575 | + confirm: function() {} | |
| 576 | + }; | |
| 577 | + var focaAbmVehiculoService = { | |
| 578 | + getVehiculo: function() { | |
| 579 | + return { | |
| 580 | + then: function() { return; } | |
| 581 | + }; | |
| 582 | + }, | |
| 583 | + getCisternas: function() { return; }, | |
| 584 | + deleteCisterna: function() { return; } | |
| 585 | + }; | |
| 586 | + var controller = $controller('focaAbmVehiculoController', { | |
| 587 | + $scope: scope, | |
| 588 | + focaAbmVehiculoService: focaAbmVehiculoService, | |
| 589 | + $routeParams: {}, | |
| 590 | + $location: {}, | |
| 591 | + $uibModal: {}, | |
| 592 | + focaModalService: focaModalService, | |
| 593 | + $timeout: $timeout, | |
| 594 | + focaBotoneraLateralService: { | |
| 595 | + showSalir: function() { return; }, | |
| 596 | + showPausar: function() { return; }, | |
| 597 | + showCancelar: function() { return; }, | |
| 598 | + showGuardar: function() { return; }, | |
| 599 | + addCustomButton: function() { return; } | |
| 600 | + }, | |
| 601 | + $window: {} | |
| 602 | + }); | |
| 603 | + var promesa = Promise.resolve(true); | |
| 604 | + | |
| 605 | + //act | |
| 606 | + spyOn(focaModalService, 'confirm').and.returnValue(promesa); | |
| 607 | + spyOn(focaAbmVehiculoService, 'deleteCisterna'); | |
| 608 | + spyOn(focaAbmVehiculoService, 'getCisternas').and.returnValue({ then: function() {} }); | |
| 609 | + scope.solicitarConfirmacionCisterna({id: 1, codigo: 'abc'}); | |
| 610 | + | |
| 611 | + //assert | |
| 612 | + promesa.then( | |
| 613 | + function() { | |
| 614 | + expect(focaAbmVehiculoService.deleteCisterna).toHaveBeenCalled(); | |
| 615 | + expect(focaAbmVehiculoService.getCisternas).toHaveBeenCalled(); | |
| 616 | + done(); | |
| 617 | + } | |
| 618 | + ); | |
| 619 | + }); | |
| 620 | + }); | |
| 621 | +}); |
spec/routeSpec.js
| ... | ... | @@ -0,0 +1,44 @@ |
| 1 | +describe('Route de abm vehículo', function() { | |
| 2 | + | |
| 3 | + var route; | |
| 4 | + | |
| 5 | + beforeEach(function() { | |
| 6 | + module('focaAbmVehiculo'); | |
| 7 | + inject(function($route) { | |
| 8 | + route = $route; | |
| 9 | + }); | |
| 10 | + }); | |
| 11 | + | |
| 12 | + it('Ruta /vehiculo dirige correctamente', function() { | |
| 13 | + //assert | |
| 14 | + expect(route.routes['/vehiculo'].controller) | |
| 15 | + .toBe('focaAbmVehiculosController'); | |
| 16 | + expect(route.routes['/vehiculo'].templateUrl) | |
| 17 | + .toBe('src/views/foca-abm-vehiculos-listado.html'); | |
| 18 | + }); | |
| 19 | + | |
| 20 | + it('Ruta /vehiculo/:idVehiculo/:idTransportista dirige correctamente', function() { | |
| 21 | + //assert | |
| 22 | + expect(route.routes['/vehiculo/:idVehiculo/:idTransportista'].controller) | |
| 23 | + .toBe('focaAbmVehiculoController'); | |
| 24 | + expect(route.routes['/vehiculo/:idVehiculo/:idTransportista'].templateUrl) | |
| 25 | + .toBe('src/views/foca-abm-vehiculos-item.html'); | |
| 26 | + }); | |
| 27 | + | |
| 28 | + it('Ruta /vehiculo/:idVehiculo dirige correctamente', function() { | |
| 29 | + //assert | |
| 30 | + expect(route.routes['/vehiculo/:idVehiculo'].controller) | |
| 31 | + .toBe('focaAbmVehiculoController'); | |
| 32 | + expect(route.routes['/vehiculo/:idVehiculo'].templateUrl) | |
| 33 | + .toBe('src/views/foca-abm-vehiculos-item.html'); | |
| 34 | + }); | |
| 35 | + | |
| 36 | + it('Ruta /vehiculo/:idVehiculo/cisterna/:idx dirige correctamente', function() { | |
| 37 | + //assert | |
| 38 | + expect(route.routes['/vehiculo/:idVehiculo/cisterna/:idx'].controller) | |
| 39 | + .toBe('focaAbmVehiculoCisternaController'); | |
| 40 | + expect(route.routes['/vehiculo/:idVehiculo/cisterna/:idx'].templateUrl) | |
| 41 | + .toBe('src/views/foca-abm-cisterna-item.html'); | |
| 42 | + }); | |
| 43 | + | |
| 44 | +}); |
spec/serviceSpec.js
| ... | ... | @@ -0,0 +1,178 @@ |
| 1 | +describe('Servicios de abm vehículo', function() { | |
| 2 | + | |
| 3 | + var servicio; | |
| 4 | + var httpBackend; | |
| 5 | + | |
| 6 | + beforeEach(function() { | |
| 7 | + module('focaAbmVehiculo'); | |
| 8 | + inject(module(function($provide) { | |
| 9 | + $provide.value('API_ENDPOINT', { | |
| 10 | + URL: 'localhost' | |
| 11 | + }); | |
| 12 | + })); | |
| 13 | + inject(function($httpBackend, _focaAbmVehiculoService_) { | |
| 14 | + httpBackend = $httpBackend; | |
| 15 | + servicio = _focaAbmVehiculoService_; | |
| 16 | + }); | |
| 17 | + }); | |
| 18 | + | |
| 19 | + describe('Servicio focaAbmVehiculoService', function() { | |
| 20 | + | |
| 21 | + it('Existe el servicio focaAbmVehiculoService', function() { | |
| 22 | + //assert | |
| 23 | + expect(typeof servicio).toEqual('object'); | |
| 24 | + }); | |
| 25 | + | |
| 26 | + it('función getVehiculos ejecuta $http.get correctamente', function() { | |
| 27 | + //arrange | |
| 28 | + var returnFake = { data: 'test' }; | |
| 29 | + var result; | |
| 30 | + httpBackend.expectGET('localhost/vehiculo').respond(returnFake); | |
| 31 | + | |
| 32 | + //act | |
| 33 | + servicio.getVehiculos().then(function(data) { | |
| 34 | + result = data.data; | |
| 35 | + }); | |
| 36 | + httpBackend.flush(); | |
| 37 | + | |
| 38 | + //assert | |
| 39 | + expect(result).toEqual(returnFake); | |
| 40 | + }); | |
| 41 | + | |
| 42 | + it('la función getVehiculo llama $http.get() correctamente', function() { | |
| 43 | + //arrange | |
| 44 | + var returnFake = { data: 'test' }; | |
| 45 | + var parametroPrueba = 1; | |
| 46 | + var result; | |
| 47 | + httpBackend.expectGET('localhost/vehiculo/' + parametroPrueba).respond(returnFake); | |
| 48 | + | |
| 49 | + //act | |
| 50 | + servicio.getVehiculo(parametroPrueba).then(function(data) { | |
| 51 | + result = data.data; | |
| 52 | + }); | |
| 53 | + httpBackend.flush(); | |
| 54 | + | |
| 55 | + //assert | |
| 56 | + expect(result).toEqual(returnFake); | |
| 57 | + }); | |
| 58 | + | |
| 59 | + it('la función getTransportistas llama $http.get() correctamente', function() { | |
| 60 | + //arrange | |
| 61 | + var returnFake = { data: 'test' }; | |
| 62 | + var result; | |
| 63 | + httpBackend.expectGET('localhost/transportista').respond(returnFake); | |
| 64 | + | |
| 65 | + //act | |
| 66 | + servicio.getTransportistas().then(function(data) { | |
| 67 | + result = data.data; | |
| 68 | + }); | |
| 69 | + httpBackend.flush(); | |
| 70 | + | |
| 71 | + //assert | |
| 72 | + expect(result).toEqual(returnFake); | |
| 73 | + }); | |
| 74 | + | |
| 75 | + it('Función guardarVehiculo llama $http.post() correctamente', function() { | |
| 76 | + //arrange | |
| 77 | + var returnFake = { data: 'test' }; | |
| 78 | + var bodyFake = { vehiculo: 1 }; | |
| 79 | + var result; | |
| 80 | + httpBackend | |
| 81 | + .expectPOST('localhost/vehiculo', JSON.stringify(bodyFake)) | |
| 82 | + .respond(returnFake); | |
| 83 | + | |
| 84 | + //act | |
| 85 | + servicio.guardarVehiculo(bodyFake.vehiculo).then(function(data) { | |
| 86 | + result = data.data; | |
| 87 | + }); | |
| 88 | + httpBackend.flush(); | |
| 89 | + | |
| 90 | + //assert | |
| 91 | + expect(result).toEqual(returnFake); | |
| 92 | + }); | |
| 93 | + | |
| 94 | + it('Función delete vehiculo ejecuta $http.delete correctamente', function() { | |
| 95 | + //arrange | |
| 96 | + var returnFake = { data: 'test' }; | |
| 97 | + var paramFake = 1; | |
| 98 | + var result; | |
| 99 | + httpBackend.expectDELETE('localhost/vehiculo/' +paramFake).respond(returnFake); | |
| 100 | + | |
| 101 | + //act | |
| 102 | + servicio.deleteVehiculo(paramFake).then(function(data) { | |
| 103 | + result = data.data; | |
| 104 | + }); | |
| 105 | + httpBackend.flush(); | |
| 106 | + | |
| 107 | + //assert | |
| 108 | + expect(result).toEqual(returnFake); | |
| 109 | + }); | |
| 110 | + | |
| 111 | + it('Función getCisternas devuelve una promesa', function() { | |
| 112 | + //arrange | |
| 113 | + var promesa = Promise.all([true]); | |
| 114 | + | |
| 115 | + //act | |
| 116 | + var espera = servicio.getCisternas(); | |
| 117 | + espera = espera.toString(); | |
| 118 | + promesa = promesa.toString(); | |
| 119 | + | |
| 120 | + //assert | |
| 121 | + expect(espera).toEqual(promesa); | |
| 122 | + }); | |
| 123 | + | |
| 124 | + it('Función guardarCisternas llama a post /cisterna', function() { | |
| 125 | + //arrange | |
| 126 | + var returnFake = { data: 'test' }; | |
| 127 | + var result; | |
| 128 | + var bodyFake = { cisternas: 1 }; | |
| 129 | + httpBackend.expectPOST('localhost/cisterna', JSON.stringify(bodyFake)) | |
| 130 | + .respond(returnFake); | |
| 131 | + | |
| 132 | + //act | |
| 133 | + servicio.guardarCisternas(bodyFake.cisternas).then(function(data) { | |
| 134 | + result = data.data; | |
| 135 | + }); | |
| 136 | + httpBackend.flush(); | |
| 137 | + | |
| 138 | + //assert | |
| 139 | + expect(result).toEqual(returnFake); | |
| 140 | + }); | |
| 141 | + | |
| 142 | + it('Funcion getVehiculosPorTransportista llama ruta correcta', function() { | |
| 143 | + //arrange | |
| 144 | + var returnFake = { data: 'test' }; | |
| 145 | + var paramFake = 1; | |
| 146 | + var result; | |
| 147 | + httpBackend.expectGET('localhost/vehiculo/transportista/' + paramFake) | |
| 148 | + .respond(returnFake); | |
| 149 | + | |
| 150 | + //act | |
| 151 | + servicio.getVehiculosPorTransportista(paramFake).then(function(data) { | |
| 152 | + result = data.data; | |
| 153 | + }); | |
| 154 | + httpBackend.flush(); | |
| 155 | + | |
| 156 | + //assert | |
| 157 | + expect(result).toEqual(returnFake); | |
| 158 | + }); | |
| 159 | + | |
| 160 | + it('Funcion getTransportistaPorId llama ruta correcta', function() { | |
| 161 | + //arrange | |
| 162 | + var returnFake = { data: 'test' }; | |
| 163 | + var paramFake = 1; | |
| 164 | + var result; | |
| 165 | + httpBackend.expectGET('localhost/transportista/' + paramFake) | |
| 166 | + .respond(returnFake); | |
| 167 | + | |
| 168 | + //act | |
| 169 | + servicio.getTransportistaPorId(paramFake).then(function(data) { | |
| 170 | + result = data.data; | |
| 171 | + }); | |
| 172 | + httpBackend.flush(); | |
| 173 | + | |
| 174 | + //assert | |
| 175 | + expect(result).toEqual(returnFake); | |
| 176 | + }); | |
| 177 | + }); | |
| 178 | +}); |