Commit b6b9b95ae9a5ff26e047a4b6fcf099e5663a6a79

Authored by Nicolás Guarnieri
Exists in master and in 1 other branch develop

Merge branch 'master' into 'master'

Master

See merge request !30
1 const templateCache = require('gulp-angular-templatecache'); 1 const templateCache = require('gulp-angular-templatecache');
2 const concat = require('gulp-concat'); 2 const concat = require('gulp-concat');
3 const htmlmin = require('gulp-htmlmin'); 3 const htmlmin = require('gulp-htmlmin');
4 const rename = require('gulp-rename'); 4 const rename = require('gulp-rename');
5 const uglify = require('gulp-uglify-es').default; 5 const uglify = require('gulp-uglify-es').default;
6 const gulp = require('gulp'); 6 const gulp = require('gulp');
7 const pump = require('pump'); 7 const pump = require('pump');
8 const jshint = require('gulp-jshint'); 8 const jshint = require('gulp-jshint');
9 const replace = require('gulp-replace'); 9 const replace = require('gulp-replace');
10 const connect = require('gulp-connect'); 10 const connect = require('gulp-connect');
11 const clean = require('gulp-clean'); 11 const clean = require('gulp-clean');
12 const header = require('gulp-header');
13 const footer = require('gulp-footer');
12 14
13 var paths = { 15 var paths = {
14 srcJS: 'src/js/*.js', 16 srcJS: 'src/js/*.js',
15 srcViews: 'src/views/*.html', 17 srcViews: 'src/views/*.html',
18 specs: 'spec/*.js',
16 tmp: 'tmp', 19 tmp: 'tmp',
17 dist: 'dist/' 20 dist: 'dist/'
18 }; 21 };
19 22
20 gulp.task('templates', function() { 23 gulp.task('templates', function() {
21 return pump( 24 return pump(
22 [ 25 [
23 gulp.src(paths.srcViews), 26 gulp.src(paths.srcViews),
24 replace('views/', ''), 27 replace('views/', ''),
25 htmlmin(), 28 htmlmin(),
26 templateCache('views.js', { 29 templateCache('views.js', {
27 module: 'focaAbmVehiculo', 30 module: 'focaAbmVehiculo',
28 root: '' 31 root: ''
29 }), 32 }),
30 gulp.dest(paths.tmp) 33 gulp.dest(paths.tmp)
31 ] 34 ]
32 ); 35 );
33 }); 36 });
34 37
35 gulp.task('uglify', ['templates'], function() { 38 gulp.task('uglify', ['templates'], function() {
36 return pump( 39 return pump(
37 [ 40 [
38 gulp.src([ 41 gulp.src([
39 paths.srcJS, 42 paths.srcJS,
40 'tmp/views.js' 43 'tmp/views.js'
41 ]), 44 ]),
42 concat('foca-abm-vehiculo.js'), 45 concat('foca-abm-vehiculo.js'),
43 replace("['ngRoute', 'focaModal', 'ui.bootstrap', 'focaBotoneraLateral']", '[]'),
44 replace("src/views/", ''), 46 replace("src/views/", ''),
47 replace("'ngRoute'", ''),
45 gulp.dest(paths.tmp), 48 gulp.dest(paths.tmp),
46 rename('foca-abm-vehiculo.min.js'), 49 rename('foca-abm-vehiculo.min.js'),
47 uglify(), 50 uglify(),
48 gulp.dest(paths.dist) 51 gulp.dest(paths.dist)
49 ] 52 ]
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 gulp.task('clean', function() { 66 gulp.task('clean', function() {
54 return gulp.src(['tmp', 'dist'], {read: false}) 67 return gulp.src(['tmp', 'dist'], {read: false})
55 .pipe(clean()); 68 .pipe(clean());
56 }); 69 });
57 70
58 gulp.task('pre-commit', function() { 71 gulp.task('pre-commit', function() {
59 return pump( 72 return pump(
60 [ 73 [
61 gulp.src(paths.srcJS), 74 gulp.src([paths.srcJS, paths.specs]),
62 jshint('.jshintrc'), 75 jshint('.jshintrc'),
63 jshint.reporter('default'), 76 jshint.reporter('default'),
64 jshint.reporter('fail') 77 jshint.reporter('fail')
65 ] 78 ]
66 ); 79 );
67 }); 80 });
68 81
69 gulp.task('clean-post-install', function() { 82 gulp.task('clean-post-install', function() {
70 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', 83 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js',
71 'index.html'], {read: false}) 84 'index.html'], {read: false})
72 .pipe(clean()); 85 .pipe(clean());
73 }); 86 });
74 87
75 gulp.task('compile', ['templates', 'uglify']); 88 gulp.task('compile', ['templates', 'uglify']);
76 89
77 gulp.task('watch', function() { 90 gulp.task('watch', function() {
78 gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); 91 gulp.watch([paths.srcJS, paths.srcViews], ['uglify']);
79 }); 92 });
80 93
81 gulp.task('webserver', function() { 94 gulp.task('webserver', function() {
82 pump [ 95 pump [
83 connect.server({port: 3000}) 96 connect.server({port: 3000})
84 ] 97 ]
85 }); 98 });
86 99
87 gulp.task('default', ['webserver']); 100 gulp.task('default', ['webserver']);
1 <html ng-app="focaAbmVehiculo"> 1 <html ng-app="focaAbmVehiculo">
2 <head> 2 <head>
3 <meta charset="UTF-8"/> 3 <meta charset="UTF-8"/>
4 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> 4 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
5 5
6 <!--CSS--> 6 <!--CSS-->
7 <link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"/> 7 <link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"/>
8 <link href="node_modules/font-awesome/css/font-awesome.min.css" rel="stylesheet"/> 8 <link href="node_modules/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
9 9
10 <!--VENDOR JS--> 10 <!--VENDOR JS-->
11 <script src="node_modules/jquery/dist/jquery.min.js"></script> 11 <script src="node_modules/jquery/dist/jquery.min.js"></script>
12 <script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script> 12 <script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
13 <script src="node_modules/angular/angular.min.js"></script> 13 <script src="node_modules/angular/angular.min.js"></script>
14 <script src="node_modules/angular-route/angular-route.min.js"></script> 14 <script src="node_modules/angular-route/angular-route.min.js"></script>
15 <script src="node_modules/ui-bootstrap4/dist/ui-bootstrap-tpls.js"></script> 15 <script src="node_modules/ui-bootstrap4/dist/ui-bootstrap-tpls.js"></script>
16 <script src="node_modules/foca-modal/dist/foca-modal.min.js"></script> 16 <script src="node_modules/foca-modal/dist/foca-modal.min.js"></script>
17 17
18 <!-- BUILD --> 18 <!-- BUILD -->
19 <script src="src/js/app.js"></script> 19 <script src="src/js/app.js"></script>
20 <script src="src/js/route.js"></script> 20 <script src="src/js/route.js"></script>
21 <script src="src/js/controller.js"></script> 21 <script src="src/js/controller.js"></script>
22 <script src="src/js/service.js"></script> 22 <script src="src/js/service.js"></script>
23 <!-- /BUILD --> 23 <!-- /BUILD -->
24 24
25 <!-- CONFIG PARA DEVELOP --> 25 <!-- CONFIG PARA DEVELOP -->
26 <script src="src/etc/develop.js"></script> 26 <script src="src/etc/develop.js"></script>
27 </head> 27 </head>
28 <body style="background: #afafaf;padding: 25px"> 28 <body style="background: #afafaf;padding: 25px">
29 <div class="container-fluid pt-3 pb-3" ng-view style="background: #fff"></div> 29 <div class="container-fluid pt-3 pb-3" ng-view style="background: #fff"></div>
30 </body> 30 </body>
31 </html> 31 </html>
32 32
1 { 1 {
2 "name": "foca-abm-vehiculo", 2 "name": "foca-abm-vehiculo",
3 "version": "0.0.1", 3 "version": "0.0.1",
4 "description": "Abm de vehiculo", 4 "description": "Abm de vehiculo",
5 "main": "index.html", 5 "main": "index.html",
6 "scripts": { 6 "scripts": {
7 "test": "echo \"Error: no test specified\" && exit 1", 7 "test": "echo \"Error: no test specified\" && exit 1",
8 "compile": "gulp uglify", 8 "compile": "gulp uglify",
9 "gulp-pre-commit": "gulp pre-commit", 9 "gulp-pre-commit": "gulp pre-commit",
10 "postinstall": "npm run compile && gulp clean-post-install", 10 "postinstall": "npm run compile && gulp clean-post-install",
11 "install-dev": "npm install -D angular bootstrap ui-bootstrap4 font-awesome jquery gulp gulp-connect jasmine-core pre-commit gulp-angular-templatecache gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-uglify-es gulp-uglify gulp-clean jshint pump git+http://git.focasoftware.com/npm/foca-modal.git" 11 "install-dev": "npm install -D angular bootstrap ui-bootstrap4 font-awesome jquery gulp gulp-connect jasmine-core pre-commit gulp-angular-templatecache gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-uglify-es gulp-uglify gulp-clean jshint pump git+http://git.focasoftware.com/npm/foca-modal.git"
12 }, 12 },
13 "pre-commit": [ 13 "pre-commit": [
14 "gulp-pre-commit" 14 "gulp-pre-commit"
15 ], 15 ],
16 "repository": { 16 "repository": {
17 "type": "git", 17 "type": "git",
18 "url": "http://git.focasoftware.com/npm/foca-abm-vehiculo.git" 18 "url": "http://git.focasoftware.com/npm/foca-abm-vehiculo.git"
19 }, 19 },
20 "author": "Foca Software", 20 "author": "Foca Software",
21 "license": "ISC", 21 "license": "ISC",
22 "peerDependencies": { 22 "peerDependencies": {
23 "angular": "^1.7.x", 23 "angular": "^1.7.x",
24 "angular-route": "^1.7.x", 24 "angular-route": "^1.7.x",
25 "bootstrap": "^4.1.x", 25 "bootstrap": "^4.1.x",
26 "jquery": "^3.3.x", 26 "jquery": "^3.3.x",
27 "font-awesome": "^4.7.x", 27 "font-awesome": "^4.7.x",
28 "gulp": "^3.9.x", 28 "gulp": "^3.9.x",
29 "gulp-concat": "2.6.x", 29 "gulp-concat": "2.6.x",
30 "gulp-jshint": "^2.1.x", 30 "gulp-jshint": "^2.1.x",
31 "gulp-rename": "^1.4.x", 31 "gulp-rename": "^1.4.x",
32 "gulp-replace": "^1.0.x", 32 "gulp-replace": "^1.0.x",
33 "gulp-uglify-es": "^1.0.x", 33 "gulp-uglify-es": "^1.0.x",
34 "jshint": "^2.9.x", 34 "jshint": "^2.9.x",
35 "pump": "^3.0.x" 35 "pump": "^3.0.x"
36 }, 36 },
37 "devDependencies": { 37 "devDependencies": {
38 "angular": "^1.7.5", 38 "angular": "^1.7.5",
39 "angular-route": "^1.7.5", 39 "angular-mocks": "^1.7.7",
40 "angular-route": "^1.7.7",
40 "bootstrap": "^4.1.3", 41 "bootstrap": "^4.1.3",
41 "foca-modal": "git+http://git.focasoftware.com/npm/foca-modal.git", 42 "foca-modal": "git+http://git.focasoftware.com/npm/foca-modal.git",
42 "font-awesome": "^4.7.0", 43 "font-awesome": "^4.7.0",
43 "gulp": "^3.9.1", 44 "gulp": "^3.9.1",
44 "gulp-angular-templatecache": "^2.2.5", 45 "gulp-angular-templatecache": "^2.2.5",
45 "gulp-clean": "^0.4.0", 46 "gulp-clean": "^0.4.0",
46 "gulp-connect": "^5.6.1", 47 "gulp-connect": "^5.6.1",
48 "gulp-footer": "^2.0.2",
49 "gulp-header": "^2.0.7",
47 "gulp-htmlmin": "^5.0.1", 50 "gulp-htmlmin": "^5.0.1",
48 "gulp-jshint": "^2.1.0", 51 "gulp-jshint": "^2.1.0",
49 "gulp-rename": "^1.4.0", 52 "gulp-rename": "^1.4.0",
50 "gulp-replace": "^1.0.0", 53 "gulp-replace": "^1.0.0",
51 "gulp-uglify": "^3.0.1", 54 "gulp-uglify": "^3.0.1",
52 "gulp-uglify-es": "^1.0.4", 55 "gulp-uglify-es": "^1.0.4",
56 "jasmine": "^3.3.1",
53 "jasmine-core": "^3.3.0", 57 "jasmine-core": "^3.3.0",
54 "jquery": "^3.3.1", 58 "jquery": "^3.3.1",
55 "jshint": "^2.9.6", 59 "jshint": "^2.9.6",
56 "pre-commit": "^1.2.2", 60 "pre-commit": "^1.2.2",
57 "pump": "^3.0.0", 61 "pump": "^3.0.0",
58 "ui-bootstrap4": "^3.0.5" 62 "ui-bootstrap4": "^3.0.5"
59 } 63 }
60 } 64 }
61 65
spec/controllerSpec.js
File was created 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 });
622
File was created 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 });
45
File was created 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 });
179
1 angular.module('focaAbmVehiculo', ['ngRoute', 'focaModal', 'ui.bootstrap', 'focaBotoneraLateral']); 1 angular.module('focaAbmVehiculo', ['ngRoute']);
2 2
src/js/controller.js
1 angular.module('focaAbmVehiculo') 1 angular.module('focaAbmVehiculo')
2 .controller('focaAbmVehiculosController', [ 2 .controller('focaAbmVehiculosController', [
3 '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', 3 '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService',
4 '$uibModal', 'focaBotoneraLateralService', '$timeout', 4 '$uibModal', 'focaBotoneraLateralService', '$timeout',
5 function($scope, focaAbmVehiculoService, $location, focaModalService, 5 function($scope, focaAbmVehiculoService, $location, focaModalService,
6 $uibModal, focaBotoneraLateralService, $timeout) { 6 $uibModal, focaBotoneraLateralService, $timeout) {
7 7
8 $scope.now = new Date(); 8 $scope.now = new Date();
9 $scope.botonera = [{ 9 $scope.botonera = [{
10 label: 'Transportista', 10 label: 'Transportista',
11 image: 'cliente.png' 11 image: 'cliente.png'
12 }]; 12 }];
13 13
14 focaAbmVehiculoService.cleanCisternas(); 14 focaAbmVehiculoService.cleanCisternas();
15 15
16 //SETEO BOTONERA LATERAL 16 //SETEO BOTONERA LATERAL
17 focaBotoneraLateralService.showSalir(false); 17 focaBotoneraLateralService.showSalir(false);
18 focaBotoneraLateralService.showPausar(false); 18 focaBotoneraLateralService.showPausar(false);
19 focaBotoneraLateralService.showCancelar(false); 19 focaBotoneraLateralService.showCancelar(false);
20 focaBotoneraLateralService.showGuardar(false); 20 focaBotoneraLateralService.showGuardar(false);
21 focaBotoneraLateralService.addCustomButton('Salir', salir); 21 focaBotoneraLateralService.addCustomButton('Salir', salir);
22 22
23 if(focaAbmVehiculoService.transportistaSeleccionado.COD) { 23 if(focaAbmVehiculoService.transportistaSeleccionado.COD) {
24 elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); 24 elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado);
25 } 25 }
26 $scope.editar = function(id) { 26 $scope.editar = function(id) {
27 $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); 27 $location.path('/vehiculo/' + id + '/' + $scope.idTransportista);
28 }; 28 };
29 $scope.solicitarConfirmacion = function(vehiculo) { 29 $scope.solicitarConfirmacion = function(vehiculo) {
30 focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + 30 focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' +
31 vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( 31 vehiculo.id + ' ' + vehiculo.tractor + ' ?').then(
32 function(data) { 32 function(data) {
33 if(data) { 33 if(data) {
34 focaAbmVehiculoService.deleteVehiculo(vehiculo.id); 34 focaAbmVehiculoService.deleteVehiculo(vehiculo.id);
35 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); 35 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1);
36 } 36 }
37 } 37 }
38 ); 38 );
39 }; 39 };
40 $scope.seleccionarTransportista = function() { 40 $scope.seleccionarTransportista = function() {
41 var parametrosModal = { 41 var parametrosModal = {
42 titulo: 'Búsqueda de Transportista', 42 titulo: 'Búsqueda de Transportista',
43 query: '/transportista', 43 query: '/transportista',
44 columnas: [ 44 columnas: [
45 { 45 {
46 nombre: 'Código', 46 nombre: 'Código',
47 propiedad: 'COD' 47 propiedad: 'COD'
48 }, 48 },
49 { 49 {
50 nombre: 'Nombre', 50 nombre: 'Nombre',
51 propiedad: 'NOM' 51 propiedad: 'NOM'
52 }, 52 },
53 { 53 {
54 nombre: 'CUIT', 54 nombre: 'CUIT',
55 propiedad: 'CUIT' 55 propiedad: 'CUIT'
56 } 56 }
57 ] 57 ]
58 }; 58 };
59 focaModalService.modal(parametrosModal).then( 59 focaModalService.modal(parametrosModal).then(
60 function(transportista) { 60 function(transportista) {
61 elegirTransportista(transportista); 61 elegirTransportista(transportista);
62 focaAbmVehiculoService.transportistaSeleccionado = transportista; 62 focaAbmVehiculoService.transportistaSeleccionado = transportista;
63 }, function() { 63 }, function() {
64 64
65 } 65 }
66 ); 66 );
67 }; 67 };
68 function elegirTransportista(transportista) { 68 function elegirTransportista(transportista) {
69 var codigo = ('00000' + transportista.COD).slice(-5); 69 var codigo = ('00000' + transportista.COD).slice(-5);
70 $scope.idTransportista = transportista.COD; 70 $scope.idTransportista = transportista.COD;
71 $scope.filtros = transportista.NOM.trim(); 71 $scope.filtros = transportista.NOM.trim();
72 $timeout(function() { 72 $timeout(function() {
73 $scope.$broadcast('addCabecera', { 73 $scope.$broadcast('addCabecera', {
74 label: 'Transportista:', 74 label: 'Transportista:',
75 valor: codigo + ' - ' + transportista.NOM 75 valor: codigo + ' - ' + transportista.NOM
76 }); 76 });
77 }); 77 });
78 buscar(transportista.COD); 78 buscar(transportista.COD);
79 } 79 }
80 80
81 function buscar(idTransportista) { 81 function buscar(idTransportista) {
82 focaAbmVehiculoService 82 focaAbmVehiculoService
83 .getVehiculosPorTransportista(idTransportista) 83 .getVehiculosPorTransportista(idTransportista)
84 .then(function(datos) { 84 .then(function(datos) {
85 $scope.vehiculos = datos.data; 85 $scope.vehiculos = datos.data;
86 }); 86 });
87 } 87 }
88 function salir() { 88 function salir() {
89 focaAbmVehiculoService.transportistaSeleccionado = {}; 89 focaAbmVehiculoService.transportistaSeleccionado = {};
90 $location.path('/'); 90 $location.path('/');
91 } 91 }
92 } 92 }
93 ]) 93 ])
94 .controller('focaAbmVehiculoController', [ 94 .controller('focaAbmVehiculoController', [
95 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', 95 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal',
96 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window', 96 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window',
97 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, 97 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal,
98 focaModalService, $timeout, focaBotoneraLateralService, $window) { 98 focaModalService, $timeout, focaBotoneraLateralService, $window) {
99 $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; 99 $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false;
100 $scope.now = new Date(); 100 $scope.now = new Date();
101 $scope.focused = 1; 101 $scope.focused = 1;
102 $scope.transportistaStamp = ''; 102 $scope.transportistaStamp = '';
103 $scope.cisternas = []; 103 $scope.cisternas = [];
104 104
105 $timeout(function() { 105 $timeout(function() {
106 focaBotoneraLateralService.showSalir(false); 106 focaBotoneraLateralService.showSalir(false);
107 focaBotoneraLateralService.showPausar(false); 107 focaBotoneraLateralService.showPausar(false);
108 focaBotoneraLateralService.showCancelar(false); 108 focaBotoneraLateralService.showCancelar(false);
109 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 109 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
110 focaBotoneraLateralService.addCustomButton('Salir', $scope.cancelar); 110 focaBotoneraLateralService.addCustomButton('Salir', $scope.cancelar);
111 }); 111 });
112 112
113 if($scope.nuevo) { 113 if($scope.nuevo) {
114 focaAbmVehiculoService 114 focaAbmVehiculoService
115 .getTransportistaPorId($routeParams.idTransportista) 115 .getTransportistaPorId($routeParams.idTransportista)
116 .then(function(res) { 116 .then(function(res) {
117 var codigo = ('00000' + res.data.COD).slice(-5); 117 var codigo = ('00000' + res.data.COD).slice(-5);
118 $scope.vehiculo.idTransportista = res.data.COD; 118 $scope.vehiculo.idTransportista = res.data.COD;
119 $scope.vehiculo.transportista = res.data; 119 $scope.vehiculo.transportista = res.data;
120 $scope.$broadcast('addCabecera', { 120 $scope.$broadcast('addCabecera', {
121 label: 'Transportista:', 121 label: 'Transportista:',
122 valor: codigo + ' - ' + res.data.NOM 122 valor: codigo + ' - ' + res.data.NOM
123 }); 123 });
124 }); 124 });
125 } 125 }
126 $scope.vehiculo = {}; 126 $scope.vehiculo = {};
127 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { 127 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) {
128 if(res.data) { 128 if(res.data) {
129 $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); 129 $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5);
130 $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; 130 $scope.transportistaStamp += ' - ' + res.data.transportista.NOM;
131 131
132 $scope.vehiculo = res.data; 132 $scope.vehiculo = res.data;
133 $scope.$broadcast('addCabecera', { 133 $scope.$broadcast('addCabecera', {
134 label: 'Transportista:', 134 label: 'Transportista:',
135 valor: $scope.transportistaStamp 135 valor: $scope.transportistaStamp
136 }); 136 });
137 $scope.$broadcast('addCabecera', { 137 $scope.$broadcast('addCabecera', {
138 label: 'Unidad:', 138 label: 'Unidad:',
139 valor: res.data.codigo 139 valor: res.data.codigo
140 }); 140 });
141 focaAbmVehiculoService 141 focaAbmVehiculoService
142 .getCisternas($routeParams.idVehiculo) 142 .getCisternas($routeParams.idVehiculo)
143 .then(function(res) { 143 .then(function(res) {
144 $scope.cisternas = res; 144 $scope.cisternas = res;
145 $scope.$apply(); 145 $scope.$apply();
146 }); 146 });
147 } 147 }
148 }); 148 });
149 149
150 $scope.next = function(key) { 150 $scope.next = function(key) {
151 if (key === 13) $scope.focused++; 151 if (key === 13) $scope.focused++;
152 }; 152 };
153 $scope.cancelar = function() { 153 $scope.cancelar = function() {
154 $location.path('/vehiculo'); 154 $location.path('/vehiculo');
155 }; 155 };
156 $scope.editar = function(key) { 156 $scope.editar = function(key) {
157 if(key) { 157 if(key) {
158 $location.path('/vehiculo/' + $routeParams.idVehiculo + 158 $location.path('/vehiculo/' + $routeParams.idVehiculo +
159 '/cisterna/' + key); 159 '/cisterna/' + key);
160 }else { 160 } else {
161 $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); 161 $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/');
162 } 162 }
163 }; 163 };
164 $scope.guardar = function(key) { 164 $scope.guardar = function(key) {
165 key = (typeof key === 'undefined') ? 13 : key; 165 key = (typeof key === 'undefined') ? 13 : key;
166 if(key === 13) { 166 if(key === 13) {
167 //Valida si existe numero de unidad 167 //Valida si existe numero de unidad
168 if(!validaTotalCargas() && !$scope.nuevo) { 168 if(!validaTotalCargas() && !$scope.nuevo) {
169 focaModalService.alert('La suma de las capacidades de las cisternas' + 169 focaModalService.alert('La suma de las capacidades de las cisternas' +
170 ' debe ser igual a la capacidad total del vehículo'); 170 ' debe ser igual a la capacidad total del vehículo');
171 return; 171 return;
172 } 172 }
173 validaCodigoUnidad().then(function() { 173 validaCodigoUnidad().then(function() {
174 delete $scope.vehiculo.transportista; 174 delete $scope.vehiculo.transportista;
175 delete $scope.vehiculo.cisternas; 175 delete $scope.vehiculo.cisternas;
176 focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) 176 focaAbmVehiculoService.guardarVehiculo($scope.vehiculo)
177 .then(function(res) { 177 .then(function(res) {
178 if ($scope.nuevo) { 178 if ($scope.nuevo) {
179 $location.path('/vehiculo/' + res.data.id + 179 $location.path('/vehiculo/' + res.data.id +
180 '/' + res.data.idTransportista); 180 '/' + res.data.idTransportista);
181 } else { 181 } else {
182 guardarCisternas().then(function() { 182 guardarCisternas().then(function() {
183 $location.path('/vehiculo'); 183 $location.path('/vehiculo');
184 }); 184 });
185 } 185 }
186 }); 186 });
187 }, function() { 187 }, function() {
188 focaModalService.alert('Código de unidad existente'); 188 focaModalService.alert('Código de unidad existente');
189 }); 189 });
190 } 190 }
191 191
192 }; 192 };
193 $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { 193 $scope.solicitarConfirmacionCisterna = function(cisterna, idx) {
194 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + 194 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' +
195 cisterna.id + ' ' + cisterna.codigo + ' ?').then( 195 cisterna.id + ' ' + cisterna.codigo + ' ?').then(
196 function(data) { 196 function(data) {
197 if(data) { 197 if(data) {
198 focaAbmVehiculoService.deleteCisterna(idx); 198 focaAbmVehiculoService.deleteCisterna(idx);
199 focaAbmVehiculoService 199 focaAbmVehiculoService
200 .getCisternas($routeParams.idVehiculo) 200 .getCisternas($routeParams.idVehiculo)
201 .then(function(res) { 201 .then(function(res) {
202 $scope.cisternas = res; 202 $scope.cisternas = res;
203 }); 203 });
204 } 204 }
205 } 205 }
206 ); 206 );
207 }; 207 };
208 208
209 function validaCodigoUnidad() { 209 function validaCodigoUnidad() {
210 return new Promise(function(resolve, reject) { 210 return new Promise(function(resolve, reject) {
211 focaAbmVehiculoService 211 focaAbmVehiculoService
212 .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) 212 .getVehiculosPorTransportista(parseInt($routeParams.idTransportista))
213 .then(function(res) { 213 .then(function(res) {
214 //Valida si existe numero de unidad 214 //Valida si existe numero de unidad
215 var existe = res.data.filter(function(vehiculo) { 215 var existe = res.data.filter(function(vehiculo) {
216 return vehiculo.codigo === $scope.vehiculo.codigo && 216 return vehiculo.codigo === $scope.vehiculo.codigo &&
217 vehiculo.id !== $scope.vehiculo.id; 217 vehiculo.id !== $scope.vehiculo.id;
218 }); 218 });
219 219
220 if(existe.length) { 220 if(existe.length) {
221 reject(existe); 221 reject(existe);
222 }else { 222 }else {
223 resolve(); 223 resolve();
224 } 224 }
225 }); 225 });
226 }); 226 });
227 } 227 }
228 228
229 function validaTotalCargas() { 229 function validaTotalCargas() {
230 var total = 0; 230 var total = 0;
231 $scope.cisternas.forEach(function(cisterna) { 231 $scope.cisternas.forEach(function(cisterna) {
232 if(!cisterna.desactivado) { 232 if(!cisterna.desactivado) {
233 total += parseInt(cisterna.capacidad); 233 total += parseInt(cisterna.capacidad);
234 } 234 }
235 }); 235 });
236 return $scope.vehiculo.capacidad == total; 236 return $scope.vehiculo.capacidad == total;
237 } 237 }
238 238
239 function guardarCisternas() { 239 function guardarCisternas() {
240 var cisternas = $scope.cisternas.map(function(cisterna) { 240 var cisternas = $scope.cisternas.map(function(cisterna) {
241 return { 241 return {
242 id: cisterna.id, 242 id: cisterna.id,
243 capacidad: parseFloat(cisterna.capacidad), 243 capacidad: parseFloat(cisterna.capacidad),
244 codigo: cisterna.codigo, 244 codigo: cisterna.codigo,
245 idUnidadMedida: cisterna.idUnidadMedida, 245 idUnidadMedida: cisterna.idUnidadMedida,
246 idVehiculo: $routeParams.idVehiculo, 246 idVehiculo: $routeParams.idVehiculo,
247 desactivado: cisterna.desactivado 247 desactivado: cisterna.desactivado
248 }; 248 };
249 }); 249 });
250 250
251 return focaAbmVehiculoService.guardarCisternas(cisternas); 251 return focaAbmVehiculoService.guardarCisternas(cisternas);
252 } 252 }
253 } 253 }
254 ]); 254 ]);
255 255
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