Commit e90468fd7f94ffcc1c0e6be93c6380cb8f1f9b18

Authored by Eric Fernandez
1 parent 67099f1abb
Exists in master

archivos testing

spec/controllerSpec.js
File was created 1 describe('Controladores abm precios condiciones', function() {
2
3 var $controller;
4 var timeout;
5
6 beforeEach(function() {
7 module('focaAbmPreciosCondiciones');
8 inject(function(_$controller_) {
9 $controller = _$controller_;
10 });
11 });
12
13 beforeEach(function() {
14 inject(function($timeout) {
15 timeout = $timeout;
16 });
17 });
18
19 describe('Controlador focaAbmPreciosCondiciones', function() {
20
21 it('Existe el controlador', function() {
22 //act
23 var controlador = $controller('focaAbmPreciosCondicionesController', {
24 $scope: {},
25 focaAbmPreciosCondicionesService: {},
26 $location: {},
27 focaModalService: {},
28 focaBotoneraLateralService: {},
29 $timeout: timeout
30 });
31
32 //assert
33 expect(typeof controlador).toEqual('object');
34 });
35
36 it('$scope.editar lleva a la ruta correcta', function() {
37 inject(function($location) {
38 //arrange
39 var scope = {};
40 var paramFake = 1;
41 $controller('focaAbmPreciosCondicionesController', {
42 $scope: scope,
43 focaAbmPreciosCondicionesService: {},
44 $location: $location,
45 focaModalService: {},
46 focaBotoneraLateralService: {},
47 $timeout: timeout
48 });
49
50
51 //act
52 scope.editar(paramFake);
53
54 //assert
55 expect($location.url()).toEqual('/precio-condicion/' + paramFake);
56 });
57 });
58
59 it('$scope.solicitarConfirmacion levanta modal confirm', function() {
60 //arrange
61 var scope = {};
62 var paramFake = 1;
63 var focaModalService = {
64 confirm: function() { }
65 };
66 $controller('focaAbmPreciosCondicionesController', {
67 $scope: scope,
68 focaAbmPreciosCondicionesService: {},
69 $location: {},
70 focaModalService: focaModalService,
71 focaBotoneraLateralService: {},
72 $timeout: timeout
73 });
74
75 //act
76 spyOn(focaModalService, 'confirm').and.returnValue({ then: function() { }});
77 scope.solicitarConfirmacion(paramFake);
78
79 //assert
80 expect(focaModalService.confirm).toHaveBeenCalled();
81 });
82
83 it('$scope.solicitarConfirmacion elimina al confirmar ok', function(done) {
84 //arrange
85 var scope = {};
86 var paramFake = 1;
87 var focaModalService = {
88 confirm: function() { }
89 };
90 var focaAbmPreciosCondicionesService = {
91 borrarPrecioCondicion: function() { }
92 };
93 $controller('focaAbmPreciosCondicionesController', {
94 $scope: scope,
95 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService,
96 $location: {},
97 focaModalService: focaModalService,
98 focaBotoneraLateralService: {},
99 $timeout: timeout
100 });
101 var promesaConfirm = Promise.resolve(true);
102 scope.preciosCondiciones = [];
103
104 //act
105 spyOn(focaModalService, 'confirm').and.returnValue(promesaConfirm);
106 spyOn(focaAbmPreciosCondicionesService, 'borrarPrecioCondicion');
107 scope.solicitarConfirmacion(paramFake);
108
109 //assert
110 promesaConfirm.then(function() {
111 expect(focaAbmPreciosCondicionesService.borrarPrecioCondicion).toHaveBeenCalled();
112 done();
113 });
114 });
115
116 it('$scope.buscar llama a obtenerPreciosCondiciones', function() {
117 //arrange
118 var scope = {};
119 var focaAbmPreciosCondicionesService = {
120 obtenerPreciosCondiciones: function() { }
121 };
122 $controller('focaAbmPreciosCondicionesController', {
123 $scope: scope,
124 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService,
125 $location: {},
126 focaModalService: {},
127 focaBotoneraLateralService: {},
128 $timeout: timeout
129 });
130
131 //act
132 spyOn(focaAbmPreciosCondicionesService, 'obtenerPreciosCondiciones')
133 .and.returnValue({ then: function() { }});
134 scope.buscar(13);
135
136 //assert
137 expect(focaAbmPreciosCondicionesService.obtenerPreciosCondiciones).toHaveBeenCalled();
138 });
139 });
140
141 describe('Controlador focaAbmPrecioCondicionController', function() {
142
143 it('Existe el controlador focaAbmPrecioCondicionController', function() {
144 //act
145 var controlador = $controller('focaAbmPrecioCondicionController', {
146 $scope: {},
147 focaAbmPreciosCondicionesService: {
148 obtenerPrecioCondicion: function() {
149 return {
150 then: function() { }
151 };
152 }
153 },
154 focaBotoneraLateralService: {},
155 $routeParams: {},
156 $location: {},
157 focaModalService: {},
158 $timeout: timeout,
159 $uibModal: {},
160 $window: {}
161 });
162
163 //assert
164 expect(typeof controlador).toEqual('object');
165 });
166
167 it('La funcion $scope.cancelar lleva a la ruta correcta', function() {
168 inject(function($location) {
169 //arrange
170 var scope = {};
171 $controller('focaAbmPrecioCondicionController', {
172 $scope: scope,
173 focaAbmPreciosCondicionesService: {
174 obtenerPrecioCondicion: function() {
175 return {
176 then: function() { }
177 };
178 }
179 },
180 focaBotoneraLateralService: {},
181 $routeParams: {},
182 $location: $location,
183 focaModalService: {},
184 $timeout: timeout,
185 $uibModal: {},
186 $window: {}
187 });
188
189 //act
190 scope.cancelar();
191
192 //assert
193 expect($location.url()).toEqual('/precio-condicion');
194 });
195 });
196
197 it('La funcion $scope.guardar llama a servicio.guardarPrecioCondicion', function() {
198 inject(function($location) {
199 //arrange
200 var scope = {};
201 var focaAbmPreciosCondicionesService = {
202 obtenerPrecioCondicion: function() {
203 return {
204 then: function() { }
205 };
206 },
207 guardarPrecioCondicion: function() { }
208 };
209 var window = {
210 location: {
211 assign: function() { }
212 }
213 };
214 $controller('focaAbmPrecioCondicionController', {
215 $scope: scope,
216 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService,
217 focaBotoneraLateralService: {},
218 $routeParams: {},
219 $location: $location,
220 focaModalService: {},
221 $timeout: timeout,
222 $uibModal: {},
223 $window: window
224 });
225 var promesaGuardarPrecioCondicion = Promise.resolve(true);
226 scope.precioCondicion = { listaPrecio: {} };
227
228 //act
229 //spyOn(window, 'location').and.returnValue({ assign: function() {} });
230 spyOn(focaAbmPreciosCondicionesService, 'guardarPrecioCondicion')
231 .and.returnValue(promesaGuardarPrecioCondicion);
232 scope.guardar();
233
234 //assert
235 expect(focaAbmPreciosCondicionesService.guardarPrecioCondicion).toHaveBeenCalled();
236 });
237 });
238
239 it('La funcion $scope.solicitarConfirmacionPlazoPago levanta modal confirm', function() {
240 //act
241 var scope = {};
242 var focaModalService = {
243 confirm: function() { }
244 };
245 $controller('focaAbmPrecioCondicionController', {
246 $scope: scope,
247 focaAbmPreciosCondicionesService: {
248 obtenerPrecioCondicion: function() {
249 return {
250 then:function() { }
251 };
252 }
253 },
254 focaBotoneraLateralService: {},
255 $routeParams: {},
256 $location: {},
257 focaModalService: focaModalService,
258 $timeout: timeout,
259 $uibModal: {},
260 $window: {}
261 });
262
263 //act
264 spyOn(focaModalService, 'confirm')
265 .and.returnValue({ then: function() {} });
266 scope.solicitarConfirmacionPlazoPago({ data: 'test' });
267
268 //assert
269 expect(focaModalService.confirm).toHaveBeenCalled();
270 });
271
272 it('La funcion $scope.solicitarConfirmacionPlazoPago borra al dar ok', function(done) {
273 //act
274 var scope = {};
275 var focaModalService = {
276 confirm: function() { }
277 };
278 var focaAbmPreciosCondicionesService = {
279 obtenerPrecioCondicion: function() {
280 return {
281 then:function() { }
282 };
283 },
284 borrarPlazoPago: function() { }
285 };
286 $controller('focaAbmPrecioCondicionController', {
287 $scope: scope,
288 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService,
289 focaBotoneraLateralService: {},
290 $routeParams: {},
291 $location: {},
292 focaModalService: focaModalService,
293 $timeout: timeout,
294 $uibModal: {},
295 $window: {}
296 });
297 var promesaConfirm = Promise.resolve(true);
298 scope.precioCondicion = {
299 plazos: []
300 };
301
302 //act
303 spyOn(focaModalService, 'confirm').and.returnValue(promesaConfirm);
304 spyOn(focaAbmPreciosCondicionesService, 'borrarPlazoPago');
305 scope.solicitarConfirmacionPlazoPago({ data: 'test' });
306
307 //assert
308 promesaConfirm.then(function() {
309 expect(focaAbmPreciosCondicionesService.borrarPlazoPago).toHaveBeenCalled();
310 done();
311 });
312 });
313
314 it('La funcion $scope.seleccionarListaPrecio levanta modal', function() {
315 //arrange
316 var scope = {};
317 var uibModal = {
318 open: function() { }
319 };
320 var focaAbmPreciosCondicionesService = {
321 obtenerPrecioCondicion: function() {
322 return {
323 then:function() { }
324 };
325 }
326 };
327 $controller('focaAbmPrecioCondicionController', {
328 $scope: scope,
329 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService,
330 focaBotoneraLateralService: {},
331 $routeParams: {},
332 $location: {},
333 focaModalService: {},
334 $timeout: timeout,
335 $uibModal: uibModal,
336 $window: {}
337 });
338
339 //act
340 spyOn(uibModal, 'open').and.returnValue({ result: { then: function() { } } });
341 scope.seleccionarListaPrecio(13);
342
343 //assert
344 expect(uibModal.open).toHaveBeenCalled();
345 });
346
347 it('La funcion $scope.verProductosListaPrecio levanta modal', function() {
348 //arrange
349 var scope = {};
350 var uibModal = {
351 open: function() { }
352 };
353 var focaAbmPreciosCondicionesService = {
354 obtenerPrecioCondicion: function() {
355 return {
356 then:function() { }
357 };
358 }
359 };
360 $controller('focaAbmPrecioCondicionController', {
361 $scope: scope,
362 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService,
363 focaBotoneraLateralService: {},
364 $routeParams: {},
365 $location: {},
366 focaModalService: {},
367 $timeout: timeout,
368 $uibModal: uibModal,
369 $window: {}
370 });
371 scope.precioCondicion = {
372 listaPrecio: {}
373 };
374 //act
375 spyOn(uibModal, 'open');
376 scope.verProductosListaPrecio();
377
378 //assert
379 expect(uibModal.open).toHaveBeenCalled();
380 });
381
382 it('la función next suma uno a $scope.focused', function() {
383 //arrange
384 var scope = {};
385 var focaAbmPreciosCondicionesService = {
386 obtenerPrecioCondicion: function() {
387 return {
388 then:function() { }
389 };
390 }
391 };
392 $controller('focaAbmPrecioCondicionController', {
393 $scope: scope,
394 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService,
395 focaBotoneraLateralService: {},
396 $routeParams: {},
397 $location: {},
398 focaModalService: {},
399 $timeout: timeout,
400 $uibModal: {},
401 $window: {}
402 });
403
404 //act
405 var esperado = scope.focused + 1;
406 scope.next(13);
407
408 //assert
409 expect(scope.focused).toEqual(esperado);
410 });
411 });
412 });
413
File was created 1 describe('Rutas de abm precios condiciones', function() {
2
3 var route;
4
5 beforeEach(function() {
6 module('focaAbmPreciosCondiciones');
7 inject(function($route) {
8 route = $route;
9 });
10 });
11
12 it('Ruta /precio-condicion dirije correctamente', function() {
13 //assert
14 expect(route.routes['/precio-condicion'].controller)
15 .toBe('focaAbmPreciosCondicionesController');
16 expect(route.routes['/precio-condicion'].templateUrl)
17 .toBe('src/views/foca-abm-precios-condiciones-listado.html');
18 });
19
20 it('Ruta /precio-condicion/:id dirije correctamente', function() {
21 //assert
22 expect(route.routes['/precio-condicion/:id'].controller)
23 .toBe('focaAbmPrecioCondicionController');
24 expect(route.routes['/precio-condicion/:id'].templateUrl)
25 .toBe('src/views/foca-abm-precios-condiciones-item.html');
26 });
27 });
28
File was created 1 describe('Servicios abm precios condiciones', function() {
2
3 var httpBackend;
4
5 beforeEach(function() {
6 module('focaAbmPreciosCondiciones');
7
8 inject(module(function($provide) {
9 $provide.value('API_ENDPOINT', {
10 URL: 'localhost'
11 });
12 }));
13 });
14
15 describe('servicio focaAbmPreciosCondicionesService', function() {
16
17 var servicio;
18
19 beforeEach(function() {
20 inject(function(focaAbmPreciosCondicionesService, $httpBackend) {
21 servicio = focaAbmPreciosCondicionesService;
22 httpBackend = $httpBackend;
23 });
24 });
25
26 it('existe el servicio focaAbmPreciosCondicionesService', function() {
27 //assert
28 expect(typeof servicio).toEqual('object');
29 });
30
31 it('la función obtenerPreciosCondiciones llama ruta correcta', function() {
32 //arrange
33 var responseFake = { data: 'test'};
34 var result;
35 var bodyFake = 1;
36 httpBackend.expectPOST('localhost/precios-condiciones', { nombre: bodyFake })
37 .respond(responseFake);
38
39 //act
40 servicio.obtenerPreciosCondiciones(bodyFake).then(function(data) {
41 result = data.data;
42 });
43 httpBackend.flush();
44
45 //assert
46 expect(result).toEqual(responseFake);
47 });
48
49 it('la función obtenerPrecioCondicion llama ruta correcta', function() {
50 //arrange
51 var responseFake = { data: 'test'};
52 var result;
53 var paramFake = 1;
54 httpBackend.expectGET('localhost/precio-condicion/' + paramFake)
55 .respond(responseFake);
56
57 //act
58 servicio.obtenerPrecioCondicion(paramFake).then(function(data) {
59 result = data.data;
60 });
61 httpBackend.flush();
62
63 //assert
64 expect(result).toEqual(responseFake);
65 });
66
67 it('la función guardarPrecioCondicion llama ruta correcta', function() {
68 //arrange
69 var responseFake = { data: 'test'};
70 var result;
71 var bodyFake = 1;
72 httpBackend.expectPOST('localhost/precio-condicion', { precioCondicion: bodyFake })
73 .respond(responseFake);
74
75 //act
76 servicio.guardarPrecioCondicion(bodyFake).then(function(data) {
77 result = data.data;
78 });
79 httpBackend.flush();
80
81 //assert
82 expect(result).toEqual(responseFake);
83 });
84
85 it('la función borrarPrecioCondicion llama ruta correcta', function() {
86 //arrange
87 var responseFake = { data: 'test'};
88 var result;
89 var paramFake = 1;
90 httpBackend.expectDELETE('localhost/precio-condicion/' + paramFake)
91 .respond(responseFake);
92
93 //act
94 servicio.borrarPrecioCondicion(paramFake).then(function(data) {
95 result = data.data;
96 });
97 httpBackend.flush();
98
99 //assert
100 expect(result).toEqual(responseFake);
101 });
102
103 it('la función obtenerPlazoPago llama ruta correcta', function() {
104 //arrange
105 var responseFake = { data: 'test'};
106 var result;
107 var paramFake = 1;
108 httpBackend.expectGET('localhost/plazo-pago/precio-condicion/' + paramFake)
109 .respond(responseFake);
110
111 //act
112 servicio.obtenerPlazoPago(paramFake).then(function(data) {
113 result = data.data;
114 });
115 httpBackend.flush();
116
117 //assert
118 expect(result).toEqual(responseFake);
119 });
120
121 it('la función borrarPlazoPago llama ruta correcta', function() {
122 //arrange
123 var responseFake = { data: 'test'};
124 var result;
125 var paramFake = 1;
126 httpBackend.expectDELETE('localhost/plazo-pago/' + paramFake)
127 .respond(responseFake);
128
129 //act
130 servicio.borrarPlazoPago(paramFake).then(function(data) {
131 result = data.data;
132 });
133 httpBackend.flush();
134
135 //assert
136 expect(result).toEqual(responseFake);
137 });
138
139 it('la función guardarPlazosPago llama ruta correcta', function() {
140 //arrange
141 var responseFake = { data: 'test'};
142 var result;
143 var bodyFake = 1;
144 httpBackend.expectPOST('localhost/plazos-pago', { plazosPago: bodyFake})
145 .respond(responseFake);
146
147 //act
148 servicio.guardarPlazosPago(bodyFake).then(function(data) {
149 result = data.data;
150 });
151 httpBackend.flush();
152
153 //assert
154 expect(result).toEqual(responseFake);
155 });
156 });
157 });
158
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