Commit 68149af34afebb06c9f0993d09c5ef87b7cfd4c7

Authored by Jose Pinto
Exists in master

Merge branch 'master' into 'develop'

Master

See merge request !14
spec/controllerSpec.js
1 describe('Controladores abm precios condiciones', function() { 1 describe('Controladores abm precios condiciones', function() {
2 2
3 var $controller; 3 var $controller;
4 var timeout; 4 var timeout;
5 5
6 beforeEach(function() { 6 beforeEach(function() {
7 module('focaAbmPreciosCondiciones'); 7 module('focaAbmPreciosCondiciones');
8 inject(function(_$controller_) { 8 inject(function(_$controller_) {
9 $controller = _$controller_; 9 $controller = _$controller_;
10 }); 10 });
11 }); 11 });
12 12
13 beforeEach(function() { 13 beforeEach(function() {
14 inject(function($timeout) { 14 inject(function($timeout) {
15 timeout = $timeout; 15 timeout = $timeout;
16 }); 16 });
17 }); 17 });
18 18
19 describe('Controlador focaAbmPreciosCondiciones', function() { 19 describe('Controlador focaAbmPreciosCondiciones', function() {
20 20
21 it('Existe el controlador', function() { 21 it('Existe el controlador', function() {
22 //act 22 //act
23 var controlador = $controller('focaAbmPreciosCondicionesController', { 23 var controlador = $controller('focaAbmPreciosCondicionesController', {
24 $scope: {}, 24 $scope: {},
25 focaAbmPreciosCondicionesService: {}, 25 focaAbmPreciosCondicionesService: {},
26 $location: {}, 26 $location: {},
27 focaModalService: {}, 27 focaModalService: {},
28 $localStorage: {},
28 focaBotoneraLateralService: {}, 29 focaBotoneraLateralService: {},
29 $timeout: timeout 30 $timeout: timeout
30 }); 31 });
31 32
32 //assert 33 //assert
33 expect(typeof controlador).toEqual('object'); 34 expect(typeof controlador).toEqual('object');
34 }); 35 });
35 36
36 it('$scope.editar lleva a la ruta correcta', function() { 37 it('$scope.editar lleva a la ruta correcta', function() {
37 inject(function($location) { 38 inject(function($location) {
38 //arrange 39 //arrange
39 var scope = {}; 40 var scope = {};
40 var paramFake = 1; 41 var paramFake = 1;
41 $controller('focaAbmPreciosCondicionesController', { 42 $controller('focaAbmPreciosCondicionesController', {
42 $scope: scope, 43 $scope: scope,
43 focaAbmPreciosCondicionesService: {}, 44 focaAbmPreciosCondicionesService: {},
44 $location: $location, 45 $location: $location,
46 $localStorage: {},
45 focaModalService: {}, 47 focaModalService: {},
46 focaBotoneraLateralService: {}, 48 focaBotoneraLateralService: {},
47 $timeout: timeout 49 $timeout: timeout
48 }); 50 });
49 51
50 52
51 //act 53 //act
52 scope.editar(paramFake); 54 scope.editar(paramFake);
53 55
54 //assert 56 //assert
55 expect($location.url()).toEqual('/precio-condicion/' + paramFake); 57 expect($location.url()).toEqual('/precio-condicion/' + paramFake);
56 }); 58 });
57 }); 59 });
58 60
59 it('$scope.solicitarConfirmacion levanta modal confirm', function() { 61 it('$scope.solicitarConfirmacion levanta modal confirm', function() {
60 //arrange 62 //arrange
61 var scope = {}; 63 var scope = {};
62 var paramFake = 1; 64 var paramFake = 1;
63 var focaModalService = { 65 var focaModalService = {
64 confirm: function() { } 66 confirm: function() { }
65 }; 67 };
66 $controller('focaAbmPreciosCondicionesController', { 68 $controller('focaAbmPreciosCondicionesController', {
67 $scope: scope, 69 $scope: scope,
68 focaAbmPreciosCondicionesService: {}, 70 focaAbmPreciosCondicionesService: {},
69 $location: {}, 71 $location: {},
72 $localStorage: {},
70 focaModalService: focaModalService, 73 focaModalService: focaModalService,
71 focaBotoneraLateralService: {}, 74 focaBotoneraLateralService: {},
72 $timeout: timeout 75 $timeout: timeout
73 }); 76 });
74 77
75 //act 78 //act
76 spyOn(focaModalService, 'confirm').and.returnValue({ then: function() { }}); 79 spyOn(focaModalService, 'confirm').and.returnValue({ then: function() { }});
77 scope.solicitarConfirmacion(paramFake); 80 scope.solicitarConfirmacion(paramFake);
78 81
79 //assert 82 //assert
80 expect(focaModalService.confirm).toHaveBeenCalled(); 83 expect(focaModalService.confirm).toHaveBeenCalled();
81 }); 84 });
82 85
83 it('$scope.solicitarConfirmacion elimina al confirmar ok', function(done) { 86 it('$scope.solicitarConfirmacion elimina al confirmar ok', function(done) {
84 //arrange 87 //arrange
85 var scope = {}; 88 var scope = {};
86 var paramFake = 1; 89 var paramFake = 1;
87 var focaModalService = { 90 var focaModalService = {
88 confirm: function() { } 91 confirm: function() { }
89 }; 92 };
90 var focaAbmPreciosCondicionesService = { 93 var focaAbmPreciosCondicionesService = {
91 borrarPrecioCondicion: function() { } 94 borrarPrecioCondicion: function() { }
92 }; 95 };
93 $controller('focaAbmPreciosCondicionesController', { 96 $controller('focaAbmPreciosCondicionesController', {
94 $scope: scope, 97 $scope: scope,
95 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, 98 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService,
96 $location: {}, 99 $location: {},
100 $localStorage: {},
97 focaModalService: focaModalService, 101 focaModalService: focaModalService,
98 focaBotoneraLateralService: {}, 102 focaBotoneraLateralService: {},
99 $timeout: timeout 103 $timeout: timeout
100 }); 104 });
101 var promesaConfirm = Promise.resolve(true); 105 var promesaConfirm = Promise.resolve(true);
102 scope.preciosCondiciones = []; 106 scope.preciosCondiciones = [];
103 107
104 //act 108 //act
105 spyOn(focaModalService, 'confirm').and.returnValue(promesaConfirm); 109 spyOn(focaModalService, 'confirm').and.returnValue(promesaConfirm);
106 spyOn(focaAbmPreciosCondicionesService, 'borrarPrecioCondicion'); 110 spyOn(focaAbmPreciosCondicionesService, 'borrarPrecioCondicion');
107 scope.solicitarConfirmacion(paramFake); 111 scope.solicitarConfirmacion(paramFake);
108 112
109 //assert 113 //assert
110 promesaConfirm.then(function() { 114 promesaConfirm.then(function() {
111 expect(focaAbmPreciosCondicionesService.borrarPrecioCondicion).toHaveBeenCalled(); 115 expect(focaAbmPreciosCondicionesService.borrarPrecioCondicion).toHaveBeenCalled();
112 done(); 116 done();
113 }); 117 });
114 }); 118 });
115 119
116 it('$scope.buscar llama a obtenerPreciosCondiciones', function() { 120 it('$scope.buscar llama a obtenerPreciosCondiciones', function() {
117 //arrange 121 //arrange
118 var scope = {}; 122 var scope = {};
119 var focaAbmPreciosCondicionesService = { 123 var focaAbmPreciosCondicionesService = {
120 obtenerPreciosCondiciones: function() { } 124 obtenerPreciosCondiciones: function() { }
121 }; 125 };
122 $controller('focaAbmPreciosCondicionesController', { 126 $controller('focaAbmPreciosCondicionesController', {
123 $scope: scope, 127 $scope: scope,
124 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, 128 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService,
125 $location: {}, 129 $location: {},
130 $localStorage: {},
126 focaModalService: {}, 131 focaModalService: {},
127 focaBotoneraLateralService: {}, 132 focaBotoneraLateralService: {},
128 $timeout: timeout 133 $timeout: timeout
129 }); 134 });
130 135
131 //act 136 //act
132 spyOn(focaAbmPreciosCondicionesService, 'obtenerPreciosCondiciones') 137 spyOn(focaAbmPreciosCondicionesService, 'obtenerPreciosCondiciones')
133 .and.returnValue({ then: function() { }}); 138 .and.returnValue({ then: function() { }});
134 scope.buscar(13); 139 scope.buscar(13);
135 140
136 //assert 141 //assert
137 expect(focaAbmPreciosCondicionesService.obtenerPreciosCondiciones).toHaveBeenCalled(); 142 expect(focaAbmPreciosCondicionesService.obtenerPreciosCondiciones).toHaveBeenCalled();
138 }); 143 });
139 }); 144 });
140 145
141 describe('Controlador focaAbmPrecioCondicionController', function() { 146 describe('Controlador focaAbmPrecioCondicionController', function() {
142 147
143 it('Existe el controlador focaAbmPrecioCondicionController', function() { 148 it('Existe el controlador focaAbmPrecioCondicionController', function() {
144 //act 149 //act
145 var controlador = $controller('focaAbmPrecioCondicionController', { 150 var controlador = $controller('focaAbmPrecioCondicionController', {
146 $scope: {}, 151 $scope: {
152 $watch: function(){}
153 },
147 focaAbmPreciosCondicionesService: { 154 focaAbmPreciosCondicionesService: {
148 obtenerPrecioCondicion: function() { 155 obtenerPrecioCondicion: function() {
149 return { 156 return {
150 then: function() { } 157 then: function() { }
151 }; 158 };
152 } 159 }
153 }, 160 },
154 focaBotoneraLateralService: {}, 161 focaBotoneraLateralService: {},
155 $routeParams: {}, 162 $routeParams: {},
156 $location: {}, 163 $location: {},
157 focaModalService: {}, 164 focaModalService: {},
158 $timeout: timeout, 165 $timeout: timeout,
159 $uibModal: {}, 166 $uibModal: {},
167 $localStorage: {},
160 $window: {} 168 $window: {}
161 }); 169 });
162 170
163 //assert 171 //assert
164 expect(typeof controlador).toEqual('object'); 172 expect(typeof controlador).toEqual('object');
165 }); 173 });
166 174
167 it('La funcion $scope.cancelar lleva a la ruta correcta', function() { 175 it('La funcion $scope.cancelar lleva a la ruta correcta', function() {
168 inject(function($location) { 176 inject(function($location) {
169 //arrange 177 //arrange
170 var scope = {}; 178 var scope = {
179 $watch: function() {},
180 salir: function() {},
181 formPrecioCondicion: ''
182 };
171 $controller('focaAbmPrecioCondicionController', { 183 $controller('focaAbmPrecioCondicionController', {
172 $scope: scope, 184 $scope: scope,
173 focaAbmPreciosCondicionesService: { 185 focaAbmPreciosCondicionesService: {
174 obtenerPrecioCondicion: function() { 186 obtenerPrecioCondicion: function() {
175 return { 187 return {
176 then: function() { } 188 then: function() { }
177 }; 189 };
178 } 190 }
179 }, 191 },
180 focaBotoneraLateralService: {}, 192 focaBotoneraLateralService: {},
181 $routeParams: {}, 193 $routeParams: {},
182 $location: $location, 194 $location: $location,
195 $localStorage: {},
183 focaModalService: {}, 196 focaModalService: {},
184 $timeout: timeout, 197 $timeout: timeout,
185 $uibModal: {}, 198 $uibModal: {},
186 $window: {} 199 $window: {}
187 }); 200 });
188 201
189 //act 202 //act
190 scope.cancelar(); 203 scope.salir();
191 204
192 //assert 205 //assert
193 expect($location.url()).toEqual('/precio-condicion'); 206 expect($location.url()).toEqual('/precio-condicion');
194 }); 207 });
195 }); 208 });
196 209
197 it('La funcion $scope.guardar llama a servicio.guardarPrecioCondicion', function() { 210 it('La funcion $scope.guardar llama a servicio.guardarPrecioCondicion', function() {
198 inject(function($location) { 211 inject(function($location) {
199 //arrange 212 //arrange
200 var scope = {}; 213 var scope = {
214 $watch: function() { }
215 };
201 var focaAbmPreciosCondicionesService = { 216 var focaAbmPreciosCondicionesService = {
202 obtenerPrecioCondicion: function() { 217 obtenerPrecioCondicion: function() {
203 return { 218 return {
204 then: function() { } 219 then: function() { }
205 }; 220 };
206 }, 221 },
207 guardarPrecioCondicion: function() { } 222 guardarPrecioCondicion: function() { }
208 }; 223 };
209 var window = { 224 var window = {
210 location: { 225 location: {
211 assign: function() { } 226 assign: function() { }
212 } 227 }
213 }; 228 };
214 $controller('focaAbmPrecioCondicionController', { 229 $controller('focaAbmPrecioCondicionController', {
215 $scope: scope, 230 $scope: scope,
216 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, 231 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService,
217 focaBotoneraLateralService: {}, 232 focaBotoneraLateralService: {},
218 $routeParams: {}, 233 $routeParams: {},
219 $location: $location, 234 $location: $location,
220 focaModalService: {}, 235 focaModalService: {
236 alert: function() {}
237 },
221 $timeout: timeout, 238 $timeout: timeout,
222 $uibModal: {}, 239 $uibModal: {},
240 $localStorage: {},
223 $window: window 241 $window: window
224 }); 242 });
225 var promesaGuardarPrecioCondicion = Promise.resolve(true); 243 var promesaGuardarPrecioCondicion = Promise.resolve(true);
226 scope.precioCondicion = { listaPrecio: {} }; 244 scope.precioCondicion = {
245 listaPrecio: {},
246 nombre: true,
247 descripcion: true,
248 idListaPrecio: true
249 };
227 250
228 //act 251 //act
229 //spyOn(window, 'location').and.returnValue({ assign: function() {} }); 252 //spyOn(window, 'location').and.returnValue({ assign: function() {} });
230 spyOn(focaAbmPreciosCondicionesService, 'guardarPrecioCondicion') 253 spyOn(focaAbmPreciosCondicionesService, 'guardarPrecioCondicion')
231 .and.returnValue(promesaGuardarPrecioCondicion); 254 .and.returnValue(promesaGuardarPrecioCondicion);
232 scope.guardar(); 255 scope.guardar();
233 256
234 //assert 257 //assert
235 expect(focaAbmPreciosCondicionesService.guardarPrecioCondicion).toHaveBeenCalled(); 258 expect(focaAbmPreciosCondicionesService.guardarPrecioCondicion).toHaveBeenCalled();
236 }); 259 });
237 }); 260 });
238 261
239 it('La funcion $scope.solicitarConfirmacionPlazoPago levanta modal confirm', function() { 262 it('La funcion $scope.solicitarConfirmacionPlazoPago levanta modal confirm', function() {
240 //act 263 //act
241 var scope = {}; 264 var scope = {
265 $watch: function() {}
266 };
242 var focaModalService = { 267 var focaModalService = {
243 confirm: function() { } 268 confirm: function() { }
244 }; 269 };
245 $controller('focaAbmPrecioCondicionController', { 270 $controller('focaAbmPrecioCondicionController', {
246 $scope: scope, 271 $scope: scope,
247 focaAbmPreciosCondicionesService: { 272 focaAbmPreciosCondicionesService: {
248 obtenerPrecioCondicion: function() { 273 obtenerPrecioCondicion: function() {
249 return { 274 return {
250 then:function() { } 275 then:function() { }
251 }; 276 };
252 } 277 }
253 }, 278 },
254 focaBotoneraLateralService: {}, 279 focaBotoneraLateralService: {},
255 $routeParams: {}, 280 $routeParams: {},
256 $location: {}, 281 $location: {},
257 focaModalService: focaModalService, 282 focaModalService: focaModalService,
258 $timeout: timeout, 283 $timeout: timeout,
259 $uibModal: {}, 284 $uibModal: {},
285 $localStorage: {},
260 $window: {} 286 $window: {}
261 }); 287 });
262 288
263 //act 289 //act
264 spyOn(focaModalService, 'confirm') 290 spyOn(focaModalService, 'confirm')
265 .and.returnValue({ then: function() {} }); 291 .and.returnValue({ then: function() {} });
266 scope.solicitarConfirmacionPlazoPago({ data: 'test' }); 292 scope.solicitarConfirmacionPlazoPago({ data: 'test' });
267 293
268 //assert 294 //assert
269 expect(focaModalService.confirm).toHaveBeenCalled(); 295 expect(focaModalService.confirm).toHaveBeenCalled();
270 }); 296 });
271 297
272 it('La funcion $scope.solicitarConfirmacionPlazoPago borra al dar ok', function(done) { 298 it('La funcion $scope.solicitarConfirmacionPlazoPago borra al dar ok', function(done) {
273 //act 299 //act
274 var scope = {}; 300 var scope = {
301 $watch: function() { }
302 };
275 var focaModalService = { 303 var focaModalService = {
276 confirm: function() { } 304 confirm: function() { }
277 }; 305 };
278 var focaAbmPreciosCondicionesService = { 306 var focaAbmPreciosCondicionesService = {
279 obtenerPrecioCondicion: function() { 307 obtenerPrecioCondicion: function() {
280 return { 308 return {
281 then:function() { } 309 then:function() { }
282 }; 310 };
283 }, 311 },
284 borrarPlazoPago: function() { } 312 borrarPlazoPago: function() { }
285 }; 313 };
286 $controller('focaAbmPrecioCondicionController', { 314 $controller('focaAbmPrecioCondicionController', {
287 $scope: scope, 315 $scope: scope,
288 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, 316 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService,
289 focaBotoneraLateralService: {}, 317 focaBotoneraLateralService: {},
290 $routeParams: {}, 318 $routeParams: {},
291 $location: {}, 319 $location: {},
292 focaModalService: focaModalService, 320 focaModalService: focaModalService,
293 $timeout: timeout, 321 $timeout: timeout,
322 $localStorage: {},
294 $uibModal: {}, 323 $uibModal: {},
295 $window: {} 324 $window: {}
296 }); 325 });
297 var promesaConfirm = Promise.resolve(true); 326 var promesaConfirm = Promise.resolve(true);
298 scope.precioCondicion = { 327 scope.precioCondicion = {
299 plazos: [] 328 plazos: []
300 }; 329 };
301 330
302 //act 331 //act
303 spyOn(focaModalService, 'confirm').and.returnValue(promesaConfirm); 332 spyOn(focaModalService, 'confirm').and.returnValue(promesaConfirm);
304 spyOn(focaAbmPreciosCondicionesService, 'borrarPlazoPago'); 333 spyOn(focaAbmPreciosCondicionesService, 'borrarPlazoPago');
305 scope.solicitarConfirmacionPlazoPago({ data: 'test' }); 334 scope.solicitarConfirmacionPlazoPago({ data: 'test' });
306 335
307 //assert 336 //assert
308 promesaConfirm.then(function() { 337 promesaConfirm.then(function() {
309 expect(focaAbmPreciosCondicionesService.borrarPlazoPago).toHaveBeenCalled(); 338 expect(focaAbmPreciosCondicionesService.borrarPlazoPago).toHaveBeenCalled();
310 done(); 339 done();
311 }); 340 });
312 }); 341 });
313 342
314 it('La funcion $scope.seleccionarListaPrecio levanta modal', function() { 343 it('La funcion $scope.seleccionarListaPrecio levanta modal', function() {
315 //arrange 344 //arrange
316 var scope = {}; 345 var scope = {
346 $watch: function() {}
347 };
317 var uibModal = { 348 var uibModal = {
318 open: function() { } 349 open: function() { }
319 }; 350 };
320 var focaAbmPreciosCondicionesService = { 351 var focaAbmPreciosCondicionesService = {
321 obtenerPrecioCondicion: function() { 352 obtenerPrecioCondicion: function() {
322 return { 353 return {
323 then:function() { } 354 then:function() { }
324 }; 355 };
325 } 356 }
326 }; 357 };
327 $controller('focaAbmPrecioCondicionController', { 358 $controller('focaAbmPrecioCondicionController', {
328 $scope: scope, 359 $scope: scope,
329 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, 360 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService,
330 focaBotoneraLateralService: {}, 361 focaBotoneraLateralService: {},
331 $routeParams: {}, 362 $routeParams: {},
332 $location: {}, 363 $location: {},
333 focaModalService: {}, 364 focaModalService: {},
334 $timeout: timeout, 365 $timeout: timeout,
335 $uibModal: uibModal, 366 $uibModal: uibModal,
367 $localStorage: {},
336 $window: {} 368 $window: {}
337 }); 369 });
338 370
339 //act 371 //act
340 spyOn(uibModal, 'open').and.returnValue({ result: { then: function() { } } }); 372 spyOn(uibModal, 'open').and.returnValue({ result: { then: function() { } } });
341 scope.seleccionarListaPrecio(13); 373 scope.seleccionarListaPrecio(13);
342 374
343 //assert 375 //assert
344 expect(uibModal.open).toHaveBeenCalled(); 376 expect(uibModal.open).toHaveBeenCalled();
345 }); 377 });
346 378
347 it('La funcion $scope.verProductosListaPrecio levanta modal', function() { 379 it('La funcion $scope.verProductosListaPrecio levanta modal', function() {
348 //arrange 380 //arrange
349 var scope = {}; 381 var scope = {
382 $watch: function() {}
383 };
350 var uibModal = { 384 var uibModal = {
351 open: function() { } 385 open: function() { }
352 }; 386 };
353 var focaAbmPreciosCondicionesService = { 387 var focaAbmPreciosCondicionesService = {
354 obtenerPrecioCondicion: function() { 388 obtenerPrecioCondicion: function() {
355 return { 389 return {
356 then:function() { } 390 then:function() { }
357 }; 391 };
358 } 392 }
359 }; 393 };
360 $controller('focaAbmPrecioCondicionController', { 394 $controller('focaAbmPrecioCondicionController', {
361 $scope: scope, 395 $scope: scope,
362 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, 396 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService,
363 focaBotoneraLateralService: {}, 397 focaBotoneraLateralService: {},
364 $routeParams: {}, 398 $routeParams: {},
365 $location: {}, 399 $location: {},
366 focaModalService: {}, 400 focaModalService: {},
367 $timeout: timeout, 401 $timeout: timeout,
368 $uibModal: uibModal, 402 $uibModal: uibModal,
403 $localStorage: {},
369 $window: {} 404 $window: {}
370 }); 405 });
371 scope.precioCondicion = { 406 scope.precioCondicion = {
372 listaPrecio: {} 407 listaPrecio: {}
373 }; 408 };
374 //act 409 //act
375 spyOn(uibModal, 'open'); 410 spyOn(uibModal, 'open');
376 scope.verProductosListaPrecio(); 411 scope.verProductosListaPrecio();
377 412
378 //assert 413 //assert
379 expect(uibModal.open).toHaveBeenCalled(); 414 expect(uibModal.open).toHaveBeenCalled();
380 }); 415 });
381 416
382 it('la función next suma uno a $scope.focused', function() { 417 it('la función next suma uno a $scope.focused', function() {
383 //arrange 418 //arrange
384 var scope = {}; 419 var scope = {
420 $watch: function() {}
421 };
385 var focaAbmPreciosCondicionesService = { 422 var focaAbmPreciosCondicionesService = {
386 obtenerPrecioCondicion: function() { 423 obtenerPrecioCondicion: function() {
387 return { 424 return {
388 then:function() { } 425 then:function() { }
389 }; 426 };
390 } 427 }
391 }; 428 };
392 $controller('focaAbmPrecioCondicionController', { 429 $controller('focaAbmPrecioCondicionController', {
393 $scope: scope, 430 $scope: scope,
394 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, 431 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService,
395 focaBotoneraLateralService: {}, 432 focaBotoneraLateralService: {},
396 $routeParams: {}, 433 $routeParams: {},
397 $location: {}, 434 $location: {},
398 focaModalService: {}, 435 focaModalService: {},
399 $timeout: timeout, 436 $timeout: timeout,
400 $uibModal: {}, 437 $uibModal: {},
438 $localStorage: {},
401 $window: {} 439 $window: {}
402 }); 440 });
403 441
404 //act 442 //act
405 var esperado = scope.focused + 1; 443 var esperado = scope.focused + 1;
406 scope.next(13); 444 scope.next(13);
407 445
408 //assert 446 //assert
409 expect(scope.focused).toEqual(esperado); 447 expect(scope.focused).toEqual(esperado);
410 }); 448 });
411 }); 449 });
412 }); 450 });
413 451
src/js/controller.js
1 angular.module('focaAbmPreciosCondiciones') 1 angular.module('focaAbmPreciosCondiciones')
2 .controller('focaAbmPreciosCondicionesController', [ 2 .controller('focaAbmPreciosCondicionesController', [
3 '$scope', 'focaAbmPreciosCondicionesService', '$location', 3 '$scope', 'focaAbmPreciosCondicionesService', '$location',
4 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$localStorage', 4 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$localStorage',
5 function($scope, focaAbmPreciosCondicionesService, $location, 5 function($scope, focaAbmPreciosCondicionesService, $location,
6 focaModalService, focaBotoneraLateralService, $timeout, $localStorage) { 6 focaModalService, focaBotoneraLateralService, $timeout, $localStorage) {
7 7
8 $timeout(function() { 8 $timeout(function() {
9 focaBotoneraLateralService.showSalir(true); 9 focaBotoneraLateralService.showSalir(true);
10 focaBotoneraLateralService.showPausar(false); 10 focaBotoneraLateralService.showPausar(false);
11 focaBotoneraLateralService.showCancelar(false); 11 focaBotoneraLateralService.showCancelar(false);
12 focaBotoneraLateralService.showGuardar(false); 12 focaBotoneraLateralService.showGuardar(false);
13 }); 13 });
14 14
15 $scope.filters = ''; 15 $scope.filters = '';
16 $scope.now = new Date(); 16 $scope.now = new Date();
17 $scope.editar = function(id) { 17 $scope.editar = function(id) {
18 $location.path('/precio-condicion/' + id); 18 $location.path('/precio-condicion/' + id);
19 }; 19 };
20 $scope.solicitarConfirmacion = function(precioCondicion) { 20 $scope.solicitarConfirmacion = function(precioCondicion) {
21 focaModalService.confirm('¿Está seguro que desea borrar el precio condición' + 21 focaModalService.confirm('¿Está seguro que desea borrar el precio condición' +
22 precioCondicion.codigo + ' ' + precioCondicion.nombre + ' ?').then( 22 precioCondicion.codigo + ' ' + precioCondicion.nombre + ' ?').then(
23 function(data) { 23 function(data) {
24 if (data) { 24 if (data) {
25 focaAbmPreciosCondicionesService 25 focaAbmPreciosCondicionesService
26 .borrarPrecioCondicion(precioCondicion.id); 26 .borrarPrecioCondicion(precioCondicion.id);
27 $scope.preciosCondiciones.splice( 27 $scope.preciosCondiciones.splice(
28 $scope.preciosCondiciones.indexOf(precioCondicion), 1 28 $scope.preciosCondiciones.indexOf(precioCondicion), 1
29 ); 29 );
30 } 30 }
31 } 31 }
32 ); 32 );
33 }; 33 };
34 34
35 $scope.buscar = function(key) { 35 $scope.buscar = function(key) {
36 if(key === 13){ 36 if(key === 13){
37 focaAbmPreciosCondicionesService 37 focaAbmPreciosCondicionesService
38 .obtenerPreciosCondiciones($scope.filters) 38 .obtenerPreciosCondiciones($scope.filters)
39 .then(function(datos) { 39 .then(function(datos) {
40 $scope.preciosCondiciones = datos.data; 40 $scope.preciosCondiciones = datos.data;
41 $scope.preciosCondiciones.forEach(function(precioCondicion) { 41 $scope.preciosCondiciones.forEach(function(precioCondicion) {
42 precioCondicion.plazoPago.sort(function(a, b) { 42 precioCondicion.plazoPago.sort(function(a, b) {
43 return a.dias- b.dias; 43 return a.dias- b.dias;
44 }); 44 });
45 }); 45 });
46 }); 46 });
47 } 47 }
48 }; 48 };
49 49
50 if ($localStorage.precioCondicion) { 50 if ($localStorage.precioCondicion) {
51 var precioCondicion = JSON.parse($localStorage.precioCondicion); 51 var precioCondicion = JSON.parse($localStorage.precioCondicion);
52 if (!precioCondicion.id) { precioCondicion.id = 0; } 52 if (!precioCondicion.id) { precioCondicion.id = 0; }
53 $location.path('/precio-condicion/' + precioCondicion.id); 53 $location.path('/precio-condicion/' + precioCondicion.id);
54 } 54 }
55 } 55 }
56 ]) 56 ])
57 .controller('focaAbmPrecioCondicionController', [ 57 .controller('focaAbmPrecioCondicionController', [
58 '$scope', 'focaAbmPreciosCondicionesService', 'focaBotoneraLateralService', 58 '$scope', 'focaAbmPreciosCondicionesService', 'focaBotoneraLateralService',
59 '$routeParams', '$location', 'focaModalService', '$timeout', '$uibModal', '$window', '$localStorage', '$filter', 59 '$routeParams', '$location', 'focaModalService', '$timeout', '$uibModal', '$window', '$localStorage', '$filter',
60 function( 60 function(
61 $scope, focaAbmPreciosCondicionesService, focaBotoneraLateralService, 61 $scope, focaAbmPreciosCondicionesService, focaBotoneraLateralService,
62 $routeParams, $location, focaModalService, $timeout, $uibModal, $window, $localStorage, $filter) { 62 $routeParams, $location, focaModalService, $timeout, $uibModal, $window, $localStorage, $filter) {
63 $scope.focused = 1; 63 $scope.focused = 1;
64 $scope.plazosAEliminar = []; 64 $scope.plazosAEliminar = [];
65 $scope.mostrarPlazos = $routeParams.id > 0; 65 $scope.mostrarPlazos = $routeParams.id > 0;
66 $scope.now = new Date(); 66 $scope.now = new Date();
67 $scope.listaPrecioLabel = ''; 67 $scope.listaPrecioLabel = '';
68 focaAbmPreciosCondicionesService.obtenerPrecioCondicion($routeParams.id) 68 focaAbmPreciosCondicionesService.obtenerPrecioCondicion($routeParams.id)
69 .then(function(datos) { 69 .then(function(datos) {
70 $scope.precioCondicion = { 70 $scope.precioCondicion = {
71 id: 0, 71 id: 0,
72 codigo: '', 72 codigo: '',
73 nombre: '', 73 nombre: '',
74 descripcion: '', 74 descripcion: '',
75 idListaPrecio: 0, 75 idListaPrecio: 0,
76 vigencia: new Date() 76 vigencia: new Date()
77 }; 77 };
78 if (datos.data.id) { 78 if (datos.data.id) {
79 $scope.precioCondicion = datos.data; 79 $scope.precioCondicion = datos.data;
80 $scope.listaPrecioLabel = datos.data.listaPrecio.ID.trim() + 80 $scope.listaPrecioLabel = datos.data.listaPrecio.ID.trim() +
81 ' - ' + datos.data.listaPrecio.DES; 81 ' - ' + datos.data.listaPrecio.DES;
82 $scope.$broadcast('addCabecera', { 82 $scope.$broadcast('addCabecera', {
83 label: 'Precio y condición:', 83 label: 'Precio y condición:',
84 valor: datos.data.nombre 84 valor: datos.data.nombre
85 }); 85 });
86 focaAbmPreciosCondicionesService.obtenerPlazoPago(datos.data.id) 86 focaAbmPreciosCondicionesService.obtenerPlazoPago(datos.data.id)
87 .then(function(datos) { 87 .then(function(datos) {
88 $scope.precioCondicion.plazos = datos.data; 88 $scope.precioCondicion.plazos = datos.data;
89 $scope.precioCondicion.plazos.sort(function(a, b) { 89 $scope.precioCondicion.plazos.sort(function(a, b) {
90 return a.dias- b.dias; 90 return a.dias- b.dias;
91 }); 91 });
92 $scope.plazoACargar = 92 $scope.plazoACargar =
93 { 93 {
94 item: datos.data.length + 1 94 item: datos.data.length + 1
95 }; 95 };
96 }); 96 });
97 } 97 }
98 }); 98 });
99 99
100 $timeout(function() {getLSPrecioC();}); 100 $timeout(function() {getLSPrecioC();});
101 101
102 $timeout(function() { 102 $timeout(function() {
103 focaBotoneraLateralService.showSalir(false); 103 focaBotoneraLateralService.showSalir(false);
104 focaBotoneraLateralService.showPausar(true); 104 focaBotoneraLateralService.showPausar(true);
105 focaBotoneraLateralService.showCancelar(false); 105 focaBotoneraLateralService.showCancelar(false);
106 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 106 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
107 focaBotoneraLateralService.addCustomButton('Cancelar', $scope.cancelar); 107 focaBotoneraLateralService.addCustomButton('Salir', $scope.salir);
108 }); 108 });
109 109
110 $scope.cancelar = function() { 110 $scope.salir = function() {
111 111
112 if ($scope.formPrecioCondicion.$pristine == false) { 112 if ($scope.formPrecioCondicion.$pristine == false) {
113 focaModalService.confirm( 113 focaModalService.confirm(
114 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 114 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
115 ).then(function(data) { 115 ).then(function(data) {
116 if (data) { 116 if (data) {
117 $location.path('/precio-condicion'); 117 $location.path('/precio-condicion');
118 } 118 }
119 }); 119 });
120 } else {
121 $location.path('/precio-condicion');
120 } 122 }
121 }; 123 };
122 $scope.guardar = function() { 124 $scope.guardar = function() {
123 125
124 if (!$scope.precioCondicion.nombre) { 126 if (!$scope.precioCondicion.nombre) {
125 focaModalService.alert('Ingrese nombre'); 127 focaModalService.alert('Ingrese nombre');
126 return; 128 return;
127 } else if (!$scope.precioCondicion.descripcion) { 129 } else if (!$scope.precioCondicion.descripcion) {
128 focaModalService.alert('Ingrese descripcion'); 130 focaModalService.alert('Ingrese descripcion');
129 return; 131 return;
130 } else if (!$scope.precioCondicion.idListaPrecio) { 132 } else if (!$scope.precioCondicion.idListaPrecio) {
131 focaModalService.alert('Seleccione precio'); 133 focaModalService.alert('Seleccione precio');
132 return; 134 return;
133 } 135 }
134 136
135 var promises = []; 137 var promises = [];
136 var precioCondicion = $scope.precioCondicion; 138 var precioCondicion = $scope.precioCondicion;
137 precioCondicion.idListaPrecio = precioCondicion.listaPrecio.ID; 139 precioCondicion.idListaPrecio = precioCondicion.listaPrecio.ID;
138 delete precioCondicion.listaPrecio; 140 delete precioCondicion.listaPrecio;
139 if ($scope.mostrarPlazos) { 141 if ($scope.mostrarPlazos) {
140 promises.push( 142 promises.push(
141 focaAbmPreciosCondicionesService 143 focaAbmPreciosCondicionesService
142 .guardarPlazosPago($scope.precioCondicion.plazos) 144 .guardarPlazosPago($scope.precioCondicion.plazos)
143 ); 145 );
144 $scope.plazosAEliminar.forEach(function(id) { 146 $scope.plazosAEliminar.forEach(function(id) {
145 promises.push( 147 promises.push(
146 focaAbmPreciosCondicionesService 148 focaAbmPreciosCondicionesService
147 .borrarPlazoPago(id) 149 .borrarPlazoPago(id)
148 ); 150 );
149 }); 151 });
150 } 152 }
151 promises.push( 153 promises.push(
152 focaAbmPreciosCondicionesService 154 focaAbmPreciosCondicionesService
153 .guardarPrecioCondicion(precioCondicion) 155 .guardarPrecioCondicion(precioCondicion)
154 ); 156 );
155 157
156 Promise.all(promises).then(function() { 158 Promise.all(promises).then(function() {
157 $timeout(function() { 159 $timeout(function() {
158 $location.path('/precio-condicion'); 160 $location.path('/precio-condicion');
159 }, 0); 161 }, 0);
160 }, function(err){ 162 }, function(err){
161 console.error(err); 163 console.error(err);
162 }); 164 });
163 }; 165 };
164 166
165 $scope.agregarPlazo = function(key) { 167 $scope.agregarPlazo = function(key) {
166 if (key === 13) { 168 if (key === 13) {
167 if (!$scope.plazoACargar.dias && $scope.plazoACargar.dias !== 0) { 169 if (!$scope.plazoACargar.dias && $scope.plazoACargar.dias !== 0) {
168 focaModalService.alert('Ingrese cantidad de días'); 170 focaModalService.alert('Ingrese cantidad de días');
169 return; 171 return;
170 } 172 }
171 var tieneEseDia = $scope.precioCondicion.plazos.filter(function(a) { 173 var tieneEseDia = $scope.precioCondicion.plazos.filter(function(a) {
172 return a.dias === $scope.plazoACargar.dias; 174 return a.dias === $scope.plazoACargar.dias;
173 }); 175 });
174 if (tieneEseDia.length > 0) { 176 if (tieneEseDia.length > 0) {
175 focaModalService.alert('Ya ha ingresado un plazo con esos días'); 177 focaModalService.alert('Ya ha ingresado un plazo con esos días');
176 return; 178 return;
177 } 179 }
178 $scope.plazoACargar.idPreciosCondiciones = $scope.precioCondicion.id; 180 $scope.plazoACargar.idPreciosCondiciones = $scope.precioCondicion.id;
179 $scope.plazoACargar.activo = true; 181 $scope.plazoACargar.activo = true;
180 $scope.precioCondicion.plazos.push($scope.plazoACargar); 182 $scope.precioCondicion.plazos.push($scope.plazoACargar);
181 $scope.plazoACargar = 183 $scope.plazoACargar =
182 { 184 {
183 item: $scope.precioCondicion.plazos.length + 1 185 item: $scope.precioCondicion.plazos.length + 1
184 }; 186 };
185 } 187 }
186 }; 188 };
187 $scope.quitarPlazo = function(key) { 189 $scope.quitarPlazo = function(key) {
188 if ($scope.precioCondicion.plazos[key].id) 190 if ($scope.precioCondicion.plazos[key].id)
189 $scope.plazosAEliminar.push($scope.precioCondicion.plazos[key].id); 191 $scope.plazosAEliminar.push($scope.precioCondicion.plazos[key].id);
190 192
191 $scope.precioCondicion.plazos.splice(key, 1); 193 $scope.precioCondicion.plazos.splice(key, 1);
192 $scope.plazoACargar = 194 $scope.plazoACargar =
193 { 195 {
194 item: $scope.precioCondicion.plazos.length + 1 196 item: $scope.precioCondicion.plazos.length + 1
195 }; 197 };
196 }; 198 };
197 $scope.solicitarConfirmacionPlazoPago = function(plazoPago) { 199 $scope.solicitarConfirmacionPlazoPago = function(plazoPago) {
198 focaModalService.confirm('¿Está seguro que desea borrar el plazo de pago ' + 200 focaModalService.confirm('¿Está seguro que desea borrar el plazo de pago ' +
199 plazoPago.item + ' ' + plazoPago.dias + ' ?').then( 201 plazoPago.item + ' ' + plazoPago.dias + ' ?').then(
200 function(confirm) { 202 function(confirm) {
201 if (confirm) { 203 if (confirm) {
202 focaAbmPreciosCondicionesService.borrarPlazoPago(plazoPago.id); 204 focaAbmPreciosCondicionesService.borrarPlazoPago(plazoPago.id);
203 $scope.precioCondicion.plazos.splice( 205 $scope.precioCondicion.plazos.splice(
204 $scope.precioCondicion.plazos.indexOf(plazoPago), 1 206 $scope.precioCondicion.plazos.indexOf(plazoPago), 1
205 ); 207 );
206 } 208 }
207 } 209 }
208 ); 210 );
209 }; 211 };
210 212
211 $scope.seleccionarListaPrecio = function(key) { 213 $scope.seleccionarListaPrecio = function(key) {
212 if (key === 13){ 214 if (key === 13){
213 var modalInstance = $uibModal.open( 215 var modalInstance = $uibModal.open(
214 { 216 {
215 ariaLabelledBy: 'Busqueda de Listas de precio', 217 ariaLabelledBy: 'Busqueda de Listas de precio',
216 templateUrl: 'modal-lista-precio.html', 218 templateUrl: 'modal-lista-precio.html',
217 controller: 'focaModalListaPrecioCtrl', 219 controller: 'focaModalListaPrecioCtrl',
218 size: 'lg' 220 size: 'lg'
219 } 221 }
220 ); 222 );
221 modalInstance.result.then(function(listaPrecio) { 223 modalInstance.result.then(function(listaPrecio) {
222 $scope.precioCondicion.idListaPrecio = listaPrecio.ID; 224 $scope.precioCondicion.idListaPrecio = listaPrecio.ID;
223 $scope.precioCondicion.listaPrecio = listaPrecio; 225 $scope.precioCondicion.listaPrecio = listaPrecio;
224 $scope.listaPrecioLabel = listaPrecio.ID + ' - ' + listaPrecio.DES; 226 $scope.listaPrecioLabel = listaPrecio.ID + ' - ' + listaPrecio.DES;
225 $scope.focused = 4; 227 $scope.focused = 4;
226 }); 228 });
227 } 229 }
228 }; 230 };
229 231
230 $scope.verProductosListaPrecio = function() { 232 $scope.verProductosListaPrecio = function() {
231 $uibModal.open( 233 $uibModal.open(
232 { 234 {
233 ariaLabelledBy: 'Busqueda de Productos', 235 ariaLabelledBy: 'Busqueda de Productos',
234 templateUrl: 'modal-busqueda-productos.html', 236 templateUrl: 'modal-busqueda-productos.html',
235 controller: 'modalBusquedaProductosCtrl', 237 controller: 'modalBusquedaProductosCtrl',
236 resolve: { 238 resolve: {
237 parametroProducto: { 239 parametroProducto: {
238 idLista: $scope.precioCondicion.listaPrecio.ID, 240 idLista: $scope.precioCondicion.listaPrecio.ID,
239 cotizacion: 1, 241 cotizacion: 1,
240 simbolo: '$', 242 simbolo: '$',
241 soloMostrar: true 243 soloMostrar: true
242 } 244 }
243 }, 245 },
244 size: 'md' 246 size: 'md'
245 } 247 }
246 ); 248 );
247 }; 249 };
248 250
249 $scope.next = function(key) { 251 $scope.next = function(key) {
250 if (key === 13) $scope.focused++; 252 if (key === 13) $scope.focused++;
251 }; 253 };
252 254
253 //watch 255 //watch
254 $scope.$watch('precioCondicion', function(newValue) { 256 $scope.$watch('precioCondicion', function(newValue) {
255 focaBotoneraLateralService.setPausarData({ 257 focaBotoneraLateralService.setPausarData({
256 label: 'precioCondicion', 258 label: 'precioCondicion',
257 val: newValue 259 val: newValue
258 }); 260 });
259 }, true); 261 }, true);
260 262
261 function setearPrecioCondicion(precioCondicion) { 263 function setearPrecioCondicion(precioCondicion) {
262 $scope.precioCondicion = precioCondicion; 264 $scope.precioCondicion = precioCondicion;
263 $scope.$broadcast('addCabecera', { 265 $scope.$broadcast('addCabecera', {
264 label: 'Precio y Condicion:', 266 label: 'Precio y Condicion:',
265 valor: $filter('rellenarDigitos')(precioCondicion.id) 267 valor: $filter('rellenarDigitos')(precioCondicion.id)
266 }); 268 });
267 } 269 }
268 270
269 function getLSPrecioC() { 271 function getLSPrecioC() {
270 var precioCondicion = JSON.parse($localStorage.precioCondicion || null); 272 var precioCondicion = JSON.parse($localStorage.precioCondicion || null);
271 273
272 if (precioCondicion) { 274 if (precioCondicion) {
273 setearPrecioCondicion(precioCondicion); 275 setearPrecioCondicion(precioCondicion);
274 delete $localStorage.precioCondicion; 276 delete $localStorage.precioCondicion;
275 } 277 }
276 } 278 }
277 } 279 }
278 ]); 280 ]);
279 281