Commit 2549988554fd4afebe60ea7de80be6b19678a30c
1 parent
9089fe2a16
Exists in
master
and in
2 other branches
archivos spec
Showing
4 changed files
with
527 additions
and
0 deletions
Show diff stats
spec/controllerSpec.js
| File was created | 1 | describe('Controladores de abm chofer', function() { | |
| 2 | |||
| 3 | var $controller; | ||
| 4 | |||
| 5 | beforeEach(function() { | ||
| 6 | module('focaAbmChofer'); | ||
| 7 | inject(function(_$controller_) { | ||
| 8 | $controller = _$controller_; | ||
| 9 | }); | ||
| 10 | }); | ||
| 11 | |||
| 12 | describe('Controlador focaAbmChoferesController', function() { | ||
| 13 | |||
| 14 | it('Existe el controlador focaAbmChoferesController', function() { | ||
| 15 | //arrange | ||
| 16 | var controlador = $controller('focaAbmChoferesController', { | ||
| 17 | $scope: {}, | ||
| 18 | focaAbmChoferService: { | ||
| 19 | transportistaSeleccionado: function() { return; } | ||
| 20 | }, | ||
| 21 | $location: {}, | ||
| 22 | $uibModal: {}, | ||
| 23 | focaModalService: {}, | ||
| 24 | focaBotoneraLateralService: {}, | ||
| 25 | $timeout: function() { return; } | ||
| 26 | }); | ||
| 27 | |||
| 28 | //assert | ||
| 29 | expect(typeof controlador).toEqual('object'); | ||
| 30 | }); | ||
| 31 | |||
| 32 | it('$scope.solicitarConfirmacion levanta modal de confirmacion', function() { | ||
| 33 | //arrange | ||
| 34 | var fakeParam = ''; | ||
| 35 | var scope = {}; | ||
| 36 | var focaModalService = { | ||
| 37 | confirm: function() { } | ||
| 38 | }; | ||
| 39 | var controlador = $controller('focaAbmChoferesController', { | ||
| 40 | $scope: scope, | ||
| 41 | focaAbmChoferService: { | ||
| 42 | transportistaSeleccionado: function() { return; } | ||
| 43 | }, | ||
| 44 | $location: {}, | ||
| 45 | $uibModal: {}, | ||
| 46 | focaModalService: focaModalService, | ||
| 47 | focaBotoneraLateralService: {}, | ||
| 48 | $timeout: function() { return; } | ||
| 49 | }); | ||
| 50 | console.info(controlador); | ||
| 51 | |||
| 52 | //act | ||
| 53 | spyOn(focaModalService, 'confirm').and.returnValue({ then: function() { }}); | ||
| 54 | scope.solicitarConfirmacion(fakeParam); | ||
| 55 | |||
| 56 | //assert | ||
| 57 | expect(focaModalService.confirm).toHaveBeenCalled(); | ||
| 58 | }); | ||
| 59 | |||
| 60 | it('$scope.solicitarConfirmacion elimina al confirmar', function(done) { | ||
| 61 | //arrange | ||
| 62 | var scope = {}; | ||
| 63 | var focaModalService = { | ||
| 64 | confirm: function() { | ||
| 65 | return { | ||
| 66 | then: function() { } | ||
| 67 | }; | ||
| 68 | } | ||
| 69 | }; | ||
| 70 | var focaAbmChoferService = { | ||
| 71 | transportistaSeleccionado: function() { return; }, | ||
| 72 | deleteChofer: function() { } | ||
| 73 | }; | ||
| 74 | var controlador = $controller('focaAbmChoferesController', { | ||
| 75 | $scope: scope, | ||
| 76 | focaAbmChoferService: focaAbmChoferService, | ||
| 77 | $location: {}, | ||
| 78 | $uibModal: {}, | ||
| 79 | focaModalService: focaModalService, | ||
| 80 | focaBotoneraLateralService: {}, | ||
| 81 | $timeout: function() { return; } | ||
| 82 | }); | ||
| 83 | console.info(controlador); | ||
| 84 | var fakeParam = ''; | ||
| 85 | var promesa = Promise.resolve(true); | ||
| 86 | |||
| 87 | //act | ||
| 88 | spyOn(focaModalService, 'confirm').and.returnValue(promesa); | ||
| 89 | spyOn(focaAbmChoferService, 'deleteChofer'); | ||
| 90 | scope.solicitarConfirmacion(fakeParam); | ||
| 91 | |||
| 92 | //assert | ||
| 93 | promesa.then(function() { | ||
| 94 | expect(focaAbmChoferService.deleteChofer).toHaveBeenCalled(); | ||
| 95 | done(); | ||
| 96 | }); | ||
| 97 | }); | ||
| 98 | |||
| 99 | it('$scope.seleccionarTransportista levanta modal', function() { | ||
| 100 | //arrange | ||
| 101 | var scope = {}; | ||
| 102 | var focaModalService = { | ||
| 103 | modal: function() { } | ||
| 104 | }; | ||
| 105 | var controlador = $controller('focaAbmChoferesController', { | ||
| 106 | $scope: scope, | ||
| 107 | focaAbmChoferService: { | ||
| 108 | transportistaSeleccionado: function() { } | ||
| 109 | }, | ||
| 110 | $location: {}, | ||
| 111 | $uibModal: {}, | ||
| 112 | focaModalService: focaModalService, | ||
| 113 | focaBotoneraLateralService: {}, | ||
| 114 | $timeout: function() { return; } | ||
| 115 | }); | ||
| 116 | console.info(controlador); | ||
| 117 | |||
| 118 | //act | ||
| 119 | spyOn(focaModalService, 'modal').and.returnValue({ then: function() { }}); | ||
| 120 | scope.seleccionarTransportista(); | ||
| 121 | |||
| 122 | //assert | ||
| 123 | expect(focaModalService.modal).toHaveBeenCalled(); | ||
| 124 | }); | ||
| 125 | }); | ||
| 126 | |||
| 127 | describe('Controlador focaAbmChoferController', function() { | ||
| 128 | |||
| 129 | it('Existe el controlador focaAbmChoferController', function() { | ||
| 130 | //arrange | ||
| 131 | var controlador = $controller('focaAbmChoferController', { | ||
| 132 | $scope: {}, | ||
| 133 | focaAbmChoferService: { | ||
| 134 | getTiposDocumento: function() { | ||
| 135 | return { | ||
| 136 | then: function() { } | ||
| 137 | }; | ||
| 138 | }, | ||
| 139 | getChofer: function() { | ||
| 140 | return { | ||
| 141 | then: function() { } | ||
| 142 | }; | ||
| 143 | }, | ||
| 144 | getTransportistas: function() { | ||
| 145 | return { | ||
| 146 | then: function() { } | ||
| 147 | }; | ||
| 148 | } | ||
| 149 | }, | ||
| 150 | $routeParams: {}, | ||
| 151 | $location: {}, | ||
| 152 | focaBotoneraLateralService: {}, | ||
| 153 | $timeout: function() { return; }, | ||
| 154 | focaModalService: {} | ||
| 155 | }); | ||
| 156 | |||
| 157 | //assert | ||
| 158 | expect(typeof controlador).toEqual('object'); | ||
| 159 | }); | ||
| 160 | |||
| 161 | it('$scope.cancelar lleva a la ruta correcta', function() { | ||
| 162 | inject(function($location) { | ||
| 163 | //arrange | ||
| 164 | var scope = {}; | ||
| 165 | var controlador = $controller('focaAbmChoferController', { | ||
| 166 | $scope: scope, | ||
| 167 | focaAbmChoferService: { | ||
| 168 | getTiposDocumento: function() { | ||
| 169 | return { | ||
| 170 | then: function() { } | ||
| 171 | }; | ||
| 172 | }, | ||
| 173 | getChofer: function() { | ||
| 174 | return { | ||
| 175 | then: function() { } | ||
| 176 | }; | ||
| 177 | }, | ||
| 178 | getTransportistas: function() { | ||
| 179 | return { | ||
| 180 | then: function() { } | ||
| 181 | }; | ||
| 182 | } | ||
| 183 | }, | ||
| 184 | $routeParams: {}, | ||
| 185 | $location: $location, | ||
| 186 | focaBotoneraLateralService: {}, | ||
| 187 | $timeout: function() { return; }, | ||
| 188 | focaModalService: {} | ||
| 189 | }); | ||
| 190 | console.info(controlador); | ||
| 191 | |||
| 192 | //act | ||
| 193 | scope.cancelar(); | ||
| 194 | |||
| 195 | //assert | ||
| 196 | expect($location.url()).toEqual('/chofer'); | ||
| 197 | }); | ||
| 198 | }); | ||
| 199 | |||
| 200 | it('$scope.guardar guarda chofer al validarDNI() da ok', function(done) { | ||
| 201 | |||
| 202 | //arrange | ||
| 203 | var scope = {}; | ||
| 204 | var focaAbmChoferService = { | ||
| 205 | getTiposDocumento: function() { | ||
| 206 | return { | ||
| 207 | then: function() { } | ||
| 208 | }; | ||
| 209 | }, | ||
| 210 | getChofer: function() { | ||
| 211 | return { | ||
| 212 | then: function() { } | ||
| 213 | }; | ||
| 214 | }, | ||
| 215 | getTransportistas: function() { | ||
| 216 | return { | ||
| 217 | then: function() { } | ||
| 218 | }; | ||
| 219 | }, | ||
| 220 | guardarChofer: function() { }, | ||
| 221 | getChoferPorDni: function() { } | ||
| 222 | }; | ||
| 223 | var controlador = $controller('focaAbmChoferController', { | ||
| 224 | $scope: scope, | ||
| 225 | focaAbmChoferService: focaAbmChoferService, | ||
| 226 | $routeParams: {}, | ||
| 227 | $location: {}, | ||
| 228 | focaBotoneraLateralService: {}, | ||
| 229 | $timeout: function() { return; }, | ||
| 230 | focaModalService: {} | ||
| 231 | }); | ||
| 232 | console.info(controlador); | ||
| 233 | var resolveFake = { data: false }; | ||
| 234 | var promesaChoferPorDni = Promise.resolve(resolveFake); | ||
| 235 | |||
| 236 | //act | ||
| 237 | spyOn(focaAbmChoferService, 'guardarChofer').and.returnValue({ then: function() { }}); | ||
| 238 | spyOn(focaAbmChoferService, 'getChoferPorDni').and.returnValue(promesaChoferPorDni); | ||
| 239 | scope.guardar(13); | ||
| 240 | |||
| 241 | //assert | ||
| 242 | promesaChoferPorDni.then(function() { | ||
| 243 | setTimeout(function() { | ||
| 244 | expect(focaAbmChoferService.guardarChofer).toHaveBeenCalled(); | ||
| 245 | done(); | ||
| 246 | }); | ||
| 247 | }); | ||
| 248 | }); | ||
| 249 | |||
| 250 | it('$scope.guardar da alerta chofer al validarDNI() da reject', function(done) { | ||
| 251 | |||
| 252 | //arrange | ||
| 253 | var scope = {}; | ||
| 254 | var focaModalService = { | ||
| 255 | alert: function() { } | ||
| 256 | }; | ||
| 257 | var focaAbmChoferService = { | ||
| 258 | getTiposDocumento: function() { | ||
| 259 | return { | ||
| 260 | then: function() { } | ||
| 261 | }; | ||
| 262 | }, | ||
| 263 | getChofer: function() { | ||
| 264 | return { | ||
| 265 | then: function() { } | ||
| 266 | }; | ||
| 267 | }, | ||
| 268 | getTransportistas: function() { | ||
| 269 | return { | ||
| 270 | then: function() { } | ||
| 271 | }; | ||
| 272 | }, | ||
| 273 | getChoferPorDni: function() { } | ||
| 274 | }; | ||
| 275 | var controlador = $controller('focaAbmChoferController', { | ||
| 276 | $scope: scope, | ||
| 277 | focaAbmChoferService: focaAbmChoferService, | ||
| 278 | $routeParams: {}, | ||
| 279 | $location: {}, | ||
| 280 | focaBotoneraLateralService: {}, | ||
| 281 | $timeout: function() { return; }, | ||
| 282 | focaModalService: focaModalService | ||
| 283 | }); | ||
| 284 | console.info(controlador); | ||
| 285 | var resolveFake = { data: { id: true } }; | ||
| 286 | var promesaChoferPorDni = Promise.resolve(resolveFake); | ||
| 287 | |||
| 288 | //act | ||
| 289 | spyOn(focaAbmChoferService, 'getChoferPorDni').and.returnValue(promesaChoferPorDni); | ||
| 290 | spyOn(focaModalService, 'alert'); | ||
| 291 | scope.chofer.id = 'dato prueba'; | ||
| 292 | scope.guardar(13); | ||
| 293 | |||
| 294 | //assert | ||
| 295 | promesaChoferPorDni.then(function() { | ||
| 296 | //await sleep(100); | ||
| 297 | setTimeout(function() { | ||
| 298 | expect(focaModalService.alert).toHaveBeenCalled(); | ||
| 299 | done(); | ||
| 300 | }); | ||
| 301 | }); | ||
| 302 | }); | ||
| 303 | }); | ||
| 304 | }); | ||
| 305 |
spec/routeSpec.js
| File was created | 1 | describe('Rutas abm chofer', function() { | |
| 2 | |||
| 3 | var route; | ||
| 4 | |||
| 5 | beforeEach(function() { | ||
| 6 | module('focaAbmChofer'); | ||
| 7 | inject(function($route) { | ||
| 8 | route = $route; | ||
| 9 | }); | ||
| 10 | }); | ||
| 11 | |||
| 12 | it('ruta /chofer redirecciona correctamente', function() { | ||
| 13 | //assert | ||
| 14 | expect(route.routes['/chofer'].controller) | ||
| 15 | .toBe('focaAbmChoferesController'); | ||
| 16 | expect(route.routes['/chofer'].templateUrl) | ||
| 17 | .toBe('src/views/foca-abm-choferes-listado.html'); | ||
| 18 | }); | ||
| 19 | |||
| 20 | it('ruta /chofer/:id/:idTransportista redirecciona correctamente', function() { | ||
| 21 | //assert | ||
| 22 | expect(route.routes['/chofer/:id/:idTransportista'].controller) | ||
| 23 | .toBe('focaAbmChoferController'); | ||
| 24 | expect(route.routes['/chofer/:id/:idTransportista'].templateUrl) | ||
| 25 | .toBe('src/views/foca-abm-choferes-item.html'); | ||
| 26 | }); | ||
| 27 | }); | ||
| 28 |
spec/serviceSpec.js
| File was created | 1 | describe('Servicios de foca abm chofer', function() { | |
| 2 | |||
| 3 | var httpBackend; | ||
| 4 | var servicio; | ||
| 5 | |||
| 6 | beforeEach(function() { | ||
| 7 | module('focaAbmChofer'); | ||
| 8 | inject(module(function($provide) { | ||
| 9 | $provide.value('API_ENDPOINT', { | ||
| 10 | URL: 'localhost' | ||
| 11 | }); | ||
| 12 | })); | ||
| 13 | inject(function($httpBackend, _focaAbmChoferService_) { | ||
| 14 | servicio = _focaAbmChoferService_; | ||
| 15 | httpBackend = $httpBackend; | ||
| 16 | }); | ||
| 17 | }); | ||
| 18 | |||
| 19 | describe('Servicio focaAbmChoferService', function() { | ||
| 20 | it('Existe el servicio', function() { | ||
| 21 | //assert | ||
| 22 | expect(typeof servicio).toEqual('object'); | ||
| 23 | }); | ||
| 24 | |||
| 25 | it('La función getChoferes lleva a la ruta correcta', function() { | ||
| 26 | //arrange | ||
| 27 | var returnFake = 'test'; | ||
| 28 | var result; | ||
| 29 | httpBackend.expectGET('localhost/chofer').respond(returnFake); | ||
| 30 | |||
| 31 | //act | ||
| 32 | servicio.getChoferes().then(function(data) { | ||
| 33 | result = data.data; | ||
| 34 | }); | ||
| 35 | httpBackend.flush(); | ||
| 36 | |||
| 37 | expect(result).toEqual(returnFake); | ||
| 38 | }); | ||
| 39 | |||
| 40 | it('La función getChofer lleva a la ruta correcta', function() { | ||
| 41 | //arrange | ||
| 42 | var returnFake = 'test'; | ||
| 43 | var paramFake = 1; | ||
| 44 | var result; | ||
| 45 | httpBackend.expectGET('localhost/chofer/' + paramFake).respond(returnFake); | ||
| 46 | |||
| 47 | //act | ||
| 48 | servicio.getChofer(paramFake).then(function(data) { | ||
| 49 | result = data.data; | ||
| 50 | }); | ||
| 51 | httpBackend.flush(); | ||
| 52 | |||
| 53 | expect(result).toEqual(returnFake); | ||
| 54 | }); | ||
| 55 | |||
| 56 | it('La función getChoferPorTransportista lleva a la ruta correcta', function() { | ||
| 57 | //arrange | ||
| 58 | var returnFake = 'test'; | ||
| 59 | var paramFake = 1; | ||
| 60 | var result; | ||
| 61 | httpBackend.expectGET('localhost/chofer/transportista/' + paramFake) | ||
| 62 | .respond(returnFake); | ||
| 63 | |||
| 64 | //act | ||
| 65 | servicio.getChoferPorTransportista(paramFake).then(function(data) { | ||
| 66 | result = data.data; | ||
| 67 | }); | ||
| 68 | httpBackend.flush(); | ||
| 69 | |||
| 70 | expect(result).toEqual(returnFake); | ||
| 71 | }); | ||
| 72 | |||
| 73 | it('La función getChoferPorDni lleva a la ruta correcta', function() { | ||
| 74 | //arrange | ||
| 75 | var returnFake = 'test'; | ||
| 76 | var paramFake = 1; | ||
| 77 | var result; | ||
| 78 | httpBackend.expectPOST('localhost/chofer/dni', { dni: paramFake }) | ||
| 79 | .respond(returnFake); | ||
| 80 | |||
| 81 | //act | ||
| 82 | servicio.getChoferPorDni(paramFake).then(function(data) { | ||
| 83 | result = data.data; | ||
| 84 | }); | ||
| 85 | httpBackend.flush(); | ||
| 86 | |||
| 87 | //assert | ||
| 88 | expect(result).toEqual(returnFake); | ||
| 89 | }); | ||
| 90 | |||
| 91 | it('La función guardarChofer llama a la ruta correcta', function() { | ||
| 92 | //arrange | ||
| 93 | var returnFake = 'test'; | ||
| 94 | var paramFake = 1; | ||
| 95 | var result; | ||
| 96 | httpBackend.expectPOST('localhost/chofer', { chofer: paramFake }) | ||
| 97 | .respond(returnFake); | ||
| 98 | |||
| 99 | //act | ||
| 100 | servicio.guardarChofer(paramFake).then(function(data) { | ||
| 101 | result = data.data; | ||
| 102 | }); | ||
| 103 | httpBackend.flush(); | ||
| 104 | |||
| 105 | //assert | ||
| 106 | expect(result).toEqual(returnFake); | ||
| 107 | }); | ||
| 108 | |||
| 109 | it('La función getTransportistas lleva a la ruta correcta', function() { | ||
| 110 | //arrange | ||
| 111 | var returnFake = 'test'; | ||
| 112 | var result; | ||
| 113 | httpBackend.expectGET('localhost/transportista').respond(returnFake); | ||
| 114 | |||
| 115 | //act | ||
| 116 | servicio.getTransportistas().then(function(data) { | ||
| 117 | result = data.data; | ||
| 118 | }); | ||
| 119 | httpBackend.flush(); | ||
| 120 | |||
| 121 | //assert | ||
| 122 | expect(result).toEqual(returnFake); | ||
| 123 | }); | ||
| 124 | |||
| 125 | it('La función getTransportistaPorId lleva a la ruta correcta', function() { | ||
| 126 | //arrange | ||
| 127 | var returnFake = 'test'; | ||
| 128 | var paramFake = 1; | ||
| 129 | var result; | ||
| 130 | httpBackend.expectGET('localhost/transportista/'+ paramFake).respond(returnFake); | ||
| 131 | |||
| 132 | //act | ||
| 133 | servicio.getTransportistaPorId(paramFake).then(function(data) { | ||
| 134 | result = data.data; | ||
| 135 | }); | ||
| 136 | httpBackend.flush(); | ||
| 137 | |||
| 138 | //assert | ||
| 139 | expect(result).toEqual(returnFake); | ||
| 140 | }); | ||
| 141 | |||
| 142 | it('La función deleteChofer lleva a la ruta correcta', function() { | ||
| 143 | //arrange | ||
| 144 | var returnFake = 'test'; | ||
| 145 | var paramFake = 1; | ||
| 146 | var result; | ||
| 147 | httpBackend.expectDELETE('localhost/chofer/'+ paramFake).respond(returnFake); | ||
| 148 | |||
| 149 | //act | ||
| 150 | servicio.deleteChofer(paramFake).then(function(data) { | ||
| 151 | result = data.data; | ||
| 152 | }); | ||
| 153 | httpBackend.flush(); | ||
| 154 | |||
| 155 | //assert | ||
| 156 | expect(result).toEqual(returnFake); | ||
| 157 | }); | ||
| 158 | |||
| 159 | it('La función getTiposDocumento lleva a la ruta correcta', function() { | ||
| 160 | //arrange | ||
| 161 | var returnFake = 'test'; | ||
| 162 | var result; | ||
| 163 | httpBackend.expectGET('localhost/tipo-documento').respond(returnFake); | ||
| 164 | |||
| 165 | //act | ||
| 166 | servicio.getTiposDocumento().then(function(data) { | ||
| 167 | result = data.data; | ||
| 168 | }); | ||
| 169 | httpBackend.flush(); | ||
| 170 | |||
| 171 | //assert | ||
| 172 | expect(result).toEqual(returnFake); | ||
| 173 | }); | ||
| 174 | }); | ||
| 175 | }); | ||
| 176 |
test.html
| File was created | 1 | <html> | |
| 2 | <head> | ||
| 3 | <link rel="stylesheet" type="text/css" href="node_modules/jasmine-core/lib/jasmine-core/jasmine.css"> | ||
| 4 | <meta charset="UTF-8" /> | ||
| 5 | </head> | ||
| 6 | <body> | ||
| 7 | <script type="text/javascript" src="node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script> | ||
| 8 | <script type="text/javascript" src="node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script> | ||
| 9 | <script type="text/javascript" src="node_modules/jasmine-core/lib/jasmine-core/boot.js"></script> | ||
| 10 | <script type="text/javascript" src="node_modules/angular/angular.min.js"></script> | ||
| 11 | <script type="text/javascript" src="node_modules/angular-route/angular-route.min.js"></script> | ||
| 12 | <script type="text/javascript" src="node_modules/angular-mocks/angular-mocks.js"></script> | ||
| 13 | <script type="text/javascript" src="src/js/app.js"></script> | ||
| 14 | <script type="text/javascript" src="src/js/controller.js"></script> | ||
| 15 | <script type="text/javascript" src="src/js/service.js"></script> | ||
| 16 | <script type="text/javascript" src="src/js/route.js"></script> | ||
| 17 | <script type="text/javascript" src="spec/controllerSpec.js"></script> | ||
| 18 | <script type="text/javascript" src="spec/serviceSpec.js"></script> | ||
| 19 | <script type="text/javascript" src="spec/routeSpec.js"></script> | ||
| 20 | </body> | ||
| 21 | </html> | ||
| 22 |