Commit a126cff657c8b2f6e0d688f7316c7392430fa00c
1 parent
17de1e938f
Exists in
master
unit test controlador
Showing
1 changed file
with
1111 additions
and
0 deletions
Show diff stats
spec/controllerSpec.js
1 | describe('controladores módulo crear cobranza', function() { | ||
2 | |||
3 | var $controller; | ||
4 | |||
5 | beforeEach(function() { | ||
6 | |||
7 | module('focaCrearCobranza'); | ||
8 | |||
9 | inject(function(_$controller_) { | ||
10 | |||
11 | $controller = _$controller_; | ||
12 | }); | ||
13 | }); | ||
14 | |||
15 | describe('Controlador cobranzaController', function() { | ||
16 | |||
17 | var $filter = function() { | ||
18 | return function() { }; | ||
19 | }; | ||
20 | |||
21 | var $timeout = function() { }; | ||
22 | |||
23 | it('existe el controlador cobranzaController', function() { | ||
24 | |||
25 | //act | ||
26 | var controlador = $controller('cobranzaController', { | ||
27 | $scope: { | ||
28 | $broadcast: function() { } | ||
29 | }, | ||
30 | $timeout: $timeout, | ||
31 | $uibModal: {}, | ||
32 | $location: {}, | ||
33 | focaCrearCobranzaService: { | ||
34 | getCotizacionByIdMoneda: function() { | ||
35 | return { | ||
36 | then: function() { } | ||
37 | }; | ||
38 | }, | ||
39 | getBotonera: function() { }, | ||
40 | getNumeroRecibo: function() { | ||
41 | return { | ||
42 | then: function() { } | ||
43 | }; | ||
44 | } | ||
45 | }, | ||
46 | focaModalService: {}, | ||
47 | $filter: $filter, | ||
48 | focaSeguimientoService: {}, | ||
49 | focaBotoneraLateralService: {}, | ||
50 | APP: {}, | ||
51 | focaLoginService: {} | ||
52 | }); | ||
53 | |||
54 | //assert | ||
55 | expect(typeof controlador).toEqual('object'); | ||
56 | }); | ||
57 | |||
58 | it('function crearCobranza muestra alerta cuando no hay cliente', function() { | ||
59 | |||
60 | //arrange | ||
61 | var scope = { | ||
62 | $broadcast: function() { } | ||
63 | }; | ||
64 | var focaModalService = { | ||
65 | alert: function() { } | ||
66 | }; | ||
67 | |||
68 | $controller('cobranzaController', { | ||
69 | $scope: scope, | ||
70 | $timeout: $timeout, | ||
71 | $uibModal: {}, | ||
72 | $location: {}, | ||
73 | focaCrearCobranzaService: { | ||
74 | getCotizacionByIdMoneda: function() { | ||
75 | return { | ||
76 | then: function() { } | ||
77 | }; | ||
78 | }, | ||
79 | getBotonera: function() { }, | ||
80 | getNumeroRecibo: function() { | ||
81 | return { | ||
82 | then: function() { } | ||
83 | }; | ||
84 | } | ||
85 | }, | ||
86 | focaModalService: focaModalService, | ||
87 | $filter: $filter, | ||
88 | focaSeguimientoService: {}, | ||
89 | focaBotoneraLateralService: {}, | ||
90 | APP: {}, | ||
91 | focaLoginService: {} | ||
92 | }); | ||
93 | |||
94 | //act | ||
95 | spyOn(focaModalService, 'alert'); | ||
96 | scope.crearCobranza(); | ||
97 | |||
98 | //assert | ||
99 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cliente'); | ||
100 | }); | ||
101 | |||
102 | it('function crearCobranza muestra alerta cuando no hay cobrador', function() { | ||
103 | |||
104 | //arrange | ||
105 | var scope = { | ||
106 | $broadcast: function() { } | ||
107 | }; | ||
108 | var focaModalService = { | ||
109 | alert: function() { } | ||
110 | }; | ||
111 | |||
112 | $controller('cobranzaController', { | ||
113 | $scope: scope, | ||
114 | $timeout: $timeout, | ||
115 | $uibModal: {}, | ||
116 | $location: {}, | ||
117 | focaCrearCobranzaService: { | ||
118 | getCotizacionByIdMoneda: function() { | ||
119 | return { | ||
120 | then: function() { } | ||
121 | }; | ||
122 | }, | ||
123 | getBotonera: function() { }, | ||
124 | getNumeroRecibo: function() { | ||
125 | return { | ||
126 | then: function() { } | ||
127 | }; | ||
128 | } | ||
129 | }, | ||
130 | focaModalService: focaModalService, | ||
131 | $filter: $filter, | ||
132 | focaSeguimientoService: {}, | ||
133 | focaBotoneraLateralService: {}, | ||
134 | APP: {}, | ||
135 | focaLoginService: {} | ||
136 | }); | ||
137 | scope.cobranza = { | ||
138 | cliente: { } | ||
139 | }; | ||
140 | |||
141 | //act | ||
142 | spyOn(focaModalService, 'alert'); | ||
143 | scope.crearCobranza(); | ||
144 | |||
145 | //assert | ||
146 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cobrador'); | ||
147 | }); | ||
148 | |||
149 | it('function crearCobranza muestra alerta cuando no hay facturas', function() { | ||
150 | |||
151 | //arrange | ||
152 | var scope = { | ||
153 | $broadcast: function() { } | ||
154 | }; | ||
155 | var focaModalService = { | ||
156 | alert: function() { } | ||
157 | }; | ||
158 | |||
159 | $controller('cobranzaController', { | ||
160 | $scope: scope, | ||
161 | $timeout: $timeout, | ||
162 | $uibModal: {}, | ||
163 | $location: {}, | ||
164 | focaCrearCobranzaService: { | ||
165 | getCotizacionByIdMoneda: function() { | ||
166 | return { | ||
167 | then: function() { } | ||
168 | }; | ||
169 | }, | ||
170 | getBotonera: function() { }, | ||
171 | getNumeroRecibo: function() { | ||
172 | return { | ||
173 | then: function() { } | ||
174 | }; | ||
175 | } | ||
176 | }, | ||
177 | focaModalService: focaModalService, | ||
178 | $filter: $filter, | ||
179 | focaSeguimientoService: {}, | ||
180 | focaBotoneraLateralService: {}, | ||
181 | APP: {}, | ||
182 | focaLoginService: {} | ||
183 | }); | ||
184 | scope.cobranza = { | ||
185 | cliente: { }, | ||
186 | cobrador: { } | ||
187 | }; | ||
188 | |||
189 | //act | ||
190 | spyOn(focaModalService, 'alert'); | ||
191 | scope.crearCobranza(); | ||
192 | |||
193 | //assert | ||
194 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese al menos una factura'); | ||
195 | }); | ||
196 | |||
197 | it('crearCobranza muestra alerta cuando la diferencia no es 0', function() { | ||
198 | |||
199 | //arrange | ||
200 | var scope = { | ||
201 | $broadcast: function() { } | ||
202 | }; | ||
203 | var focaModalService = { | ||
204 | alert: function() { } | ||
205 | }; | ||
206 | |||
207 | $controller('cobranzaController', { | ||
208 | $scope: scope, | ||
209 | $timeout: $timeout, | ||
210 | $uibModal: {}, | ||
211 | $location: {}, | ||
212 | focaCrearCobranzaService: { | ||
213 | getCotizacionByIdMoneda: function() { | ||
214 | return { | ||
215 | then: function() { } | ||
216 | }; | ||
217 | }, | ||
218 | getBotonera: function() { }, | ||
219 | getNumeroRecibo: function() { | ||
220 | return { | ||
221 | then: function() { } | ||
222 | }; | ||
223 | } | ||
224 | }, | ||
225 | focaModalService: focaModalService, | ||
226 | $filter: $filter, | ||
227 | focaSeguimientoService: {}, | ||
228 | focaBotoneraLateralService: {}, | ||
229 | APP: {}, | ||
230 | focaLoginService: {} | ||
231 | }); | ||
232 | scope.cobranza = { | ||
233 | cliente: {}, | ||
234 | cobrador: {}, | ||
235 | moneda: { SIMBOLO: '' } | ||
236 | }; | ||
237 | scope.facturaTabla = [1]; | ||
238 | |||
239 | //act | ||
240 | spyOn(focaModalService, 'alert'); | ||
241 | spyOn(scope, 'getTotalCobrado').and.returnValue(1); | ||
242 | spyOn(scope, 'getTotalDeuda').and.returnValue(1); | ||
243 | scope.crearCobranza(); | ||
244 | |||
245 | //assert | ||
246 | expect(focaModalService.alert).toHaveBeenCalledWith('La diferencia debe ser 0,00'); | ||
247 | }); | ||
248 | |||
249 | it('crearCobranza llama a startGuardar y guardarCobranza', function() { | ||
250 | |||
251 | //arrange | ||
252 | var scope = { | ||
253 | $broadcast: function() { } | ||
254 | }; | ||
255 | var focaBotoneraLateralService = { | ||
256 | startGuardar: function() { } | ||
257 | }; | ||
258 | var focaCrearCobranzaService = { | ||
259 | guardarCobranza: function() { }, | ||
260 | getCotizacionByIdMoneda: function() { | ||
261 | return { | ||
262 | then: function() { } | ||
263 | }; | ||
264 | }, | ||
265 | getBotonera: function() { }, | ||
266 | getNumeroRecibo: function() { | ||
267 | return { | ||
268 | then: function() { } | ||
269 | }; | ||
270 | } | ||
271 | }; | ||
272 | |||
273 | $controller('cobranzaController', { | ||
274 | $scope: scope, | ||
275 | $timeout: $timeout, | ||
276 | $uibModal: {}, | ||
277 | $location: {}, | ||
278 | focaCrearCobranzaService: focaCrearCobranzaService, | ||
279 | focaModalService: {}, | ||
280 | $filter: $filter, | ||
281 | focaSeguimientoService: {}, | ||
282 | focaBotoneraLateralService: focaBotoneraLateralService, | ||
283 | APP: {}, | ||
284 | focaLoginService: {} | ||
285 | }); | ||
286 | scope.cobranza = { | ||
287 | cliente: {}, | ||
288 | cobrador: {}, | ||
289 | moneda: { SIMBOLO: '' }, | ||
290 | cotizacion: {} | ||
291 | }; | ||
292 | scope.facturaTabla = [1]; | ||
293 | |||
294 | //act | ||
295 | spyOn(focaBotoneraLateralService, 'startGuardar'); | ||
296 | spyOn(focaCrearCobranzaService, 'guardarCobranza') | ||
297 | .and.returnValue({ then: function() { } }); | ||
298 | spyOn(scope, 'getTotalCobrado').and.returnValue(0); | ||
299 | spyOn(scope, 'getTotalDeuda').and.returnValue(0); | ||
300 | scope.crearCobranza(); | ||
301 | |||
302 | //assert | ||
303 | expect(focaBotoneraLateralService.startGuardar).toHaveBeenCalled(); | ||
304 | expect(focaCrearCobranzaService.guardarCobranza).toHaveBeenCalled(); | ||
305 | }); | ||
306 | |||
307 | it('seleccionarCobros seatea cobroDeuda en false', function() { | ||
308 | |||
309 | //arrange | ||
310 | var scope = { | ||
311 | $broadcast: function() { } | ||
312 | }; | ||
313 | |||
314 | $controller('cobranzaController', { | ||
315 | $scope: scope, | ||
316 | $timeout: $timeout, | ||
317 | $uibModal: {}, | ||
318 | $location: {}, | ||
319 | focaCrearCobranzaService: { | ||
320 | getCotizacionByIdMoneda: function() { | ||
321 | return { | ||
322 | then: function() { } | ||
323 | }; | ||
324 | }, | ||
325 | getBotonera: function() { }, | ||
326 | getNumeroRecibo: function() { | ||
327 | return { | ||
328 | then: function() { } | ||
329 | }; | ||
330 | } | ||
331 | }, | ||
332 | focaModalService: {}, | ||
333 | $filter: $filter, | ||
334 | focaSeguimientoService: {}, | ||
335 | focaBotoneraLateralService: {}, | ||
336 | APP: {}, | ||
337 | focaLoginService: {} | ||
338 | }); | ||
339 | |||
340 | //act | ||
341 | scope.seleccionarCobros(); | ||
342 | |||
343 | //assert | ||
344 | expect(scope.cobroDeuda).toEqual(false); | ||
345 | }); | ||
346 | |||
347 | it('seleccionarComprobantes seatea cobroDeuda en true', function() { | ||
348 | |||
349 | //arrange | ||
350 | var scope = { | ||
351 | $broadcast: function() { } | ||
352 | }; | ||
353 | |||
354 | $controller('cobranzaController', { | ||
355 | $scope: scope, | ||
356 | $timeout: $timeout, | ||
357 | $uibModal: {}, | ||
358 | $location: {}, | ||
359 | focaCrearCobranzaService: { | ||
360 | getCotizacionByIdMoneda: function() { | ||
361 | return { | ||
362 | then: function() { } | ||
363 | }; | ||
364 | }, | ||
365 | getBotonera: function() { }, | ||
366 | getNumeroRecibo: function() { | ||
367 | return { | ||
368 | then: function() { } | ||
369 | }; | ||
370 | } | ||
371 | }, | ||
372 | focaModalService: {}, | ||
373 | $filter: $filter, | ||
374 | focaSeguimientoService: {}, | ||
375 | focaBotoneraLateralService: {}, | ||
376 | APP: {}, | ||
377 | focaLoginService: {} | ||
378 | }); | ||
379 | |||
380 | //act | ||
381 | scope.seleccionarComprobantes(); | ||
382 | |||
383 | //assert | ||
384 | expect(scope.cobroDeuda).toEqual(true); | ||
385 | }); | ||
386 | |||
387 | it('seleccionarCobranza levanta modal y setea datos', function(done) { | ||
388 | |||
389 | //arrange | ||
390 | var scope = { | ||
391 | $broadcast: function() { } | ||
392 | }; | ||
393 | var uibModal = { | ||
394 | open: function() { } | ||
395 | }; | ||
396 | |||
397 | $controller('cobranzaController', { | ||
398 | $scope: scope, | ||
399 | $timeout: $timeout, | ||
400 | $uibModal: uibModal, | ||
401 | $location: {}, | ||
402 | focaCrearCobranzaService: { | ||
403 | getCotizacionByIdMoneda: function() { | ||
404 | return { | ||
405 | then: function() { } | ||
406 | }; | ||
407 | }, | ||
408 | getBotonera: function() { }, | ||
409 | getNumeroRecibo: function() { | ||
410 | return { | ||
411 | then: function() { } | ||
412 | }; | ||
413 | } | ||
414 | }, | ||
415 | focaModalService: {}, | ||
416 | $filter: $filter, | ||
417 | focaSeguimientoService: {}, | ||
418 | focaBotoneraLateralService: {}, | ||
419 | APP: {}, | ||
420 | focaLoginService: {} | ||
421 | }); | ||
422 | var respuesta = { facturas: 1, cobros: 2, cliente: { } }; | ||
423 | var promesa = { result: Promise.resolve(respuesta) }; | ||
424 | |||
425 | //act | ||
426 | spyOn(uibModal, 'open').and.returnValue(promesa); | ||
427 | spyOn(scope, '$broadcast'); | ||
428 | scope.seleccionarCobranza(); | ||
429 | |||
430 | //assert | ||
431 | promesa.result.then(function() { | ||
432 | expect(uibModal.open).toHaveBeenCalled(); | ||
433 | expect(scope.$broadcast).toHaveBeenCalledWith('cleanCabecera'); | ||
434 | expect(scope.facturaTabla).toEqual(respuesta.facturas); | ||
435 | expect(scope.cobrosTabla).toEqual(respuesta.cobros); | ||
436 | done(); | ||
437 | }); | ||
438 | }); | ||
439 | |||
440 | it('seleccionarCliente levanta modal y setea datos', function(done) { | ||
441 | |||
442 | //arrange | ||
443 | var scope = { | ||
444 | $broadcast: function() { } | ||
445 | }; | ||
446 | var uibModal = { | ||
447 | open: function() { } | ||
448 | }; | ||
449 | |||
450 | $controller('cobranzaController', { | ||
451 | $scope: scope, | ||
452 | $timeout: $timeout, | ||
453 | $uibModal: uibModal, | ||
454 | $location: {}, | ||
455 | focaCrearCobranzaService: { | ||
456 | getCotizacionByIdMoneda: function() { | ||
457 | return { | ||
458 | then: function() { } | ||
459 | }; | ||
460 | }, | ||
461 | getBotonera: function() { }, | ||
462 | getNumeroRecibo: function() { | ||
463 | return { | ||
464 | then: function() { } | ||
465 | }; | ||
466 | } | ||
467 | }, | ||
468 | focaModalService: {}, | ||
469 | $filter: $filter, | ||
470 | focaSeguimientoService: {}, | ||
471 | focaBotoneraLateralService: {}, | ||
472 | APP: {}, | ||
473 | focaLoginService: {} | ||
474 | }); | ||
475 | scope.cobranza = { | ||
476 | cobrador: {} | ||
477 | }; | ||
478 | var respuesta = { facturas: 1, cobros: 2, cliente: { } }; | ||
479 | var promesa = { result: Promise.resolve(respuesta) }; | ||
480 | |||
481 | //act | ||
482 | spyOn(uibModal, 'open').and.returnValue(promesa); | ||
483 | spyOn(scope, '$broadcast'); | ||
484 | scope.seleccionarCliente(); | ||
485 | |||
486 | //assert | ||
487 | promesa.result.then(function() { | ||
488 | expect(uibModal.open).toHaveBeenCalled(); | ||
489 | expect(scope.$broadcast).toHaveBeenCalled(); | ||
490 | done(); | ||
491 | }); | ||
492 | }); | ||
493 | |||
494 | it('seleccionarFactura muestra alerta cuando no se seteo cliente', function() { | ||
495 | |||
496 | //arrange | ||
497 | var scope = { | ||
498 | $broadcast: function() { } | ||
499 | }; | ||
500 | var focaModalService = { | ||
501 | alert: function() { } | ||
502 | }; | ||
503 | |||
504 | $controller('cobranzaController', { | ||
505 | $scope: scope, | ||
506 | $timeout: $timeout, | ||
507 | $uibModal: {}, | ||
508 | $location: {}, | ||
509 | focaCrearCobranzaService: { | ||
510 | getCotizacionByIdMoneda: function() { | ||
511 | return { | ||
512 | then: function() { } | ||
513 | }; | ||
514 | }, | ||
515 | getBotonera: function() { }, | ||
516 | getNumeroRecibo: function() { | ||
517 | return { | ||
518 | then: function() { } | ||
519 | }; | ||
520 | } | ||
521 | }, | ||
522 | focaModalService: focaModalService, | ||
523 | $filter: $filter, | ||
524 | focaSeguimientoService: {}, | ||
525 | focaBotoneraLateralService: {}, | ||
526 | APP: {}, | ||
527 | focaLoginService: {} | ||
528 | }); | ||
529 | |||
530 | //act | ||
531 | spyOn(focaModalService, 'alert'); | ||
532 | scope.seleccionarFactura(); | ||
533 | |||
534 | //assert | ||
535 | expect(focaModalService.alert).toHaveBeenCalledWith('Seleccione primero un cliente'); | ||
536 | }); | ||
537 | |||
538 | it('seleccionarFactura levanta modal', function() { | ||
539 | |||
540 | //arrange | ||
541 | var scope = { | ||
542 | $broadcast: function() { } | ||
543 | }; | ||
544 | var uibModal = { | ||
545 | open: function() { } | ||
546 | }; | ||
547 | |||
548 | $controller('cobranzaController', { | ||
549 | $scope: scope, | ||
550 | $timeout: $timeout, | ||
551 | $uibModal: uibModal, | ||
552 | $location: {}, | ||
553 | focaCrearCobranzaService: { | ||
554 | getCotizacionByIdMoneda: function() { | ||
555 | return { | ||
556 | then: function() { } | ||
557 | }; | ||
558 | }, | ||
559 | getBotonera: function() { }, | ||
560 | getNumeroRecibo: function() { | ||
561 | return { | ||
562 | then: function() { } | ||
563 | }; | ||
564 | } | ||
565 | }, | ||
566 | focaModalService: {}, | ||
567 | $filter: $filter, | ||
568 | focaSeguimientoService: {}, | ||
569 | focaBotoneraLateralService: {}, | ||
570 | APP: {}, | ||
571 | focaLoginService: {} | ||
572 | }); | ||
573 | scope.cobranza = { | ||
574 | cliente: { } | ||
575 | }; | ||
576 | |||
577 | var respuesta = { result: { then: function() { } } }; | ||
578 | |||
579 | //act | ||
580 | spyOn(uibModal, 'open').and.returnValue(respuesta); | ||
581 | scope.seleccionarFactura(); | ||
582 | |||
583 | //assert | ||
584 | expect(uibModal.open).toHaveBeenCalled(); | ||
585 | }); | ||
586 | |||
587 | it('seleccionarCheque levanta modal', function() { | ||
588 | |||
589 | //arrange | ||
590 | var scope = { | ||
591 | $broadcast: function() { } | ||
592 | }; | ||
593 | var uibModal = { | ||
594 | open: function() { } | ||
595 | }; | ||
596 | |||
597 | $controller('cobranzaController', { | ||
598 | $scope: scope, | ||
599 | $timeout: $timeout, | ||
600 | $uibModal: uibModal, | ||
601 | $location: {}, | ||
602 | focaCrearCobranzaService: { | ||
603 | getCotizacionByIdMoneda: function() { | ||
604 | return { | ||
605 | then: function() { } | ||
606 | }; | ||
607 | }, | ||
608 | getBotonera: function() { }, | ||
609 | getNumeroRecibo: function() { | ||
610 | return { | ||
611 | then: function() { } | ||
612 | }; | ||
613 | } | ||
614 | }, | ||
615 | focaModalService: {}, | ||
616 | $filter: $filter, | ||
617 | focaSeguimientoService: {}, | ||
618 | focaBotoneraLateralService: {}, | ||
619 | APP: {}, | ||
620 | focaLoginService: {} | ||
621 | }); | ||
622 | scope.cobranza = { | ||
623 | cliente: { } | ||
624 | }; | ||
625 | |||
626 | var respuesta = { result: { then: function() { } } }; | ||
627 | |||
628 | //act | ||
629 | spyOn(uibModal, 'open').and.returnValue(respuesta); | ||
630 | scope.seleccionarCheque(); | ||
631 | |||
632 | //assert | ||
633 | expect(uibModal.open).toHaveBeenCalled(); | ||
634 | }); | ||
635 | |||
636 | it('seleccionarEfectivo levanta modal', function() { | ||
637 | |||
638 | //arrange | ||
639 | var scope = { | ||
640 | $broadcast: function() { } | ||
641 | }; | ||
642 | var uibModal = { | ||
643 | open: function() { } | ||
644 | }; | ||
645 | |||
646 | $controller('cobranzaController', { | ||
647 | $scope: scope, | ||
648 | $timeout: $timeout, | ||
649 | $uibModal: uibModal, | ||
650 | $location: {}, | ||
651 | focaCrearCobranzaService: { | ||
652 | getCotizacionByIdMoneda: function() { | ||
653 | return { | ||
654 | then: function() { } | ||
655 | }; | ||
656 | }, | ||
657 | getBotonera: function() { }, | ||
658 | getNumeroRecibo: function() { | ||
659 | return { | ||
660 | then: function() { } | ||
661 | }; | ||
662 | } | ||
663 | }, | ||
664 | focaModalService: {}, | ||
665 | $filter: $filter, | ||
666 | focaSeguimientoService: {}, | ||
667 | focaBotoneraLateralService: {}, | ||
668 | APP: {}, | ||
669 | focaLoginService: {} | ||
670 | }); | ||
671 | scope.cobranza = { | ||
672 | cliente: { } | ||
673 | }; | ||
674 | |||
675 | var respuesta = { result: { then: function() { } } }; | ||
676 | |||
677 | //act | ||
678 | spyOn(uibModal, 'open').and.returnValue(respuesta); | ||
679 | scope.seleccionarEfectivo(); | ||
680 | |||
681 | //assert | ||
682 | expect(uibModal.open).toHaveBeenCalled(); | ||
683 | }); | ||
684 | |||
685 | it('seleccionarDetalles levanta modal', function() { | ||
686 | |||
687 | //arrange | ||
688 | var scope = { | ||
689 | $broadcast: function() { } | ||
690 | }; | ||
691 | var uibModal = { | ||
692 | open: function() { } | ||
693 | }; | ||
694 | |||
695 | $controller('cobranzaController', { | ||
696 | $scope: scope, | ||
697 | $timeout: $timeout, | ||
698 | $uibModal: uibModal, | ||
699 | $location: {}, | ||
700 | focaCrearCobranzaService: { | ||
701 | getCotizacionByIdMoneda: function() { | ||
702 | return { | ||
703 | then: function() { } | ||
704 | }; | ||
705 | }, | ||
706 | getBotonera: function() { }, | ||
707 | getNumeroRecibo: function() { | ||
708 | return { | ||
709 | then: function() { } | ||
710 | }; | ||
711 | } | ||
712 | }, | ||
713 | focaModalService: {}, | ||
714 | $filter: $filter, | ||
715 | focaSeguimientoService: {}, | ||
716 | focaBotoneraLateralService: {}, | ||
717 | APP: {}, | ||
718 | focaLoginService: {} | ||
719 | }); | ||
720 | scope.cobranza = { | ||
721 | cliente: { } | ||
722 | }; | ||
723 | |||
724 | var respuesta = { result: { then: function() { } } }; | ||
725 | |||
726 | //act | ||
727 | spyOn(uibModal, 'open').and.returnValue(respuesta); | ||
728 | scope.seleccionarDetalles(); | ||
729 | |||
730 | //assert | ||
731 | expect(uibModal.open).toHaveBeenCalled(); | ||
732 | }); | ||
733 | |||
734 | it('seleccionarMoneda levanta modal', function(done) { | ||
735 | |||
736 | //arrange | ||
737 | var scope = { | ||
738 | $broadcast: function() { } | ||
739 | }; | ||
740 | var focaModalService = { | ||
741 | modal: function() { } | ||
742 | }; | ||
743 | |||
744 | $controller('cobranzaController', { | ||
745 | $scope: scope, | ||
746 | $timeout: $timeout, | ||
747 | $uibModal: {}, | ||
748 | $location: {}, | ||
749 | focaCrearCobranzaService: { | ||
750 | getCotizacionByIdMoneda: function() { | ||
751 | return { | ||
752 | then: function() { } | ||
753 | }; | ||
754 | }, | ||
755 | getBotonera: function() { }, | ||
756 | getNumeroRecibo: function() { | ||
757 | return { | ||
758 | then: function() { } | ||
759 | }; | ||
760 | } | ||
761 | }, | ||
762 | focaModalService: focaModalService, | ||
763 | $filter: $filter, | ||
764 | focaSeguimientoService: {}, | ||
765 | focaBotoneraLateralService: {}, | ||
766 | APP: {}, | ||
767 | focaLoginService: {} | ||
768 | }); | ||
769 | |||
770 | var respuesta = 1; | ||
771 | var promesa = Promise.resolve(respuesta); | ||
772 | |||
773 | //act | ||
774 | spyOn(focaModalService, 'modal').and.returnValue(promesa); | ||
775 | spyOn(scope, 'seleccionarCotizacion'); | ||
776 | scope.seleccionarMoneda(); | ||
777 | |||
778 | //assert | ||
779 | expect(focaModalService.modal).toHaveBeenCalled(); | ||
780 | promesa.then(function() { | ||
781 | expect(scope.seleccionarCotizacion).toHaveBeenCalled(); | ||
782 | done(); | ||
783 | }); | ||
784 | }); | ||
785 | |||
786 | it('seleccionarCotizacion levanta modal', function(done) { | ||
787 | |||
788 | //arrange | ||
789 | var scope = { | ||
790 | $broadcast: function() { } | ||
791 | }; | ||
792 | var uibModal = { | ||
793 | open: function() { } | ||
794 | }; | ||
795 | |||
796 | $controller('cobranzaController', { | ||
797 | $scope: scope, | ||
798 | $timeout: $timeout, | ||
799 | $uibModal: uibModal, | ||
800 | $location: {}, | ||
801 | focaCrearCobranzaService: { | ||
802 | getCotizacionByIdMoneda: function() { | ||
803 | return { | ||
804 | then: function() { } | ||
805 | }; | ||
806 | }, | ||
807 | getBotonera: function() { }, | ||
808 | getNumeroRecibo: function() { | ||
809 | return { | ||
810 | then: function() { } | ||
811 | }; | ||
812 | } | ||
813 | }, | ||
814 | focaModalService: {}, | ||
815 | $filter: $filter, | ||
816 | focaSeguimientoService: {}, | ||
817 | focaBotoneraLateralService: {}, | ||
818 | APP: {}, | ||
819 | focaLoginService: {} | ||
820 | }); | ||
821 | |||
822 | var respuesta = 1; | ||
823 | var promesa = { result: Promise.resolve(respuesta) }; | ||
824 | |||
825 | //act | ||
826 | spyOn(uibModal, 'open').and.returnValue(promesa); | ||
827 | spyOn(scope, '$broadcast'); | ||
828 | scope.seleccionarCotizacion({ }); | ||
829 | |||
830 | //assert | ||
831 | promesa.result.then(function() { | ||
832 | expect(uibModal.open).toHaveBeenCalled(); | ||
833 | expect(scope.$broadcast).toHaveBeenCalled(); | ||
834 | scope.cobranza.cotizacion = respuesta; | ||
835 | done(); | ||
836 | }); | ||
837 | }); | ||
838 | |||
839 | it('seleccionarCobrador levanta modal', function(done) { | ||
840 | |||
841 | //arrange | ||
842 | var scope = { | ||
843 | $broadcast: function() { } | ||
844 | }; | ||
845 | var focaModalService = { | ||
846 | modal: function() { } | ||
847 | }; | ||
848 | |||
849 | $controller('cobranzaController', { | ||
850 | $scope: scope, | ||
851 | $timeout: $timeout, | ||
852 | $uibModal: {}, | ||
853 | $location: {}, | ||
854 | focaCrearCobranzaService: { | ||
855 | getCotizacionByIdMoneda: function() { | ||
856 | return { | ||
857 | then: function() { } | ||
858 | }; | ||
859 | }, | ||
860 | getBotonera: function() { }, | ||
861 | getNumeroRecibo: function() { | ||
862 | return { | ||
863 | then: function() { } | ||
864 | }; | ||
865 | } | ||
866 | }, | ||
867 | focaModalService: focaModalService, | ||
868 | $filter: $filter, | ||
869 | focaSeguimientoService: {}, | ||
870 | focaBotoneraLateralService: {}, | ||
871 | APP: {}, | ||
872 | focaLoginService: {} | ||
873 | }); | ||
874 | |||
875 | var respuesta = 1; | ||
876 | var promesa = Promise.resolve(respuesta); | ||
877 | |||
878 | //act | ||
879 | spyOn(focaModalService, 'modal').and.returnValue(promesa); | ||
880 | spyOn(scope, '$broadcast'); | ||
881 | scope.seleccionarCobrador({ }); | ||
882 | |||
883 | //assert | ||
884 | promesa.then(function() { | ||
885 | expect(focaModalService.modal).toHaveBeenCalled(); | ||
886 | expect(scope.$broadcast).toHaveBeenCalled(); | ||
887 | scope.cobranza.cobrador = respuesta; | ||
888 | done(); | ||
889 | }); | ||
890 | }); | ||
891 | |||
892 | it('getTotalDeuda devuelve correcto', function() { | ||
893 | |||
894 | //arrange | ||
895 | var scope = { | ||
896 | $broadcast: function() { } | ||
897 | }; | ||
898 | |||
899 | $controller('cobranzaController', { | ||
900 | $scope: scope, | ||
901 | $timeout: $timeout, | ||
902 | $uibModal: {}, | ||
903 | $location: {}, | ||
904 | focaCrearCobranzaService: { | ||
905 | getCotizacionByIdMoneda: function() { | ||
906 | return { | ||
907 | then: function() { } | ||
908 | }; | ||
909 | }, | ||
910 | getBotonera: function() { }, | ||
911 | getNumeroRecibo: function() { | ||
912 | return { | ||
913 | then: function() { } | ||
914 | }; | ||
915 | } | ||
916 | }, | ||
917 | focaModalService: {}, | ||
918 | $filter: $filter, | ||
919 | focaSeguimientoService: {}, | ||
920 | focaBotoneraLateralService: {}, | ||
921 | APP: {}, | ||
922 | focaLoginService: {} | ||
923 | }); | ||
924 | scope.facturaTabla = [{ IPA: 1 }]; | ||
925 | |||
926 | //act | ||
927 | var esperado = 1; | ||
928 | var resultado = scope.getTotalDeuda(); | ||
929 | |||
930 | //assert | ||
931 | expect(resultado).toEqual(esperado); | ||
932 | }); | ||
933 | |||
934 | it('getTotalCobrado devuelve correcto', function() { | ||
935 | |||
936 | //arrange | ||
937 | var scope = { | ||
938 | $broadcast: function() { } | ||
939 | }; | ||
940 | |||
941 | $controller('cobranzaController', { | ||
942 | $scope: scope, | ||
943 | $timeout: $timeout, | ||
944 | $uibModal: {}, | ||
945 | $location: {}, | ||
946 | focaCrearCobranzaService: { | ||
947 | getCotizacionByIdMoneda: function() { | ||
948 | return { | ||
949 | then: function() { } | ||
950 | }; | ||
951 | }, | ||
952 | getBotonera: function() { }, | ||
953 | getNumeroRecibo: function() { | ||
954 | return { | ||
955 | then: function() { } | ||
956 | }; | ||
957 | } | ||
958 | }, | ||
959 | focaModalService: {}, | ||
960 | $filter: $filter, | ||
961 | focaSeguimientoService: {}, | ||
962 | focaBotoneraLateralService: {}, | ||
963 | APP: {}, | ||
964 | focaLoginService: {} | ||
965 | }); | ||
966 | scope.cobrosTabla = [{ importe: 1 }]; | ||
967 | |||
968 | //act | ||
969 | var esperado = 1; | ||
970 | var resultado = scope.getTotalCobrado(); | ||
971 | |||
972 | //assert | ||
973 | expect(resultado).toEqual(esperado); | ||
974 | }); | ||
975 | |||
976 | it('getSubTotal devuelve correcto', function() { | ||
977 | |||
978 | //arrange | ||
979 | var scope = { | ||
980 | $broadcast: function() { } | ||
981 | }; | ||
982 | |||
983 | $controller('cobranzaController', { | ||
984 | $scope: scope, | ||
985 | $timeout: $timeout, | ||
986 | $uibModal: {}, | ||
987 | $location: {}, | ||
988 | focaCrearCobranzaService: { | ||
989 | getCotizacionByIdMoneda: function() { | ||
990 | return { | ||
991 | then: function() { } | ||
992 | }; | ||
993 | }, | ||
994 | getBotonera: function() { }, | ||
995 | getNumeroRecibo: function() { | ||
996 | return { | ||
997 | then: function() { } | ||
998 | }; | ||
999 | } | ||
1000 | }, | ||
1001 | focaModalService: {}, | ||
1002 | $filter: $filter, | ||
1003 | focaSeguimientoService: {}, | ||
1004 | focaBotoneraLateralService: {}, | ||
1005 | APP: {}, | ||
1006 | focaLoginService: {} | ||
1007 | }); | ||
1008 | scope.articuloACargar = { | ||
1009 | precio: 2, | ||
1010 | cantidad: 5 | ||
1011 | }; | ||
1012 | |||
1013 | //act | ||
1014 | var esperado = 10; | ||
1015 | var resultado = scope.getSubTotal(); | ||
1016 | |||
1017 | //assert | ||
1018 | expect(resultado).toEqual(esperado); | ||
1019 | }); | ||
1020 | |||
1021 | it('salir lleva a la ruta correcta', function() { | ||
1022 | |||
1023 | inject(function($location) { | ||
1024 | |||
1025 | //arrange | ||
1026 | var scope = { | ||
1027 | $broadcast: function() { } | ||
1028 | }; | ||
1029 | |||
1030 | $controller('cobranzaController', { | ||
1031 | $scope: scope, | ||
1032 | $timeout: $timeout, | ||
1033 | $uibModal: {}, | ||
1034 | $location: $location, | ||
1035 | focaCrearCobranzaService: { | ||
1036 | getCotizacionByIdMoneda: function() { | ||
1037 | return { | ||
1038 | then: function() { } | ||
1039 | }; | ||
1040 | }, | ||
1041 | getBotonera: function() { }, | ||
1042 | getNumeroRecibo: function() { | ||
1043 | return { | ||
1044 | then: function() { } | ||
1045 | }; | ||
1046 | } | ||
1047 | }, | ||
1048 | focaModalService: {}, | ||
1049 | $filter: $filter, | ||
1050 | focaSeguimientoService: {}, | ||
1051 | focaBotoneraLateralService: {}, | ||
1052 | APP: {}, | ||
1053 | focaLoginService: {} | ||
1054 | }); | ||
1055 | |||
1056 | //act | ||
1057 | scope.salir(); | ||
1058 | |||
1059 | //assert | ||
1060 | expect($location.url()).toEqual('/'); | ||
1061 | }); | ||
1062 | }); | ||
1063 | |||
1064 | it('parsearATexto parsea correctamente', function() { | ||
1065 | |||
1066 | //arrange | ||
1067 | var scope = { | ||
1068 | $broadcast: function() { } | ||
1069 | }; | ||
1070 | |||
1071 | $controller('cobranzaController', { | ||
1072 | $scope: scope, | ||
1073 | $timeout: $timeout, | ||
1074 | $uibModal: {}, | ||
1075 | $location: {}, | ||
1076 | focaCrearCobranzaService: { | ||
1077 | getCotizacionByIdMoneda: function() { | ||
1078 | return { | ||
1079 | then: function() { } | ||
1080 | }; | ||
1081 | }, | ||
1082 | getBotonera: function() { }, | ||
1083 | getNumeroRecibo: function() { | ||
1084 | return { | ||
1085 | then: function() { } | ||
1086 | }; | ||
1087 | } | ||
1088 | }, | ||
1089 | focaModalService: {}, | ||
1090 | $filter: $filter, | ||
1091 | focaSeguimientoService: {}, | ||
1092 | focaBotoneraLateralService: {}, | ||
1093 | APP: {}, | ||
1094 | focaLoginService: {} | ||
1095 | }); | ||
1096 | |||
1097 | var parametro = { | ||
1098 | cantidad: '1', | ||
1099 | precio: '2' | ||
1100 | }; | ||
1101 | |||
1102 | //act | ||
1103 | scope.parsearATexto(parametro); | ||
1104 | |||
1105 | //assert | ||
1106 | expect(typeof parametro.cantidad).toEqual('number'); | ||
1107 | expect(typeof parametro.precio).toEqual('number'); | ||
1108 | }); | ||
1109 | |||
1110 | }); | ||
1111 | }); | ||
1112 |