Commit c2c7a3fb939c4497a43850eb3aa4436095ce6ef0
Exists in
master
Merge remote-tracking branch 'upstream/master'
Showing
8 changed files
Show diff stats
gulpfile.js
| ... | ... | @@ -9,10 +9,13 @@ const pump = require('pump'); |
| 9 | 9 | const jshint = require('gulp-jshint'); |
| 10 | 10 | const replace = require('gulp-replace'); |
| 11 | 11 | const connect = require('gulp-connect'); |
| 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 | }; |
| ... | ... | @@ -31,7 +34,7 @@ gulp.task('templates', function() { |
| 31 | 34 | ); |
| 32 | 35 | }); |
| 33 | 36 | |
| 34 | -gulp.task('uglify', ['templates'], function() { | |
| 37 | +gulp.task('uglify', ['templates', 'uglify-spec'], function() { | |
| 35 | 38 | return pump( |
| 36 | 39 | [ |
| 37 | 40 | gulp.src([ |
| ... | ... | @@ -40,7 +43,6 @@ gulp.task('uglify', ['templates'], function() { |
| 40 | 43 | ]), |
| 41 | 44 | concat('foca-abm-precios-condiciones.js'), |
| 42 | 45 | replace('src/views/', ''), |
| 43 | - replace("['ngRoute', 'ui.bootstrap', 'focaModal']", '[]'), | |
| 44 | 46 | gulp.dest(paths.tmp), |
| 45 | 47 | rename('foca-abm-precios-condiciones.min.js'), |
| 46 | 48 | uglify(), |
| ... | ... | @@ -49,15 +51,26 @@ gulp.task('uglify', ['templates'], function() { |
| 49 | 51 | ); |
| 50 | 52 | }); |
| 51 | 53 | |
| 54 | +gulp.task('uglify-spec', function() { | |
| 55 | + return pump([ | |
| 56 | + gulp.src(paths.specs), | |
| 57 | + concat('foca-abm-precios-condiciones.spec.js'), | |
| 58 | + replace("src/views/", ''), | |
| 59 | + header("describe('Módulo foca-abm-precios-condiciones', function() { \n"), | |
| 60 | + footer("});"), | |
| 61 | + gulp.dest(paths.dist) | |
| 62 | + ]); | |
| 63 | +}); | |
| 64 | + | |
| 52 | 65 | gulp.task('clean', function() { |
| 53 | 66 | return gulp.src(['tmp', 'dist'], {read: false}) |
| 54 | 67 | .pipe(clean()); |
| 55 | 68 | }); |
| 56 | 69 | |
| 57 | 70 | gulp.task('pre-commit', function() { |
| 58 | - pump( | |
| 71 | + return pump( | |
| 59 | 72 | [ |
| 60 | - gulp.src(paths.srcJS), | |
| 73 | + gulp.src([paths.srcJS, paths.specs]), | |
| 61 | 74 | jshint('.jshintrc'), |
| 62 | 75 | jshint.reporter('default'), |
| 63 | 76 | jshint.reporter('fail') |
| ... | ... | @@ -67,7 +80,7 @@ gulp.task('pre-commit', function() { |
| 67 | 80 | |
| 68 | 81 | gulp.task('clean-post-install', function() { |
| 69 | 82 | return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', |
| 70 | - 'index.html'], {read: false}) | |
| 83 | + 'index.html', 'spec', 'test.html'], {read: false}) | |
| 71 | 84 | .pipe(clean()); |
| 72 | 85 | }); |
| 73 | 86 |
index.html
| ... | ... | @@ -1,32 +0,0 @@ |
| 1 | -<html ng-app="focaAbmPreciosCondiciones"> | |
| 2 | - | |
| 3 | -<head> | |
| 4 | - <meta charset="UTF-8" /> | |
| 5 | - <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
| 6 | - | |
| 7 | - <!--CSS--> | |
| 8 | - <link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" /> | |
| 9 | - <link href="node_modules/font-awesome/css/font-awesome.min.css" rel="stylesheet" /> | |
| 10 | - | |
| 11 | - <!--VENDOR JS--> | |
| 12 | - <script src="node_modules/jquery/dist/jquery.min.js"></script> | |
| 13 | - <script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script> | |
| 14 | - <script src="node_modules/angular/angular.min.js"></script> | |
| 15 | - <script src="node_modules/angular-route/angular-route.min.js"></script> | |
| 16 | - <script src="node_modules/ui-bootstrap4/dist/ui-bootstrap-tpls.js"></script> | |
| 17 | - <script src="node_modules/foca-modal/dist/foca-modal.min.js"></script> | |
| 18 | - | |
| 19 | - <!-- BUILD --> | |
| 20 | - <script src="src/js/app.js"></script> | |
| 21 | - <script src="src/js/route.js"></script> | |
| 22 | - <script src="src/js/controller.js"></script> | |
| 23 | - <script src="src/js/service.js"></script> | |
| 24 | - <script src="src/etc/develop.js"></script> | |
| 25 | - <!-- /BUILD --> | |
| 26 | - | |
| 27 | -<body> | |
| 28 | - <div ng-view> | |
| 29 | - </div> | |
| 30 | -</body> | |
| 31 | - | |
| 32 | -</html> |
package.json
| ... | ... | @@ -4,11 +4,11 @@ |
| 4 | 4 | "description": "ABM de precios y condiciones", |
| 5 | 5 | "main": "dist/foca-abm-precios-condiciones.js", |
| 6 | 6 | "scripts": { |
| 7 | - "test": "echo \"Error: no test specified\" && exit 1", | |
| 7 | + "test": "test.html", | |
| 8 | 8 | "compile": "gulp uglify", |
| 9 | 9 | "gulp-pre-commit": "gulp pre-commit", |
| 10 | 10 | "postinstall": "npm run compile && gulp clean-post-install", |
| 11 | - "install-dev": "npm install -D jasmine-core pre-commit angular angular-route bootstrap ui-bootstrap4 font-awesome gulp gulp-angular-templatecache gulp-connect gulp-clean gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-sequence gulp-uglify-es gulp-uglify gulp-replace jquery jshint pump git+http://git.focasoftware.com/npm/foca-modal.git" | |
| 11 | + "install-dev": "npm install -D jasmine-core pre-commit angular angular-route bootstrap ui-bootstrap4 font-awesome gulp gulp-angular-templatecache gulp-connect gulp-clean gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-sequence gulp-uglify-es gulp-uglify gulp-replace jquery jshint pump angular-mocks git+http://git.focasoftware.com/npm/foca-modal.git" | |
| 12 | 12 | }, |
| 13 | 13 | "pre-commit": [ |
| 14 | 14 | "gulp-pre-commit" |
| ... | ... | @@ -34,15 +34,16 @@ |
| 34 | 34 | "pump": "^3.0.x" |
| 35 | 35 | }, |
| 36 | 36 | "devDependencies": { |
| 37 | - "angular": "^1.7.4", | |
| 38 | - "angular-route": "^1.7.5", | |
| 39 | - "bootstrap": "^4.1.3", | |
| 37 | + "angular": "^1.7.7", | |
| 38 | + "angular-mocks": "^1.7.7", | |
| 39 | + "angular-route": "^1.7.7", | |
| 40 | + "bootstrap": "^4.2.1", | |
| 40 | 41 | "foca-modal": "git+http://git.focasoftware.com/npm/foca-modal.git", |
| 41 | 42 | "font-awesome": "^4.7.0", |
| 42 | 43 | "gulp": "^3.9.1", |
| 43 | - "gulp-angular-templatecache": "^2.2.1", | |
| 44 | + "gulp-angular-templatecache": "^2.2.6", | |
| 44 | 45 | "gulp-clean": "^0.4.0", |
| 45 | - "gulp-connect": "^5.6.1", | |
| 46 | + "gulp-connect": "^5.7.0", | |
| 46 | 47 | "gulp-htmlmin": "^5.0.1", |
| 47 | 48 | "gulp-jshint": "^2.1.0", |
| 48 | 49 | "gulp-rename": "^1.4.0", |
| ... | ... | @@ -50,11 +51,11 @@ |
| 50 | 51 | "gulp-sequence": "^1.0.0", |
| 51 | 52 | "gulp-uglify": "^3.0.1", |
| 52 | 53 | "gulp-uglify-es": "^1.0.4", |
| 53 | - "jasmine-core": "^3.2.1", | |
| 54 | + "jasmine-core": "^3.3.0", | |
| 54 | 55 | "jquery": "^3.3.1", |
| 55 | - "jshint": "^2.9.6", | |
| 56 | + "jshint": "^2.10.1", | |
| 56 | 57 | "pre-commit": "^1.2.2", |
| 57 | 58 | "pump": "^3.0.0", |
| 58 | - "ui-bootstrap4": "^3.0.5" | |
| 59 | + "ui-bootstrap4": "^3.0.6" | |
| 59 | 60 | } |
| 60 | 61 | } |
spec/controllerSpec.js
| ... | ... | @@ -0,0 +1,412 @@ |
| 1 | +describe('Controladores abm precios condiciones', function() { | |
| 2 | + | |
| 3 | + var $controller; | |
| 4 | + var timeout; | |
| 5 | + | |
| 6 | + beforeEach(function() { | |
| 7 | + module('focaAbmPreciosCondiciones'); | |
| 8 | + inject(function(_$controller_) { | |
| 9 | + $controller = _$controller_; | |
| 10 | + }); | |
| 11 | + }); | |
| 12 | + | |
| 13 | + beforeEach(function() { | |
| 14 | + inject(function($timeout) { | |
| 15 | + timeout = $timeout; | |
| 16 | + }); | |
| 17 | + }); | |
| 18 | + | |
| 19 | + describe('Controlador focaAbmPreciosCondiciones', function() { | |
| 20 | + | |
| 21 | + it('Existe el controlador', function() { | |
| 22 | + //act | |
| 23 | + var controlador = $controller('focaAbmPreciosCondicionesController', { | |
| 24 | + $scope: {}, | |
| 25 | + focaAbmPreciosCondicionesService: {}, | |
| 26 | + $location: {}, | |
| 27 | + focaModalService: {}, | |
| 28 | + focaBotoneraLateralService: {}, | |
| 29 | + $timeout: timeout | |
| 30 | + }); | |
| 31 | + | |
| 32 | + //assert | |
| 33 | + expect(typeof controlador).toEqual('object'); | |
| 34 | + }); | |
| 35 | + | |
| 36 | + it('$scope.editar lleva a la ruta correcta', function() { | |
| 37 | + inject(function($location) { | |
| 38 | + //arrange | |
| 39 | + var scope = {}; | |
| 40 | + var paramFake = 1; | |
| 41 | + $controller('focaAbmPreciosCondicionesController', { | |
| 42 | + $scope: scope, | |
| 43 | + focaAbmPreciosCondicionesService: {}, | |
| 44 | + $location: $location, | |
| 45 | + focaModalService: {}, | |
| 46 | + focaBotoneraLateralService: {}, | |
| 47 | + $timeout: timeout | |
| 48 | + }); | |
| 49 | + | |
| 50 | + | |
| 51 | + //act | |
| 52 | + scope.editar(paramFake); | |
| 53 | + | |
| 54 | + //assert | |
| 55 | + expect($location.url()).toEqual('/precio-condicion/' + paramFake); | |
| 56 | + }); | |
| 57 | + }); | |
| 58 | + | |
| 59 | + it('$scope.solicitarConfirmacion levanta modal confirm', function() { | |
| 60 | + //arrange | |
| 61 | + var scope = {}; | |
| 62 | + var paramFake = 1; | |
| 63 | + var focaModalService = { | |
| 64 | + confirm: function() { } | |
| 65 | + }; | |
| 66 | + $controller('focaAbmPreciosCondicionesController', { | |
| 67 | + $scope: scope, | |
| 68 | + focaAbmPreciosCondicionesService: {}, | |
| 69 | + $location: {}, | |
| 70 | + focaModalService: focaModalService, | |
| 71 | + focaBotoneraLateralService: {}, | |
| 72 | + $timeout: timeout | |
| 73 | + }); | |
| 74 | + | |
| 75 | + //act | |
| 76 | + spyOn(focaModalService, 'confirm').and.returnValue({ then: function() { }}); | |
| 77 | + scope.solicitarConfirmacion(paramFake); | |
| 78 | + | |
| 79 | + //assert | |
| 80 | + expect(focaModalService.confirm).toHaveBeenCalled(); | |
| 81 | + }); | |
| 82 | + | |
| 83 | + it('$scope.solicitarConfirmacion elimina al confirmar ok', function(done) { | |
| 84 | + //arrange | |
| 85 | + var scope = {}; | |
| 86 | + var paramFake = 1; | |
| 87 | + var focaModalService = { | |
| 88 | + confirm: function() { } | |
| 89 | + }; | |
| 90 | + var focaAbmPreciosCondicionesService = { | |
| 91 | + borrarPrecioCondicion: function() { } | |
| 92 | + }; | |
| 93 | + $controller('focaAbmPreciosCondicionesController', { | |
| 94 | + $scope: scope, | |
| 95 | + focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, | |
| 96 | + $location: {}, | |
| 97 | + focaModalService: focaModalService, | |
| 98 | + focaBotoneraLateralService: {}, | |
| 99 | + $timeout: timeout | |
| 100 | + }); | |
| 101 | + var promesaConfirm = Promise.resolve(true); | |
| 102 | + scope.preciosCondiciones = []; | |
| 103 | + | |
| 104 | + //act | |
| 105 | + spyOn(focaModalService, 'confirm').and.returnValue(promesaConfirm); | |
| 106 | + spyOn(focaAbmPreciosCondicionesService, 'borrarPrecioCondicion'); | |
| 107 | + scope.solicitarConfirmacion(paramFake); | |
| 108 | + | |
| 109 | + //assert | |
| 110 | + promesaConfirm.then(function() { | |
| 111 | + expect(focaAbmPreciosCondicionesService.borrarPrecioCondicion).toHaveBeenCalled(); | |
| 112 | + done(); | |
| 113 | + }); | |
| 114 | + }); | |
| 115 | + | |
| 116 | + it('$scope.buscar llama a obtenerPreciosCondiciones', function() { | |
| 117 | + //arrange | |
| 118 | + var scope = {}; | |
| 119 | + var focaAbmPreciosCondicionesService = { | |
| 120 | + obtenerPreciosCondiciones: function() { } | |
| 121 | + }; | |
| 122 | + $controller('focaAbmPreciosCondicionesController', { | |
| 123 | + $scope: scope, | |
| 124 | + focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, | |
| 125 | + $location: {}, | |
| 126 | + focaModalService: {}, | |
| 127 | + focaBotoneraLateralService: {}, | |
| 128 | + $timeout: timeout | |
| 129 | + }); | |
| 130 | + | |
| 131 | + //act | |
| 132 | + spyOn(focaAbmPreciosCondicionesService, 'obtenerPreciosCondiciones') | |
| 133 | + .and.returnValue({ then: function() { }}); | |
| 134 | + scope.buscar(13); | |
| 135 | + | |
| 136 | + //assert | |
| 137 | + expect(focaAbmPreciosCondicionesService.obtenerPreciosCondiciones).toHaveBeenCalled(); | |
| 138 | + }); | |
| 139 | + }); | |
| 140 | + | |
| 141 | + describe('Controlador focaAbmPrecioCondicionController', function() { | |
| 142 | + | |
| 143 | + it('Existe el controlador focaAbmPrecioCondicionController', function() { | |
| 144 | + //act | |
| 145 | + var controlador = $controller('focaAbmPrecioCondicionController', { | |
| 146 | + $scope: {}, | |
| 147 | + focaAbmPreciosCondicionesService: { | |
| 148 | + obtenerPrecioCondicion: function() { | |
| 149 | + return { | |
| 150 | + then: function() { } | |
| 151 | + }; | |
| 152 | + } | |
| 153 | + }, | |
| 154 | + focaBotoneraLateralService: {}, | |
| 155 | + $routeParams: {}, | |
| 156 | + $location: {}, | |
| 157 | + focaModalService: {}, | |
| 158 | + $timeout: timeout, | |
| 159 | + $uibModal: {}, | |
| 160 | + $window: {} | |
| 161 | + }); | |
| 162 | + | |
| 163 | + //assert | |
| 164 | + expect(typeof controlador).toEqual('object'); | |
| 165 | + }); | |
| 166 | + | |
| 167 | + it('La funcion $scope.cancelar lleva a la ruta correcta', function() { | |
| 168 | + inject(function($location) { | |
| 169 | + //arrange | |
| 170 | + var scope = {}; | |
| 171 | + $controller('focaAbmPrecioCondicionController', { | |
| 172 | + $scope: scope, | |
| 173 | + focaAbmPreciosCondicionesService: { | |
| 174 | + obtenerPrecioCondicion: function() { | |
| 175 | + return { | |
| 176 | + then: function() { } | |
| 177 | + }; | |
| 178 | + } | |
| 179 | + }, | |
| 180 | + focaBotoneraLateralService: {}, | |
| 181 | + $routeParams: {}, | |
| 182 | + $location: $location, | |
| 183 | + focaModalService: {}, | |
| 184 | + $timeout: timeout, | |
| 185 | + $uibModal: {}, | |
| 186 | + $window: {} | |
| 187 | + }); | |
| 188 | + | |
| 189 | + //act | |
| 190 | + scope.cancelar(); | |
| 191 | + | |
| 192 | + //assert | |
| 193 | + expect($location.url()).toEqual('/precio-condicion'); | |
| 194 | + }); | |
| 195 | + }); | |
| 196 | + | |
| 197 | + it('La funcion $scope.guardar llama a servicio.guardarPrecioCondicion', function() { | |
| 198 | + inject(function($location) { | |
| 199 | + //arrange | |
| 200 | + var scope = {}; | |
| 201 | + var focaAbmPreciosCondicionesService = { | |
| 202 | + obtenerPrecioCondicion: function() { | |
| 203 | + return { | |
| 204 | + then: function() { } | |
| 205 | + }; | |
| 206 | + }, | |
| 207 | + guardarPrecioCondicion: function() { } | |
| 208 | + }; | |
| 209 | + var window = { | |
| 210 | + location: { | |
| 211 | + assign: function() { } | |
| 212 | + } | |
| 213 | + }; | |
| 214 | + $controller('focaAbmPrecioCondicionController', { | |
| 215 | + $scope: scope, | |
| 216 | + focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, | |
| 217 | + focaBotoneraLateralService: {}, | |
| 218 | + $routeParams: {}, | |
| 219 | + $location: $location, | |
| 220 | + focaModalService: {}, | |
| 221 | + $timeout: timeout, | |
| 222 | + $uibModal: {}, | |
| 223 | + $window: window | |
| 224 | + }); | |
| 225 | + var promesaGuardarPrecioCondicion = Promise.resolve(true); | |
| 226 | + scope.precioCondicion = { listaPrecio: {} }; | |
| 227 | + | |
| 228 | + //act | |
| 229 | + //spyOn(window, 'location').and.returnValue({ assign: function() {} }); | |
| 230 | + spyOn(focaAbmPreciosCondicionesService, 'guardarPrecioCondicion') | |
| 231 | + .and.returnValue(promesaGuardarPrecioCondicion); | |
| 232 | + scope.guardar(); | |
| 233 | + | |
| 234 | + //assert | |
| 235 | + expect(focaAbmPreciosCondicionesService.guardarPrecioCondicion).toHaveBeenCalled(); | |
| 236 | + }); | |
| 237 | + }); | |
| 238 | + | |
| 239 | + it('La funcion $scope.solicitarConfirmacionPlazoPago levanta modal confirm', function() { | |
| 240 | + //act | |
| 241 | + var scope = {}; | |
| 242 | + var focaModalService = { | |
| 243 | + confirm: function() { } | |
| 244 | + }; | |
| 245 | + $controller('focaAbmPrecioCondicionController', { | |
| 246 | + $scope: scope, | |
| 247 | + focaAbmPreciosCondicionesService: { | |
| 248 | + obtenerPrecioCondicion: function() { | |
| 249 | + return { | |
| 250 | + then:function() { } | |
| 251 | + }; | |
| 252 | + } | |
| 253 | + }, | |
| 254 | + focaBotoneraLateralService: {}, | |
| 255 | + $routeParams: {}, | |
| 256 | + $location: {}, | |
| 257 | + focaModalService: focaModalService, | |
| 258 | + $timeout: timeout, | |
| 259 | + $uibModal: {}, | |
| 260 | + $window: {} | |
| 261 | + }); | |
| 262 | + | |
| 263 | + //act | |
| 264 | + spyOn(focaModalService, 'confirm') | |
| 265 | + .and.returnValue({ then: function() {} }); | |
| 266 | + scope.solicitarConfirmacionPlazoPago({ data: 'test' }); | |
| 267 | + | |
| 268 | + //assert | |
| 269 | + expect(focaModalService.confirm).toHaveBeenCalled(); | |
| 270 | + }); | |
| 271 | + | |
| 272 | + it('La funcion $scope.solicitarConfirmacionPlazoPago borra al dar ok', function(done) { | |
| 273 | + //act | |
| 274 | + var scope = {}; | |
| 275 | + var focaModalService = { | |
| 276 | + confirm: function() { } | |
| 277 | + }; | |
| 278 | + var focaAbmPreciosCondicionesService = { | |
| 279 | + obtenerPrecioCondicion: function() { | |
| 280 | + return { | |
| 281 | + then:function() { } | |
| 282 | + }; | |
| 283 | + }, | |
| 284 | + borrarPlazoPago: function() { } | |
| 285 | + }; | |
| 286 | + $controller('focaAbmPrecioCondicionController', { | |
| 287 | + $scope: scope, | |
| 288 | + focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, | |
| 289 | + focaBotoneraLateralService: {}, | |
| 290 | + $routeParams: {}, | |
| 291 | + $location: {}, | |
| 292 | + focaModalService: focaModalService, | |
| 293 | + $timeout: timeout, | |
| 294 | + $uibModal: {}, | |
| 295 | + $window: {} | |
| 296 | + }); | |
| 297 | + var promesaConfirm = Promise.resolve(true); | |
| 298 | + scope.precioCondicion = { | |
| 299 | + plazos: [] | |
| 300 | + }; | |
| 301 | + | |
| 302 | + //act | |
| 303 | + spyOn(focaModalService, 'confirm').and.returnValue(promesaConfirm); | |
| 304 | + spyOn(focaAbmPreciosCondicionesService, 'borrarPlazoPago'); | |
| 305 | + scope.solicitarConfirmacionPlazoPago({ data: 'test' }); | |
| 306 | + | |
| 307 | + //assert | |
| 308 | + promesaConfirm.then(function() { | |
| 309 | + expect(focaAbmPreciosCondicionesService.borrarPlazoPago).toHaveBeenCalled(); | |
| 310 | + done(); | |
| 311 | + }); | |
| 312 | + }); | |
| 313 | + | |
| 314 | + it('La funcion $scope.seleccionarListaPrecio levanta modal', function() { | |
| 315 | + //arrange | |
| 316 | + var scope = {}; | |
| 317 | + var uibModal = { | |
| 318 | + open: function() { } | |
| 319 | + }; | |
| 320 | + var focaAbmPreciosCondicionesService = { | |
| 321 | + obtenerPrecioCondicion: function() { | |
| 322 | + return { | |
| 323 | + then:function() { } | |
| 324 | + }; | |
| 325 | + } | |
| 326 | + }; | |
| 327 | + $controller('focaAbmPrecioCondicionController', { | |
| 328 | + $scope: scope, | |
| 329 | + focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, | |
| 330 | + focaBotoneraLateralService: {}, | |
| 331 | + $routeParams: {}, | |
| 332 | + $location: {}, | |
| 333 | + focaModalService: {}, | |
| 334 | + $timeout: timeout, | |
| 335 | + $uibModal: uibModal, | |
| 336 | + $window: {} | |
| 337 | + }); | |
| 338 | + | |
| 339 | + //act | |
| 340 | + spyOn(uibModal, 'open').and.returnValue({ result: { then: function() { } } }); | |
| 341 | + scope.seleccionarListaPrecio(13); | |
| 342 | + | |
| 343 | + //assert | |
| 344 | + expect(uibModal.open).toHaveBeenCalled(); | |
| 345 | + }); | |
| 346 | + | |
| 347 | + it('La funcion $scope.verProductosListaPrecio levanta modal', function() { | |
| 348 | + //arrange | |
| 349 | + var scope = {}; | |
| 350 | + var uibModal = { | |
| 351 | + open: function() { } | |
| 352 | + }; | |
| 353 | + var focaAbmPreciosCondicionesService = { | |
| 354 | + obtenerPrecioCondicion: function() { | |
| 355 | + return { | |
| 356 | + then:function() { } | |
| 357 | + }; | |
| 358 | + } | |
| 359 | + }; | |
| 360 | + $controller('focaAbmPrecioCondicionController', { | |
| 361 | + $scope: scope, | |
| 362 | + focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, | |
| 363 | + focaBotoneraLateralService: {}, | |
| 364 | + $routeParams: {}, | |
| 365 | + $location: {}, | |
| 366 | + focaModalService: {}, | |
| 367 | + $timeout: timeout, | |
| 368 | + $uibModal: uibModal, | |
| 369 | + $window: {} | |
| 370 | + }); | |
| 371 | + scope.precioCondicion = { | |
| 372 | + listaPrecio: {} | |
| 373 | + }; | |
| 374 | + //act | |
| 375 | + spyOn(uibModal, 'open'); | |
| 376 | + scope.verProductosListaPrecio(); | |
| 377 | + | |
| 378 | + //assert | |
| 379 | + expect(uibModal.open).toHaveBeenCalled(); | |
| 380 | + }); | |
| 381 | + | |
| 382 | + it('la función next suma uno a $scope.focused', function() { | |
| 383 | + //arrange | |
| 384 | + var scope = {}; | |
| 385 | + var focaAbmPreciosCondicionesService = { | |
| 386 | + obtenerPrecioCondicion: function() { | |
| 387 | + return { | |
| 388 | + then:function() { } | |
| 389 | + }; | |
| 390 | + } | |
| 391 | + }; | |
| 392 | + $controller('focaAbmPrecioCondicionController', { | |
| 393 | + $scope: scope, | |
| 394 | + focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService, | |
| 395 | + focaBotoneraLateralService: {}, | |
| 396 | + $routeParams: {}, | |
| 397 | + $location: {}, | |
| 398 | + focaModalService: {}, | |
| 399 | + $timeout: timeout, | |
| 400 | + $uibModal: {}, | |
| 401 | + $window: {} | |
| 402 | + }); | |
| 403 | + | |
| 404 | + //act | |
| 405 | + var esperado = scope.focused + 1; | |
| 406 | + scope.next(13); | |
| 407 | + | |
| 408 | + //assert | |
| 409 | + expect(scope.focused).toEqual(esperado); | |
| 410 | + }); | |
| 411 | + }); | |
| 412 | +}); |
spec/routeSpec.js
| ... | ... | @@ -0,0 +1,27 @@ |
| 1 | +describe('Rutas de abm precios condiciones', function() { | |
| 2 | + | |
| 3 | + var route; | |
| 4 | + | |
| 5 | + beforeEach(function() { | |
| 6 | + module('focaAbmPreciosCondiciones'); | |
| 7 | + inject(function($route) { | |
| 8 | + route = $route; | |
| 9 | + }); | |
| 10 | + }); | |
| 11 | + | |
| 12 | + it('Ruta /precio-condicion dirije correctamente', function() { | |
| 13 | + //assert | |
| 14 | + expect(route.routes['/precio-condicion'].controller) | |
| 15 | + .toBe('focaAbmPreciosCondicionesController'); | |
| 16 | + expect(route.routes['/precio-condicion'].templateUrl) | |
| 17 | + .toBe('src/views/foca-abm-precios-condiciones-listado.html'); | |
| 18 | + }); | |
| 19 | + | |
| 20 | + it('Ruta /precio-condicion/:id dirije correctamente', function() { | |
| 21 | + //assert | |
| 22 | + expect(route.routes['/precio-condicion/:id'].controller) | |
| 23 | + .toBe('focaAbmPrecioCondicionController'); | |
| 24 | + expect(route.routes['/precio-condicion/:id'].templateUrl) | |
| 25 | + .toBe('src/views/foca-abm-precios-condiciones-item.html'); | |
| 26 | + }); | |
| 27 | +}); |
spec/serviceSpec.js
| ... | ... | @@ -0,0 +1,157 @@ |
| 1 | +describe('Servicios abm precios condiciones', function() { | |
| 2 | + | |
| 3 | + var httpBackend; | |
| 4 | + | |
| 5 | + beforeEach(function() { | |
| 6 | + module('focaAbmPreciosCondiciones'); | |
| 7 | + | |
| 8 | + inject(module(function($provide) { | |
| 9 | + $provide.value('API_ENDPOINT', { | |
| 10 | + URL: 'localhost' | |
| 11 | + }); | |
| 12 | + })); | |
| 13 | + }); | |
| 14 | + | |
| 15 | + describe('servicio focaAbmPreciosCondicionesService', function() { | |
| 16 | + | |
| 17 | + var servicio; | |
| 18 | + | |
| 19 | + beforeEach(function() { | |
| 20 | + inject(function(focaAbmPreciosCondicionesService, $httpBackend) { | |
| 21 | + servicio = focaAbmPreciosCondicionesService; | |
| 22 | + httpBackend = $httpBackend; | |
| 23 | + }); | |
| 24 | + }); | |
| 25 | + | |
| 26 | + it('existe el servicio focaAbmPreciosCondicionesService', function() { | |
| 27 | + //assert | |
| 28 | + expect(typeof servicio).toEqual('object'); | |
| 29 | + }); | |
| 30 | + | |
| 31 | + it('la función obtenerPreciosCondiciones llama ruta correcta', function() { | |
| 32 | + //arrange | |
| 33 | + var responseFake = { data: 'test'}; | |
| 34 | + var result; | |
| 35 | + var bodyFake = 1; | |
| 36 | + httpBackend.expectPOST('localhost/precios-condiciones', { nombre: bodyFake }) | |
| 37 | + .respond(responseFake); | |
| 38 | + | |
| 39 | + //act | |
| 40 | + servicio.obtenerPreciosCondiciones(bodyFake).then(function(data) { | |
| 41 | + result = data.data; | |
| 42 | + }); | |
| 43 | + httpBackend.flush(); | |
| 44 | + | |
| 45 | + //assert | |
| 46 | + expect(result).toEqual(responseFake); | |
| 47 | + }); | |
| 48 | + | |
| 49 | + it('la función obtenerPrecioCondicion llama ruta correcta', function() { | |
| 50 | + //arrange | |
| 51 | + var responseFake = { data: 'test'}; | |
| 52 | + var result; | |
| 53 | + var paramFake = 1; | |
| 54 | + httpBackend.expectGET('localhost/precio-condicion/' + paramFake) | |
| 55 | + .respond(responseFake); | |
| 56 | + | |
| 57 | + //act | |
| 58 | + servicio.obtenerPrecioCondicion(paramFake).then(function(data) { | |
| 59 | + result = data.data; | |
| 60 | + }); | |
| 61 | + httpBackend.flush(); | |
| 62 | + | |
| 63 | + //assert | |
| 64 | + expect(result).toEqual(responseFake); | |
| 65 | + }); | |
| 66 | + | |
| 67 | + it('la función guardarPrecioCondicion llama ruta correcta', function() { | |
| 68 | + //arrange | |
| 69 | + var responseFake = { data: 'test'}; | |
| 70 | + var result; | |
| 71 | + var bodyFake = 1; | |
| 72 | + httpBackend.expectPOST('localhost/precio-condicion', { precioCondicion: bodyFake }) | |
| 73 | + .respond(responseFake); | |
| 74 | + | |
| 75 | + //act | |
| 76 | + servicio.guardarPrecioCondicion(bodyFake).then(function(data) { | |
| 77 | + result = data.data; | |
| 78 | + }); | |
| 79 | + httpBackend.flush(); | |
| 80 | + | |
| 81 | + //assert | |
| 82 | + expect(result).toEqual(responseFake); | |
| 83 | + }); | |
| 84 | + | |
| 85 | + it('la función borrarPrecioCondicion llama ruta correcta', function() { | |
| 86 | + //arrange | |
| 87 | + var responseFake = { data: 'test'}; | |
| 88 | + var result; | |
| 89 | + var paramFake = 1; | |
| 90 | + httpBackend.expectDELETE('localhost/precio-condicion/' + paramFake) | |
| 91 | + .respond(responseFake); | |
| 92 | + | |
| 93 | + //act | |
| 94 | + servicio.borrarPrecioCondicion(paramFake).then(function(data) { | |
| 95 | + result = data.data; | |
| 96 | + }); | |
| 97 | + httpBackend.flush(); | |
| 98 | + | |
| 99 | + //assert | |
| 100 | + expect(result).toEqual(responseFake); | |
| 101 | + }); | |
| 102 | + | |
| 103 | + it('la función obtenerPlazoPago llama ruta correcta', function() { | |
| 104 | + //arrange | |
| 105 | + var responseFake = { data: 'test'}; | |
| 106 | + var result; | |
| 107 | + var paramFake = 1; | |
| 108 | + httpBackend.expectGET('localhost/plazo-pago/precio-condicion/' + paramFake) | |
| 109 | + .respond(responseFake); | |
| 110 | + | |
| 111 | + //act | |
| 112 | + servicio.obtenerPlazoPago(paramFake).then(function(data) { | |
| 113 | + result = data.data; | |
| 114 | + }); | |
| 115 | + httpBackend.flush(); | |
| 116 | + | |
| 117 | + //assert | |
| 118 | + expect(result).toEqual(responseFake); | |
| 119 | + }); | |
| 120 | + | |
| 121 | + it('la función borrarPlazoPago llama ruta correcta', function() { | |
| 122 | + //arrange | |
| 123 | + var responseFake = { data: 'test'}; | |
| 124 | + var result; | |
| 125 | + var paramFake = 1; | |
| 126 | + httpBackend.expectDELETE('localhost/plazo-pago/' + paramFake) | |
| 127 | + .respond(responseFake); | |
| 128 | + | |
| 129 | + //act | |
| 130 | + servicio.borrarPlazoPago(paramFake).then(function(data) { | |
| 131 | + result = data.data; | |
| 132 | + }); | |
| 133 | + httpBackend.flush(); | |
| 134 | + | |
| 135 | + //assert | |
| 136 | + expect(result).toEqual(responseFake); | |
| 137 | + }); | |
| 138 | + | |
| 139 | + it('la función guardarPlazosPago llama ruta correcta', function() { | |
| 140 | + //arrange | |
| 141 | + var responseFake = { data: 'test'}; | |
| 142 | + var result; | |
| 143 | + var bodyFake = 1; | |
| 144 | + httpBackend.expectPOST('localhost/plazos-pago', { plazosPago: bodyFake}) | |
| 145 | + .respond(responseFake); | |
| 146 | + | |
| 147 | + //act | |
| 148 | + servicio.guardarPlazosPago(bodyFake).then(function(data) { | |
| 149 | + result = data.data; | |
| 150 | + }); | |
| 151 | + httpBackend.flush(); | |
| 152 | + | |
| 153 | + //assert | |
| 154 | + expect(result).toEqual(responseFake); | |
| 155 | + }); | |
| 156 | + }); | |
| 157 | +}); |
src/js/app.js
test.html
| ... | ... | @@ -0,0 +1,21 @@ |
| 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> |