Commit b6b9b95ae9a5ff26e047a4b6fcf099e5663a6a79
Exists in
master
and in
1 other branch
Merge branch 'master' into 'master'
Master See merge request !30
Showing
9 changed files
Show diff stats
gulpfile.js
... | ... | @@ -9,10 +9,13 @@ const jshint = require('gulp-jshint'); |
9 | 9 | const replace = require('gulp-replace'); |
10 | 10 | const connect = require('gulp-connect'); |
11 | 11 | const clean = require('gulp-clean'); |
12 | +const header = require('gulp-header'); | |
13 | +const footer = require('gulp-footer'); | |
12 | 14 | |
13 | 15 | var paths = { |
14 | 16 | srcJS: 'src/js/*.js', |
15 | 17 | srcViews: 'src/views/*.html', |
18 | + specs: 'spec/*.js', | |
16 | 19 | tmp: 'tmp', |
17 | 20 | dist: 'dist/' |
18 | 21 | }; |
... | ... | @@ -40,8 +43,8 @@ gulp.task('uglify', ['templates'], function() { |
40 | 43 | 'tmp/views.js' |
41 | 44 | ]), |
42 | 45 | concat('foca-abm-vehiculo.js'), |
43 | - replace("['ngRoute', 'focaModal', 'ui.bootstrap', 'focaBotoneraLateral']", '[]'), | |
44 | 46 | replace("src/views/", ''), |
47 | + replace("'ngRoute'", ''), | |
45 | 48 | gulp.dest(paths.tmp), |
46 | 49 | rename('foca-abm-vehiculo.min.js'), |
47 | 50 | uglify(), |
... | ... | @@ -50,6 +53,16 @@ gulp.task('uglify', ['templates'], function() { |
50 | 53 | ); |
51 | 54 | }); |
52 | 55 | |
56 | +gulp.task('uglify-spec', function() { | |
57 | + return pump([ | |
58 | + gulp.src(paths.specs), | |
59 | + concat('foca-abm-vehiculo.spec.js'), | |
60 | + header("describe('Módulo foca-abm-vehiculo', function() { \n"), | |
61 | + footer("});"), | |
62 | + gulp.dest(paths.dist) | |
63 | + ]); | |
64 | +}) | |
65 | + | |
53 | 66 | gulp.task('clean', function() { |
54 | 67 | return gulp.src(['tmp', 'dist'], {read: false}) |
55 | 68 | .pipe(clean()); |
... | ... | @@ -58,7 +71,7 @@ gulp.task('clean', function() { |
58 | 71 | gulp.task('pre-commit', function() { |
59 | 72 | return pump( |
60 | 73 | [ |
61 | - gulp.src(paths.srcJS), | |
74 | + gulp.src([paths.srcJS, paths.specs]), | |
62 | 75 | jshint('.jshintrc'), |
63 | 76 | jshint.reporter('default'), |
64 | 77 | jshint.reporter('fail') |
index.html
package.json
... | ... | @@ -36,7 +36,8 @@ |
36 | 36 | }, |
37 | 37 | "devDependencies": { |
38 | 38 | "angular": "^1.7.5", |
39 | - "angular-route": "^1.7.5", | |
39 | + "angular-mocks": "^1.7.7", | |
40 | + "angular-route": "^1.7.7", | |
40 | 41 | "bootstrap": "^4.1.3", |
41 | 42 | "foca-modal": "git+http://git.focasoftware.com/npm/foca-modal.git", |
42 | 43 | "font-awesome": "^4.7.0", |
... | ... | @@ -44,12 +45,15 @@ |
44 | 45 | "gulp-angular-templatecache": "^2.2.5", |
45 | 46 | "gulp-clean": "^0.4.0", |
46 | 47 | "gulp-connect": "^5.6.1", |
48 | + "gulp-footer": "^2.0.2", | |
49 | + "gulp-header": "^2.0.7", | |
47 | 50 | "gulp-htmlmin": "^5.0.1", |
48 | 51 | "gulp-jshint": "^2.1.0", |
49 | 52 | "gulp-rename": "^1.4.0", |
50 | 53 | "gulp-replace": "^1.0.0", |
51 | 54 | "gulp-uglify": "^3.0.1", |
52 | 55 | "gulp-uglify-es": "^1.0.4", |
56 | + "jasmine": "^3.3.1", | |
53 | 57 | "jasmine-core": "^3.3.0", |
54 | 58 | "jquery": "^3.3.1", |
55 | 59 | "jshint": "^2.9.6", |
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 | +}); |
src/js/app.js
src/js/controller.js
... | ... | @@ -145,9 +145,9 @@ angular.module('focaAbmVehiculo') |
145 | 145 | $scope.cisternas = res; |
146 | 146 | $scope.$apply(); |
147 | 147 | }); |
148 | - } | |
148 | + } | |
149 | 149 | }); |
150 | - | |
150 | + | |
151 | 151 | $scope.next = function(key) { |
152 | 152 | if (key === 13) $scope.focused++; |
153 | 153 | }; |
... | ... | @@ -158,7 +158,7 @@ angular.module('focaAbmVehiculo') |
158 | 158 | if(key) { |
159 | 159 | $location.path('/vehiculo/' + $routeParams.idVehiculo + |
160 | 160 | '/cisterna/' + key); |
161 | - }else { | |
161 | + } else { | |
162 | 162 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); |
163 | 163 | } |
164 | 164 | }; |
test.html
... | ... | @@ -0,0 +1,21 @@ |
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> |