Commit 43df6ec56c7d2da31127b050810e8855d76dc239
Exists in
master
and in
2 other branches
Merge branch 'master' into 'master'
Master(efernandez) See merge request !18
Showing
9 changed files
Show diff stats
gulpfile.js
| ... | ... | @@ -9,10 +9,13 @@ const jshint = require('gulp-jshint'); |
| 9 | 9 | const replace = require('gulp-replace'); |
| 10 | 10 | const connect = require('gulp-connect'); |
| 11 | 11 | const clean = require('gulp-clean'); |
| 12 | +const header = require('gulp-header'); | |
| 13 | +const footer = require('gulp-footer'); | |
| 12 | 14 | |
| 13 | 15 | var paths = { |
| 14 | 16 | srcJS: 'src/js/*.js', |
| 15 | 17 | srcViews: 'src/views/*.html', |
| 18 | + specs: 'spec/*.js', | |
| 16 | 19 | tmp: 'tmp', |
| 17 | 20 | dist: 'dist/' |
| 18 | 21 | }; |
| ... | ... | @@ -32,7 +35,7 @@ gulp.task('templates', function() { |
| 32 | 35 | ); |
| 33 | 36 | }); |
| 34 | 37 | |
| 35 | -gulp.task('uglify', ['templates'], function() { | |
| 38 | +gulp.task('uglify', ['templates', 'uglify-spec'], function() { | |
| 36 | 39 | return pump( |
| 37 | 40 | [ |
| 38 | 41 | gulp.src([ |
| ... | ... | @@ -49,27 +52,36 @@ gulp.task('uglify', ['templates'], function() { |
| 49 | 52 | ); |
| 50 | 53 | }); |
| 51 | 54 | |
| 55 | +gulp.task('uglify-spec', function() { | |
| 56 | + return pump([ | |
| 57 | + gulp.src(paths.specs), | |
| 58 | + concat('foca-abm-vendedor-cobrador.spec.js'), | |
| 59 | + replace("src/views/", ''), | |
| 60 | + header("describe('Módulo foca-abm-vendedor-cobrador', function() { \n"), | |
| 61 | + footer("});"), | |
| 62 | + gulp.dest(paths.dist) | |
| 63 | + ]); | |
| 64 | +}); | |
| 65 | + | |
| 52 | 66 | gulp.task('clean', function() { |
| 53 | 67 | return gulp.src(['tmp', 'dist'], {read: false}) |
| 54 | 68 | .pipe(clean()); |
| 55 | 69 | }); |
| 56 | 70 | |
| 57 | 71 | gulp.task('pre-commit', function() { |
| 58 | - pump( | |
| 72 | + return pump( | |
| 59 | 73 | [ |
| 60 | - gulp.src(paths.srcJS), | |
| 74 | + gulp.src([paths.srcJS, paths.specs]), | |
| 61 | 75 | jshint('.jshintrc'), |
| 62 | 76 | jshint.reporter('default'), |
| 63 | 77 | jshint.reporter('fail') |
| 64 | 78 | ] |
| 65 | 79 | ); |
| 66 | - | |
| 67 | - gulp.start('uglify'); | |
| 68 | 80 | }); |
| 69 | 81 | |
| 70 | 82 | gulp.task('clean-post-install', function() { |
| 71 | 83 | return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', |
| 72 | - 'index.html'], {read: false}) | |
| 84 | + 'index.html', 'spec', 'test.html'], {read: false}) | |
| 73 | 85 | .pipe(clean()); |
| 74 | 86 | }); |
| 75 | 87 |
package.json
spec/controllerSpec.js
| ... | ... | @@ -0,0 +1,694 @@ |
| 1 | +describe('Controladores abm vendedor cobrador', function() { | |
| 2 | + | |
| 3 | + var $controller; | |
| 4 | + | |
| 5 | + beforeEach(function() { | |
| 6 | + module('focaAbmVendedorCobrador'); | |
| 7 | + inject(function(_$controller_) { | |
| 8 | + $controller = _$controller_; | |
| 9 | + }); | |
| 10 | + }); | |
| 11 | + describe('controlador focaAbmVendedoresCobradoresController', function() { | |
| 12 | + | |
| 13 | + var focaBotoneraLateralService = { | |
| 14 | + showSalir: function() { }, | |
| 15 | + showPausar: function() { }, | |
| 16 | + showCancelar: function() { }, | |
| 17 | + showGuardar: function() { } | |
| 18 | + }; | |
| 19 | + | |
| 20 | + it('existe el controlador focaAbmVendedoresCobradoresController', function() { | |
| 21 | + //act | |
| 22 | + var controlador = $controller('focaAbmVendedoresCobradoresController', { | |
| 23 | + $scope: {}, | |
| 24 | + focaAbmVendedorCobradorService: {}, | |
| 25 | + $location: {}, | |
| 26 | + $filter: {}, | |
| 27 | + focaBotoneraLateralService: focaBotoneraLateralService, | |
| 28 | + focaModalService: {} | |
| 29 | + }); | |
| 30 | + | |
| 31 | + //arrange | |
| 32 | + expect(typeof controlador).toEqual('object'); | |
| 33 | + }); | |
| 34 | + | |
| 35 | + it('la función $scope.editar llama a la url correcta', function() { | |
| 36 | + inject(function($location) { | |
| 37 | + | |
| 38 | + //arrange | |
| 39 | + var scope = {}; | |
| 40 | + $controller('focaAbmVendedoresCobradoresController', { | |
| 41 | + $scope: scope, | |
| 42 | + focaAbmVendedorCobradorService: {}, | |
| 43 | + $location: $location, | |
| 44 | + $filter: {}, | |
| 45 | + focaBotoneraLateralService: focaBotoneraLateralService, | |
| 46 | + focaModalService: {} | |
| 47 | + }); | |
| 48 | + var paramFake = 1; | |
| 49 | + | |
| 50 | + //act | |
| 51 | + scope.editar(paramFake); | |
| 52 | + //arrange | |
| 53 | + expect($location.url()).toEqual('/vendedor-cobrador/' + paramFake); | |
| 54 | + }); | |
| 55 | + }); | |
| 56 | + | |
| 57 | + it('la función $scope.eliminar llama a modal confirmar', function() { | |
| 58 | + inject(function($location) { | |
| 59 | + | |
| 60 | + //arrange | |
| 61 | + var scope = {}; | |
| 62 | + var focaModalService = { | |
| 63 | + confirm: function() { } | |
| 64 | + }; | |
| 65 | + $controller('focaAbmVendedoresCobradoresController', { | |
| 66 | + $scope: scope, | |
| 67 | + focaAbmVendedorCobradorService: {}, | |
| 68 | + $location: $location, | |
| 69 | + $filter: {}, | |
| 70 | + focaBotoneraLateralService: focaBotoneraLateralService, | |
| 71 | + focaModalService: focaModalService | |
| 72 | + }); | |
| 73 | + var paramFake = 1; | |
| 74 | + | |
| 75 | + //act | |
| 76 | + spyOn(focaModalService, 'confirm').and.returnValue({ then: function() { } }); | |
| 77 | + scope.eliminar(paramFake); | |
| 78 | + | |
| 79 | + //arrange | |
| 80 | + expect(focaModalService.confirm).toHaveBeenCalled(); | |
| 81 | + }); | |
| 82 | + }); | |
| 83 | + | |
| 84 | + it('función $scope.eliminar llama eliminarVendedorCobrador al confirm ok', function(done) { | |
| 85 | + inject(function($location) { | |
| 86 | + | |
| 87 | + //arrange | |
| 88 | + var scope = {}; | |
| 89 | + var focaModalService = { | |
| 90 | + confirm: function() { } | |
| 91 | + }; | |
| 92 | + var focaAbmVendedorCobradorService = { | |
| 93 | + eliminarVendedorCobrador: function() { } | |
| 94 | + }; | |
| 95 | + $controller('focaAbmVendedoresCobradoresController', { | |
| 96 | + $scope: scope, | |
| 97 | + focaAbmVendedorCobradorService: focaAbmVendedorCobradorService, | |
| 98 | + $location: $location, | |
| 99 | + $filter: {}, | |
| 100 | + focaBotoneraLateralService: focaBotoneraLateralService, | |
| 101 | + focaModalService: focaModalService | |
| 102 | + }); | |
| 103 | + var paramFake = 1; | |
| 104 | + var promesaConfirmar = Promise.resolve(true); | |
| 105 | + | |
| 106 | + //act | |
| 107 | + spyOn(focaModalService, 'confirm').and.returnValue(promesaConfirmar); | |
| 108 | + spyOn(focaAbmVendedorCobradorService, 'eliminarVendedorCobrador') | |
| 109 | + .and.returnValue({ then: function() { } }); | |
| 110 | + scope.eliminar(paramFake); | |
| 111 | + | |
| 112 | + //arrange | |
| 113 | + promesaConfirmar.then(function() { | |
| 114 | + expect(focaAbmVendedorCobradorService.eliminarVendedorCobrador) | |
| 115 | + .toHaveBeenCalled(); | |
| 116 | + done(); | |
| 117 | + }); | |
| 118 | + }); | |
| 119 | + }); | |
| 120 | + | |
| 121 | + it('función $scope.resetPage llama a $scope.selectPage', function() { | |
| 122 | + | |
| 123 | + //arrange | |
| 124 | + var scope = {}; | |
| 125 | + $controller('focaAbmVendedoresCobradoresController', { | |
| 126 | + $scope: scope, | |
| 127 | + focaAbmVendedorCobradorService: {}, | |
| 128 | + $location: {}, | |
| 129 | + $filter: {}, | |
| 130 | + focaBotoneraLateralService: focaBotoneraLateralService, | |
| 131 | + focaModalService: {} | |
| 132 | + }); | |
| 133 | + | |
| 134 | + //act | |
| 135 | + spyOn(scope, 'selectPage'); | |
| 136 | + scope.resetPage(); | |
| 137 | + | |
| 138 | + //arrange | |
| 139 | + expect(scope.selectPage).toHaveBeenCalled(); | |
| 140 | + }); | |
| 141 | + | |
| 142 | + it('función $scope.search llama a getVendedoresCobradores', function() { | |
| 143 | + | |
| 144 | + //arrange | |
| 145 | + var scope = {}; | |
| 146 | + var focaAbmVendedorCobradorService = { | |
| 147 | + getVendedoresCobradores: function() { } | |
| 148 | + }; | |
| 149 | + $controller('focaAbmVendedoresCobradoresController', { | |
| 150 | + $scope: scope, | |
| 151 | + focaAbmVendedorCobradorService: focaAbmVendedorCobradorService, | |
| 152 | + $location: {}, | |
| 153 | + $filter: {}, | |
| 154 | + focaBotoneraLateralService: focaBotoneraLateralService, | |
| 155 | + focaModalService: {} | |
| 156 | + }); | |
| 157 | + | |
| 158 | + //act | |
| 159 | + spyOn(focaAbmVendedorCobradorService, 'getVendedoresCobradores') | |
| 160 | + .and.returnValue({ then: function() { } }); | |
| 161 | + scope.search(13); | |
| 162 | + | |
| 163 | + //arrange | |
| 164 | + expect(focaAbmVendedorCobradorService.getVendedoresCobradores).toHaveBeenCalled(); | |
| 165 | + }); | |
| 166 | + | |
| 167 | + it('función scope.search llama getVendedoresCobradores y llama resetPage', function(done) { | |
| 168 | + | |
| 169 | + //arrange | |
| 170 | + var scope = {}; | |
| 171 | + var focaAbmVendedorCobradorService = { | |
| 172 | + getVendedoresCobradores: function() { } | |
| 173 | + }; | |
| 174 | + $controller('focaAbmVendedoresCobradoresController', { | |
| 175 | + $scope: scope, | |
| 176 | + focaAbmVendedorCobradorService: focaAbmVendedorCobradorService, | |
| 177 | + $location: {}, | |
| 178 | + $filter: {}, | |
| 179 | + focaBotoneraLateralService: focaBotoneraLateralService, | |
| 180 | + focaModalService: {} | |
| 181 | + }); | |
| 182 | + var promesaVendedores = Promise.resolve({ data: [] }); | |
| 183 | + | |
| 184 | + //act | |
| 185 | + spyOn(focaAbmVendedorCobradorService, 'getVendedoresCobradores') | |
| 186 | + .and.returnValue(promesaVendedores); | |
| 187 | + spyOn(scope, 'resetPage'); | |
| 188 | + scope.vendedoresCobradores = []; | |
| 189 | + scope.search(13); | |
| 190 | + | |
| 191 | + //arrange | |
| 192 | + promesaVendedores.then(function() { | |
| 193 | + expect(scope.resetPage).toHaveBeenCalled(); | |
| 194 | + done(); | |
| 195 | + }); | |
| 196 | + }); | |
| 197 | + }); | |
| 198 | + | |
| 199 | + describe('Controlador focaAbmVendedorCobradorController', function() { | |
| 200 | + | |
| 201 | + var timeout; | |
| 202 | + | |
| 203 | + beforeEach(function() { | |
| 204 | + inject(function($timeout) { | |
| 205 | + timeout = $timeout; | |
| 206 | + }); | |
| 207 | + }); | |
| 208 | + | |
| 209 | + it('existe el controlador focaAbmVendedorCobradorController', function() { | |
| 210 | + | |
| 211 | + //act | |
| 212 | + var controlador = $controller('focaAbmVendedorCobradorController', { | |
| 213 | + $scope: {}, | |
| 214 | + focaAbmVendedorCobradorService: { | |
| 215 | + getCodigoSiguiente: function() { | |
| 216 | + return { | |
| 217 | + then: function() { } | |
| 218 | + }; | |
| 219 | + }, | |
| 220 | + getVendedorCobradorById: function() { | |
| 221 | + return { | |
| 222 | + then: function() { } | |
| 223 | + }; | |
| 224 | + } | |
| 225 | + }, | |
| 226 | + $routeParams: {}, | |
| 227 | + focaBotoneraLateralService: {}, | |
| 228 | + $timeout: timeout, | |
| 229 | + $uibModal: {}, | |
| 230 | + $location: {}, | |
| 231 | + focaModalService: {} | |
| 232 | + }); | |
| 233 | + | |
| 234 | + //assert | |
| 235 | + expect(typeof controlador).toEqual('object'); | |
| 236 | + }); | |
| 237 | + | |
| 238 | + it('la función $scope.guardar llama a guardaVendedorCobrador del servicio', function() { | |
| 239 | + //arrange | |
| 240 | + var scope= {}; | |
| 241 | + var focaAbmVendedorCobradorService = { | |
| 242 | + getCodigoSiguiente: function() { | |
| 243 | + return { | |
| 244 | + then: function() { } | |
| 245 | + }; | |
| 246 | + }, | |
| 247 | + getVendedorCobradorById: function() { | |
| 248 | + return { | |
| 249 | + then: function() { } | |
| 250 | + }; | |
| 251 | + }, | |
| 252 | + guardarVendedorCobrador: function() { } | |
| 253 | + }; | |
| 254 | + $controller('focaAbmVendedorCobradorController', { | |
| 255 | + $scope: scope, | |
| 256 | + focaAbmVendedorCobradorService: focaAbmVendedorCobradorService, | |
| 257 | + $routeParams: {}, | |
| 258 | + focaBotoneraLateralService: {}, | |
| 259 | + $timeout: timeout, | |
| 260 | + $uibModal: {}, | |
| 261 | + $location: {}, | |
| 262 | + focaModalService: {} | |
| 263 | + }); | |
| 264 | + var responseFake = { | |
| 265 | + then: function() { | |
| 266 | + return { | |
| 267 | + catch: function() { } | |
| 268 | + }; | |
| 269 | + } | |
| 270 | + }; | |
| 271 | + | |
| 272 | + //act | |
| 273 | + spyOn(focaAbmVendedorCobradorService, 'guardarVendedorCobrador') | |
| 274 | + .and.returnValue(responseFake); | |
| 275 | + scope.guardar(); | |
| 276 | + | |
| 277 | + //assert | |
| 278 | + expect(focaAbmVendedorCobradorService.guardarVendedorCobrador).toHaveBeenCalled(); | |
| 279 | + }); | |
| 280 | + | |
| 281 | + it('la función $scope.guardar llama a guardaVendedorCobrador y edicion true' + | |
| 282 | + 'llama a $location.path', function(done) | |
| 283 | + { | |
| 284 | + inject(function($location) { | |
| 285 | + | |
| 286 | + //arrange | |
| 287 | + var scope= {}; | |
| 288 | + var focaAbmVendedorCobradorService = { | |
| 289 | + getCodigoSiguiente: function() { | |
| 290 | + return { | |
| 291 | + then: function() { } | |
| 292 | + }; | |
| 293 | + }, | |
| 294 | + getVendedorCobradorById: function() { | |
| 295 | + return { | |
| 296 | + then: function() { } | |
| 297 | + }; | |
| 298 | + }, | |
| 299 | + guardarVendedorCobrador: function() { } | |
| 300 | + }; | |
| 301 | + $controller('focaAbmVendedorCobradorController', { | |
| 302 | + $scope: scope, | |
| 303 | + focaAbmVendedorCobradorService: focaAbmVendedorCobradorService, | |
| 304 | + $routeParams: {}, | |
| 305 | + focaBotoneraLateralService: {}, | |
| 306 | + $timeout: timeout, | |
| 307 | + $uibModal: {}, | |
| 308 | + $location: $location, | |
| 309 | + focaModalService: {} | |
| 310 | + }); | |
| 311 | + var promiseFake = Promise.resolve(true, false); | |
| 312 | + | |
| 313 | + //act | |
| 314 | + spyOn(focaAbmVendedorCobradorService, 'guardarVendedorCobrador') | |
| 315 | + .and.returnValue(promiseFake); | |
| 316 | + scope.edicion = true; | |
| 317 | + scope.guardar(); | |
| 318 | + | |
| 319 | + //assert | |
| 320 | + promiseFake.then(function() { | |
| 321 | + expect($location.url()).toEqual('/vendedor-cobrador'); | |
| 322 | + done(); | |
| 323 | + }); | |
| 324 | + }); | |
| 325 | + }); | |
| 326 | + | |
| 327 | + it('la función $scope.guardar llama a guardaVendedorCobrador y scope.edicion false' + | |
| 328 | + 'llama a scope.cambiarContraseña', function(done) | |
| 329 | + { | |
| 330 | + //arrange | |
| 331 | + var scope= {}; | |
| 332 | + var focaAbmVendedorCobradorService = { | |
| 333 | + getCodigoSiguiente: function() { | |
| 334 | + return { | |
| 335 | + then: function() { } | |
| 336 | + }; | |
| 337 | + }, | |
| 338 | + getVendedorCobradorById: function() { | |
| 339 | + return { | |
| 340 | + then: function() { } | |
| 341 | + }; | |
| 342 | + }, | |
| 343 | + guardarVendedorCobrador: function() { } | |
| 344 | + }; | |
| 345 | + $controller('focaAbmVendedorCobradorController', { | |
| 346 | + $scope: scope, | |
| 347 | + focaAbmVendedorCobradorService: focaAbmVendedorCobradorService, | |
| 348 | + $routeParams: {}, | |
| 349 | + focaBotoneraLateralService: {}, | |
| 350 | + $timeout: timeout, | |
| 351 | + $uibModal: {}, | |
| 352 | + $location: {}, | |
| 353 | + focaModalService: {} | |
| 354 | + }); | |
| 355 | + var promiseFake = Promise.resolve(true, false); | |
| 356 | + | |
| 357 | + //act | |
| 358 | + spyOn(focaAbmVendedorCobradorService, 'guardarVendedorCobrador') | |
| 359 | + .and.returnValue(promiseFake); | |
| 360 | + spyOn(scope, 'cambiarPassword'); | |
| 361 | + scope.edicion = false; | |
| 362 | + scope.guardar(); | |
| 363 | + | |
| 364 | + //assert | |
| 365 | + promiseFake.then(function() { | |
| 366 | + expect(scope.cambiarPassword).toHaveBeenCalled(); | |
| 367 | + done(); | |
| 368 | + }); | |
| 369 | + }); | |
| 370 | + | |
| 371 | + it('la función $scope.guardar llama a guardaVendedorCobrador y llama foca modal alert' + | |
| 372 | + 'cuando la promsa es rechazada y el error es 409', function(done) | |
| 373 | + { | |
| 374 | + //arrange | |
| 375 | + var scope= {}; | |
| 376 | + var focaAbmVendedorCobradorService = { | |
| 377 | + getCodigoSiguiente: function() { | |
| 378 | + return { | |
| 379 | + then: function() { } | |
| 380 | + }; | |
| 381 | + }, | |
| 382 | + getVendedorCobradorById: function() { | |
| 383 | + return { | |
| 384 | + then: function() { } | |
| 385 | + }; | |
| 386 | + }, | |
| 387 | + guardarVendedorCobrador: function() { } | |
| 388 | + }; | |
| 389 | + var focaModalService = { | |
| 390 | + alert: function() { } | |
| 391 | + }; | |
| 392 | + $controller('focaAbmVendedorCobradorController', { | |
| 393 | + $scope: scope, | |
| 394 | + focaAbmVendedorCobradorService: focaAbmVendedorCobradorService, | |
| 395 | + $routeParams: {}, | |
| 396 | + focaBotoneraLateralService: {}, | |
| 397 | + $timeout: timeout, | |
| 398 | + $uibModal: {}, | |
| 399 | + $location: {}, | |
| 400 | + focaModalService: focaModalService | |
| 401 | + }); | |
| 402 | + var promiseFake = Promise.reject({ status: 409 }); | |
| 403 | + | |
| 404 | + //act | |
| 405 | + spyOn(focaAbmVendedorCobradorService, 'guardarVendedorCobrador') | |
| 406 | + .and.returnValue(promiseFake); | |
| 407 | + spyOn(focaModalService, 'alert'); | |
| 408 | + scope.guardar(); | |
| 409 | + | |
| 410 | + //assert | |
| 411 | + promiseFake.catch(function() { | |
| 412 | + setTimeout(function() { | |
| 413 | + expect(focaModalService.alert).toHaveBeenCalled(); | |
| 414 | + done(); | |
| 415 | + }, 100); | |
| 416 | + }); | |
| 417 | + }); | |
| 418 | + | |
| 419 | + it('la función $scope.seleccionarProvincia llama a foca Modal', function() { | |
| 420 | + //arrange | |
| 421 | + var scope= {}; | |
| 422 | + var focaAbmVendedorCobradorService = { | |
| 423 | + getCodigoSiguiente: function() { | |
| 424 | + return { | |
| 425 | + then: function() { } | |
| 426 | + }; | |
| 427 | + }, | |
| 428 | + getVendedorCobradorById: function() { | |
| 429 | + return { | |
| 430 | + then: function() { } | |
| 431 | + }; | |
| 432 | + }, | |
| 433 | + }; | |
| 434 | + var focaModalService = { | |
| 435 | + modal: function() { } | |
| 436 | + }; | |
| 437 | + $controller('focaAbmVendedorCobradorController', { | |
| 438 | + $scope: scope, | |
| 439 | + focaAbmVendedorCobradorService: focaAbmVendedorCobradorService, | |
| 440 | + $routeParams: {}, | |
| 441 | + focaBotoneraLateralService: {}, | |
| 442 | + $timeout: timeout, | |
| 443 | + $uibModal: {}, | |
| 444 | + $location: {}, | |
| 445 | + focaModalService: focaModalService | |
| 446 | + }); | |
| 447 | + | |
| 448 | + //act | |
| 449 | + spyOn(focaModalService, 'modal').and.returnValue({ then: function() { } }); | |
| 450 | + scope.seleccionarProvincia(13); | |
| 451 | + | |
| 452 | + //assert | |
| 453 | + expect(focaModalService.modal).toHaveBeenCalled(); | |
| 454 | + }); | |
| 455 | + | |
| 456 | + it('función $scope.seleccionarLocalidad llama foca alert si no hay provincia', function() { | |
| 457 | + //arrange | |
| 458 | + var scope= {}; | |
| 459 | + var focaAbmVendedorCobradorService = { | |
| 460 | + getCodigoSiguiente: function() { | |
| 461 | + return { | |
| 462 | + then: function() { } | |
| 463 | + }; | |
| 464 | + }, | |
| 465 | + getVendedorCobradorById: function() { | |
| 466 | + return { | |
| 467 | + then: function() { } | |
| 468 | + }; | |
| 469 | + }, | |
| 470 | + }; | |
| 471 | + var focaModalService = { | |
| 472 | + alert: function() { } | |
| 473 | + }; | |
| 474 | + $controller('focaAbmVendedorCobradorController', { | |
| 475 | + $scope: scope, | |
| 476 | + focaAbmVendedorCobradorService: focaAbmVendedorCobradorService, | |
| 477 | + $routeParams: {}, | |
| 478 | + focaBotoneraLateralService: {}, | |
| 479 | + $timeout: timeout, | |
| 480 | + $uibModal: {}, | |
| 481 | + $location: {}, | |
| 482 | + focaModalService: focaModalService | |
| 483 | + }); | |
| 484 | + | |
| 485 | + //act | |
| 486 | + spyOn(focaModalService, 'alert'); | |
| 487 | + scope.vendedorCobrador.provincia.ID = false; | |
| 488 | + scope.seleccionarLocalidad(); | |
| 489 | + | |
| 490 | + //assert | |
| 491 | + expect(focaModalService.alert).toHaveBeenCalled(); | |
| 492 | + }); | |
| 493 | + | |
| 494 | + it('función $scope.seleccionarLocalidad llama foca modal', function() { | |
| 495 | + //arrange | |
| 496 | + var scope= {}; | |
| 497 | + var focaAbmVendedorCobradorService = { | |
| 498 | + getCodigoSiguiente: function() { | |
| 499 | + return { | |
| 500 | + then: function() { } | |
| 501 | + }; | |
| 502 | + }, | |
| 503 | + getVendedorCobradorById: function() { | |
| 504 | + return { | |
| 505 | + then: function() { } | |
| 506 | + }; | |
| 507 | + }, | |
| 508 | + }; | |
| 509 | + var focaModalService = { | |
| 510 | + modal: function() { } | |
| 511 | + }; | |
| 512 | + $controller('focaAbmVendedorCobradorController', { | |
| 513 | + $scope: scope, | |
| 514 | + focaAbmVendedorCobradorService: focaAbmVendedorCobradorService, | |
| 515 | + $routeParams: {}, | |
| 516 | + focaBotoneraLateralService: {}, | |
| 517 | + $timeout: timeout, | |
| 518 | + $uibModal: {}, | |
| 519 | + $location: {}, | |
| 520 | + focaModalService: focaModalService | |
| 521 | + }); | |
| 522 | + | |
| 523 | + //act | |
| 524 | + spyOn(focaModalService, 'modal').and.returnValue({ then: function() { } }); | |
| 525 | + scope.vendedorCobrador.provincia.ID = true; | |
| 526 | + scope.seleccionarLocalidad(13); | |
| 527 | + | |
| 528 | + //assert | |
| 529 | + expect(focaModalService.modal).toHaveBeenCalled(); | |
| 530 | + }); | |
| 531 | + | |
| 532 | + it('la función scope.cancelar lleva a location correcte', function() { | |
| 533 | + | |
| 534 | + inject(function($location) { | |
| 535 | + //arrange | |
| 536 | + var scope = {}; | |
| 537 | + $controller('focaAbmVendedorCobradorController', { | |
| 538 | + $scope: scope, | |
| 539 | + focaAbmVendedorCobradorService: { | |
| 540 | + getCodigoSiguiente: function() { | |
| 541 | + return { | |
| 542 | + then: function() { } | |
| 543 | + }; | |
| 544 | + }, | |
| 545 | + getVendedorCobradorById: function() { | |
| 546 | + return { | |
| 547 | + then: function() { } | |
| 548 | + }; | |
| 549 | + } | |
| 550 | + }, | |
| 551 | + $routeParams: {}, | |
| 552 | + focaBotoneraLateralService: {}, | |
| 553 | + $timeout: timeout, | |
| 554 | + $uibModal: {}, | |
| 555 | + $location: $location, | |
| 556 | + focaModalService: {} | |
| 557 | + }); | |
| 558 | + | |
| 559 | + //act | |
| 560 | + scope.formVendedorCobrador = { | |
| 561 | + $pristine: true | |
| 562 | + }; | |
| 563 | + scope.cancelar(); | |
| 564 | + | |
| 565 | + //assert | |
| 566 | + expect($location.url()).toEqual('/vendedor-cobrador'); | |
| 567 | + }); | |
| 568 | + }); | |
| 569 | + | |
| 570 | + it('la funcion scope.next suma uno a scope.focused', function() { | |
| 571 | + | |
| 572 | + //arrange | |
| 573 | + var scope = {}; | |
| 574 | + $controller('focaAbmVendedorCobradorController', { | |
| 575 | + $scope: scope, | |
| 576 | + focaAbmVendedorCobradorService: { | |
| 577 | + getCodigoSiguiente: function() { | |
| 578 | + return { | |
| 579 | + then: function() { } | |
| 580 | + }; | |
| 581 | + }, | |
| 582 | + getVendedorCobradorById: function() { | |
| 583 | + return { | |
| 584 | + then: function() { } | |
| 585 | + }; | |
| 586 | + } | |
| 587 | + }, | |
| 588 | + $routeParams: {}, | |
| 589 | + focaBotoneraLateralService: {}, | |
| 590 | + $timeout: timeout, | |
| 591 | + $uibModal: {}, | |
| 592 | + $location: {}, | |
| 593 | + focaModalService: {} | |
| 594 | + }); | |
| 595 | + | |
| 596 | + //act | |
| 597 | + var esperado = scope.focused + 1; | |
| 598 | + scope.next(13); | |
| 599 | + | |
| 600 | + //assert | |
| 601 | + expect(scope.focused).toEqual(esperado); | |
| 602 | + }); | |
| 603 | + | |
| 604 | + it('la funcion scope.cambiarPassword abre modal', function() { | |
| 605 | + | |
| 606 | + //arrange | |
| 607 | + var scope = {}; | |
| 608 | + var uibModal = { | |
| 609 | + open: function() { } | |
| 610 | + }; | |
| 611 | + $controller('focaAbmVendedorCobradorController', { | |
| 612 | + $scope: scope, | |
| 613 | + focaAbmVendedorCobradorService: { | |
| 614 | + getCodigoSiguiente: function() { | |
| 615 | + return { | |
| 616 | + then: function() { } | |
| 617 | + }; | |
| 618 | + }, | |
| 619 | + getVendedorCobradorById: function() { | |
| 620 | + return { | |
| 621 | + then: function() { } | |
| 622 | + }; | |
| 623 | + } | |
| 624 | + }, | |
| 625 | + $routeParams: {}, | |
| 626 | + focaBotoneraLateralService: {}, | |
| 627 | + $timeout: timeout, | |
| 628 | + $uibModal: uibModal, | |
| 629 | + $location: {}, | |
| 630 | + focaModalService: {} | |
| 631 | + }); | |
| 632 | + var responseFake = { | |
| 633 | + result: { | |
| 634 | + then: function() { } | |
| 635 | + } | |
| 636 | + }; | |
| 637 | + | |
| 638 | + //act | |
| 639 | + spyOn(uibModal, 'open').and.returnValue(responseFake); | |
| 640 | + scope.cambiarPassword(); | |
| 641 | + | |
| 642 | + //assert | |
| 643 | + expect(uibModal.open).toHaveBeenCalled(); | |
| 644 | + }); | |
| 645 | + | |
| 646 | + it('la funcion scope.cambiarPassword abre modal y llama a location cuando edicion es ' + | |
| 647 | + 'falso', function(done) | |
| 648 | + { | |
| 649 | + inject(function($location) { | |
| 650 | + | |
| 651 | + //arrange | |
| 652 | + var scope = {}; | |
| 653 | + var uibModal = { | |
| 654 | + open: function() { } | |
| 655 | + }; | |
| 656 | + $controller('focaAbmVendedorCobradorController', { | |
| 657 | + $scope: scope, | |
| 658 | + focaAbmVendedorCobradorService: { | |
| 659 | + getCodigoSiguiente: function() { | |
| 660 | + return { | |
| 661 | + then: function() { } | |
| 662 | + }; | |
| 663 | + }, | |
| 664 | + getVendedorCobradorById: function() { | |
| 665 | + return { | |
| 666 | + then: function() { } | |
| 667 | + }; | |
| 668 | + } | |
| 669 | + }, | |
| 670 | + $routeParams: {}, | |
| 671 | + focaBotoneraLateralService: {}, | |
| 672 | + $timeout: timeout, | |
| 673 | + $uibModal: uibModal, | |
| 674 | + $location: $location, | |
| 675 | + focaModalService: {} | |
| 676 | + }); | |
| 677 | + var responseFake = { | |
| 678 | + result: Promise.resolve(true) | |
| 679 | + }; | |
| 680 | + | |
| 681 | + //act | |
| 682 | + spyOn(uibModal, 'open').and.returnValue(responseFake); | |
| 683 | + scope.edicion = false; | |
| 684 | + scope.cambiarPassword(); | |
| 685 | + | |
| 686 | + //assert | |
| 687 | + responseFake.result.then(function() { | |
| 688 | + expect($location.url()).toEqual('/vendedor-cobrador'); | |
| 689 | + done(); | |
| 690 | + }); | |
| 691 | + }); | |
| 692 | + }); | |
| 693 | + }); | |
| 694 | +}); |
spec/routeSpec.js
| ... | ... | @@ -0,0 +1,27 @@ |
| 1 | +describe('Rutas de abm vendedor cobrador', function() { | |
| 2 | + | |
| 3 | + var route; | |
| 4 | + | |
| 5 | + beforeEach(function() { | |
| 6 | + module('focaAbmVendedorCobrador'); | |
| 7 | + inject(function($route) { | |
| 8 | + route = $route; | |
| 9 | + }); | |
| 10 | + }); | |
| 11 | + | |
| 12 | + it('ruta /vendedor-cobrador lleva a ruta correcta', function() { | |
| 13 | + //assert | |
| 14 | + expect(route.routes['/vendedor-cobrador'].controller) | |
| 15 | + .toBe('focaAbmVendedoresCobradoresController'); | |
| 16 | + expect(route.routes['/vendedor-cobrador'].templateUrl) | |
| 17 | + .toBe('src/views/foca-abm-vendedor-cobrador-listado.html'); | |
| 18 | + }); | |
| 19 | + | |
| 20 | + it('ruta /vendedor-cobrador/:id lleva a ruta correcta', function() { | |
| 21 | + //assert | |
| 22 | + expect(route.routes['/vendedor-cobrador/:id'].controller) | |
| 23 | + .toBe('focaAbmVendedorCobradorController'); | |
| 24 | + expect(route.routes['/vendedor-cobrador/:id'].templateUrl) | |
| 25 | + .toBe('src/views/foca-abm-vendedor-cobrador-item.html'); | |
| 26 | + }); | |
| 27 | +}); |
spec/serviceSpec.js
| ... | ... | @@ -0,0 +1,120 @@ |
| 1 | +describe('Servicios abm vendedor cobrador', function() { | |
| 2 | + | |
| 3 | + var httpBackend; | |
| 4 | + | |
| 5 | + beforeEach(function() { | |
| 6 | + module('focaAbmVendedorCobrador'); | |
| 7 | + | |
| 8 | + inject(module(function($provide) { | |
| 9 | + $provide.value('API_ENDPOINT', { | |
| 10 | + URL: 'local' | |
| 11 | + }); | |
| 12 | + })); | |
| 13 | + | |
| 14 | + inject(function($httpBackend) { | |
| 15 | + httpBackend = $httpBackend; | |
| 16 | + }); | |
| 17 | + }); | |
| 18 | + | |
| 19 | + describe('Servicio focaAbmVendedorCobradorService', function() { | |
| 20 | + | |
| 21 | + var servicio; | |
| 22 | + | |
| 23 | + beforeEach(inject(function(focaAbmVendedorCobradorService) { | |
| 24 | + servicio = focaAbmVendedorCobradorService; | |
| 25 | + })); | |
| 26 | + | |
| 27 | + it('Existe el servicio focaAbmVendedorCobradorService', function() { | |
| 28 | + //assert | |
| 29 | + expect(typeof servicio).toEqual('object'); | |
| 30 | + }); | |
| 31 | + | |
| 32 | + it('la función getVendedoresCobradores llama a la ruta correcta', function() { | |
| 33 | + //arrange | |
| 34 | + var result; | |
| 35 | + var fakeResponse = { data: 'test' }; | |
| 36 | + var fakeBody = 2; | |
| 37 | + httpBackend.expectPOST('local/vendedor-cobrador/list', { nombre: fakeBody }) | |
| 38 | + .respond(fakeResponse); | |
| 39 | + | |
| 40 | + //act | |
| 41 | + servicio.getVendedoresCobradores(fakeBody).then(function(data) { | |
| 42 | + result = data.data; | |
| 43 | + }); | |
| 44 | + httpBackend.flush(); | |
| 45 | + | |
| 46 | + //assert | |
| 47 | + expect(result).toEqual(fakeResponse); | |
| 48 | + }); | |
| 49 | + | |
| 50 | + it('la función getVendedorCobradorById llama a la ruta correcta', function() { | |
| 51 | + //arrange | |
| 52 | + var result; | |
| 53 | + var fakeResponse = { data: 'test' }; | |
| 54 | + var fakeParam = 1; | |
| 55 | + httpBackend.expectGET('local/vendedor-cobrador/' + fakeParam).respond(fakeResponse); | |
| 56 | + | |
| 57 | + //act | |
| 58 | + servicio.getVendedorCobradorById(fakeParam).then(function(data) { | |
| 59 | + result = data.data; | |
| 60 | + }); | |
| 61 | + httpBackend.flush(); | |
| 62 | + | |
| 63 | + //assert | |
| 64 | + expect(result).toEqual(fakeResponse); | |
| 65 | + }); | |
| 66 | + | |
| 67 | + it('la función guardarVendedorCobrador llama a la ruta correcta', function() { | |
| 68 | + //arrange | |
| 69 | + var result; | |
| 70 | + var fakeResponse = { data: 'test' }; | |
| 71 | + var fakeBody = 1; | |
| 72 | + httpBackend.expectPOST('local/vendedor-cobrador', { vendedorCobrador: fakeBody }) | |
| 73 | + .respond(fakeResponse); | |
| 74 | + | |
| 75 | + //act | |
| 76 | + servicio.guardarVendedorCobrador(fakeBody).then(function(data) { | |
| 77 | + result = data.data; | |
| 78 | + }); | |
| 79 | + httpBackend.flush(); | |
| 80 | + | |
| 81 | + //assert | |
| 82 | + expect(result).toEqual(fakeResponse); | |
| 83 | + }); | |
| 84 | + | |
| 85 | + it('la función eliminarVendedorCobrador llama a la ruta correcta', function() { | |
| 86 | + //arrange | |
| 87 | + var result; | |
| 88 | + var fakeResponse = { data: 'test' }; | |
| 89 | + var fakeParam = 1; | |
| 90 | + httpBackend.expectDELETE('local/vendedor-cobrador/' + fakeParam) | |
| 91 | + .respond(fakeResponse); | |
| 92 | + | |
| 93 | + //act | |
| 94 | + servicio.eliminarVendedorCobrador(fakeParam).then(function(data) { | |
| 95 | + result = data.data; | |
| 96 | + }); | |
| 97 | + httpBackend.flush(); | |
| 98 | + | |
| 99 | + //assert | |
| 100 | + expect(result).toEqual(fakeResponse); | |
| 101 | + }); | |
| 102 | + | |
| 103 | + it('la función getCodigoSiguiente llama a la ruta correcta', function() { | |
| 104 | + //arrange | |
| 105 | + var result; | |
| 106 | + var fakeResponse = { data: 'test' }; | |
| 107 | + httpBackend.expectGET('local/vendedor-cobrador/obtener/siguiente-codigo') | |
| 108 | + .respond(fakeResponse); | |
| 109 | + | |
| 110 | + //act | |
| 111 | + servicio.getCodigoSiguiente().then(function(data) { | |
| 112 | + result = data.data; | |
| 113 | + }); | |
| 114 | + httpBackend.flush(); | |
| 115 | + | |
| 116 | + //assert | |
| 117 | + expect(result).toEqual(fakeResponse); | |
| 118 | + }); | |
| 119 | + }); | |
| 120 | +}); |
src/js/app.js
src/js/controller.js
| ... | ... | @@ -96,39 +96,40 @@ angular.module('focaAbmVendedorCobrador') |
| 96 | 96 | |
| 97 | 97 | return paginas; |
| 98 | 98 | } |
| 99 | - | |
| 100 | - function primera() { | |
| 101 | - $scope.selectedClientes = 0; | |
| 102 | - } | |
| 103 | - | |
| 104 | - function anterior() { | |
| 105 | - if ($scope.selectedClientes === 0 && $scope.currentPage > 1) { | |
| 106 | - retrocederPagina(); | |
| 107 | - } else { | |
| 108 | - $scope.selectedClientes--; | |
| 109 | - } | |
| 110 | - } | |
| 111 | - | |
| 112 | - function siguiente() { | |
| 113 | - if ($scope.selectedClientes < $scope.currentPageVendedoresCobradores.length - 1 ) { | |
| 114 | - $scope.selectedClientes++; | |
| 115 | - } else { | |
| 116 | - avanzarPagina(); | |
| 117 | - } | |
| 118 | - } | |
| 119 | - | |
| 120 | - function retrocederPagina() { | |
| 121 | - if ($scope.currentPage > 1) { | |
| 122 | - $scope.selectPage($scope.currentPage - 1); | |
| 123 | - $scope.selectedClientes = $scope.numPerPage - 1; | |
| 124 | - } | |
| 125 | - } | |
| 126 | - | |
| 127 | - function avanzarPagina() { | |
| 128 | - if ($scope.currentPage < $scope.lastPage) { | |
| 129 | - $scope.selectPage($scope.currentPage + 1); | |
| 130 | - $scope.selectedClientes = 0; | |
| 131 | - } | |
| 132 | - } | |
| 99 | + // TODO: descomentar cuando se use | |
| 100 | + // function primera() { | |
| 101 | + // $scope.selectedClientes = 0; | |
| 102 | + // } | |
| 103 | + | |
| 104 | + // function anterior() { | |
| 105 | + // if ($scope.selectedClientes === 0 && $scope.currentPage > 1) { | |
| 106 | + // retrocederPagina(); | |
| 107 | + // } else { | |
| 108 | + // $scope.selectedClientes--; | |
| 109 | + // } | |
| 110 | + // } | |
| 111 | + | |
| 112 | + // function siguiente() { | |
| 113 | + // if ($scope.selectedClientes < $scope.currentPageVendedoresCobradores.length - 1 ) | |
| 114 | + //{ | |
| 115 | + // $scope.selectedClientes++; | |
| 116 | + // } else { | |
| 117 | + // avanzarPagina(); | |
| 118 | + // } | |
| 119 | + // } | |
| 120 | + | |
| 121 | + // function retrocederPagina() { | |
| 122 | + // if ($scope.currentPage > 1) { | |
| 123 | + // $scope.selectPage($scope.currentPage - 1); | |
| 124 | + // $scope.selectedClientes = $scope.numPerPage - 1; | |
| 125 | + // } | |
| 126 | + // } | |
| 127 | + | |
| 128 | + // function avanzarPagina() { | |
| 129 | + // if ($scope.currentPage < $scope.lastPage) { | |
| 130 | + // $scope.selectPage($scope.currentPage + 1); | |
| 131 | + // $scope.selectedClientes = 0; | |
| 132 | + // } | |
| 133 | + // } | |
| 133 | 134 | } |
| 134 | 135 | ]); |
src/js/service.js
| 1 | 1 | angular.module('focaAbmVendedorCobrador') |
| 2 | - .factory('focaAbmVendedorCobradorService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { | |
| 2 | + .factory('focaAbmVendedorCobradorService', ['$http', 'API_ENDPOINT', | |
| 3 | + function($http, API_ENDPOINT) { | |
| 3 | 4 | return { |
| 4 | 5 | getVendedoresCobradores: function(nombre) { |
| 5 | 6 | return $http.post(API_ENDPOINT.URL + '/vendedor-cobrador/list', {nombre: nombre}); |
test.html
| ... | ... | @@ -0,0 +1,22 @@ |
| 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/controllerItem.js"></script> | |
| 16 | + <script type="text/javascript" src="src/js/service.js"></script> | |
| 17 | + <script type="text/javascript" src="src/js/route.js"></script> | |
| 18 | + <script type="text/javascript" src="spec/controllerSpec.js"></script> | |
| 19 | + <script type="text/javascript" src="spec/serviceSpec.js"></script> | |
| 20 | + <script type="text/javascript" src="spec/routeSpec.js"></script> | |
| 21 | + </body> | |
| 22 | +</html> |