Commit 43df6ec56c7d2da31127b050810e8855d76dc239
Exists in
master
Merge branch 'master' into 'master'
Master(efernandez) See merge request !18
Showing
9 changed files
Show diff stats
gulpfile.js
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: 'focaAbmVendedorCobrador', | 30 | module: 'focaAbmVendedorCobrador', |
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', 'uglify-spec'], 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-vendedor-cobrador.js'), | 45 | concat('foca-abm-vendedor-cobrador.js'), |
43 | replace("src/views/", ''), | 46 | replace("src/views/", ''), |
44 | gulp.dest(paths.tmp), | 47 | gulp.dest(paths.tmp), |
45 | rename('foca-abm-vendedor-cobrador.min.js'), | 48 | rename('foca-abm-vendedor-cobrador.min.js'), |
46 | uglify(), | 49 | uglify(), |
47 | gulp.dest(paths.dist) | 50 | gulp.dest(paths.dist) |
48 | ] | 51 | ] |
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 | gulp.task('clean', function() { | 66 | gulp.task('clean', function() { |
53 | return gulp.src(['tmp', 'dist'], {read: false}) | 67 | return gulp.src(['tmp', 'dist'], {read: false}) |
54 | .pipe(clean()); | 68 | .pipe(clean()); |
55 | }); | 69 | }); |
56 | 70 | ||
57 | gulp.task('pre-commit', function() { | 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 | jshint('.jshintrc'), | 75 | jshint('.jshintrc'), |
62 | jshint.reporter('default'), | 76 | jshint.reporter('default'), |
63 | jshint.reporter('fail') | 77 | jshint.reporter('fail') |
64 | ] | 78 | ] |
65 | ); | 79 | ); |
66 | |||
67 | gulp.start('uglify'); | ||
68 | }); | 80 | }); |
69 | 81 | ||
70 | gulp.task('clean-post-install', function() { | 82 | gulp.task('clean-post-install', function() { |
71 | return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', | 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 | .pipe(clean()); | 85 | .pipe(clean()); |
74 | }); | 86 | }); |
75 | 87 | ||
76 | gulp.task('compile', ['templates', 'uglify']); | 88 | gulp.task('compile', ['templates', 'uglify']); |
77 | 89 | ||
78 | gulp.task('watch', function() { | 90 | gulp.task('watch', function() { |
79 | gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); | 91 | gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); |
80 | }); | 92 | }); |
81 | 93 | ||
82 | gulp.task('webserver', function() { | 94 | gulp.task('webserver', function() { |
83 | pump [ | 95 | pump [ |
84 | connect.server({port: 3000}) | 96 | connect.server({port: 3000}) |
85 | ] | 97 | ] |
86 | }); | 98 | }); |
87 | 99 |
package.json
1 | { | 1 | { |
2 | "name": "foca-abm-vendedor-cobrador", | 2 | "name": "foca-abm-vendedor-cobrador", |
3 | "version": "0.0.1", | 3 | "version": "0.0.1", |
4 | "description": "Abm de Vendedores/Compradores", | 4 | "description": "Abm de Vendedores/Compradores", |
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 i --ignore-scripts" | 11 | "install-dev": "npm i --ignore-scripts" |
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-vendedor-cobrador.git" | 18 | "url": "http://git.focasoftware.com/npm/foca-abm-vendedor-cobrador.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-mocks": "^1.7.7", | ||
39 | "angular-route": "^1.7.5", | 40 | "angular-route": "^1.7.5", |
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", |
47 | "gulp-htmlmin": "^5.0.1", | 48 | "gulp-htmlmin": "^5.0.1", |
48 | "gulp-jshint": "^2.1.0", | 49 | "gulp-jshint": "^2.1.0", |
49 | "gulp-rename": "^1.4.0", | 50 | "gulp-rename": "^1.4.0", |
50 | "gulp-replace": "^1.0.0", | 51 | "gulp-replace": "^1.0.0", |
51 | "gulp-uglify": "^3.0.1", | 52 | "gulp-uglify": "^3.0.1", |
52 | "gulp-uglify-es": "^1.0.4", | 53 | "gulp-uglify-es": "^1.0.4", |
53 | "jasmine-core": "^3.3.0", | 54 | "jasmine-core": "^3.3.0", |
54 | "jquery": "^3.3.1", | 55 | "jquery": "^3.3.1", |
55 | "jshint": "^2.9.6", | 56 | "jshint": "^2.9.6", |
56 | "pre-commit": "^1.2.2", | 57 | "pre-commit": "^1.2.2", |
57 | "pump": "^3.0.0", | 58 | "pump": "^3.0.0", |
58 | "ui-bootstrap4": "^3.0.5" | 59 | "ui-bootstrap4": "^3.0.5" |
59 | } | 60 | } |
60 | } | 61 | } |
61 | 62 |
spec/controllerSpec.js
File was created | 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 | }); | ||
695 |
spec/routeSpec.js
File was created | 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 | }); | ||
28 |
spec/serviceSpec.js
File was created | 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 | }); | ||
121 |
src/js/app.js
1 | angular.module('focaAbmVendedorCobrador', []); | 1 | angular.module('focaAbmVendedorCobrador', ['ngRoute']); |
2 | 2 |
src/js/controller.js
1 | angular.module('focaAbmVendedorCobrador') | 1 | angular.module('focaAbmVendedorCobrador') |
2 | .controller('focaAbmVendedoresCobradoresController', [ | 2 | .controller('focaAbmVendedoresCobradoresController', [ |
3 | '$scope', 'focaAbmVendedorCobradorService', '$location', '$filter', | 3 | '$scope', 'focaAbmVendedorCobradorService', '$location', '$filter', |
4 | 'focaBotoneraLateralService', 'focaModalService', | 4 | 'focaBotoneraLateralService', 'focaModalService', |
5 | function($scope, focaAbmVendedorCobradorService, $location, $filter, | 5 | function($scope, focaAbmVendedorCobradorService, $location, $filter, |
6 | focaBotoneraLateralService, focaModalService) { | 6 | focaBotoneraLateralService, focaModalService) { |
7 | $scope.now = new Date(); | 7 | $scope.now = new Date(); |
8 | $scope.vendedoresCobradores = []; | 8 | $scope.vendedoresCobradores = []; |
9 | $scope.filters = ''; | 9 | $scope.filters = ''; |
10 | $scope.numPerPage = 10; | 10 | $scope.numPerPage = 10; |
11 | $scope.currentPageVendedoresCobradores = []; | 11 | $scope.currentPageVendedoresCobradores = []; |
12 | $scope.vendedoresCobradores = []; | 12 | $scope.vendedoresCobradores = []; |
13 | 13 | ||
14 | //SETEO BOTONERA LATERAL | 14 | //SETEO BOTONERA LATERAL |
15 | focaBotoneraLateralService.showSalir(true); | 15 | focaBotoneraLateralService.showSalir(true); |
16 | focaBotoneraLateralService.showPausar(false); | 16 | focaBotoneraLateralService.showPausar(false); |
17 | focaBotoneraLateralService.showCancelar(false); | 17 | focaBotoneraLateralService.showCancelar(false); |
18 | focaBotoneraLateralService.showGuardar(false); | 18 | focaBotoneraLateralService.showGuardar(false); |
19 | 19 | ||
20 | $scope.editar = function(id) { | 20 | $scope.editar = function(id) { |
21 | $location.path('/vendedor-cobrador/' + id); | 21 | $location.path('/vendedor-cobrador/' + id); |
22 | }; | 22 | }; |
23 | 23 | ||
24 | $scope.eliminar = function(vendedorCobrador) { | 24 | $scope.eliminar = function(vendedorCobrador) { |
25 | var tipo = !!(vendedorCobrador.rol | 2) ? 'cobrador' : 'vendedor'; | 25 | var tipo = !!(vendedorCobrador.rol | 2) ? 'cobrador' : 'vendedor'; |
26 | focaModalService.confirm('¿Está seguro que desea borrar el ' + tipo + | 26 | focaModalService.confirm('¿Está seguro que desea borrar el ' + tipo + |
27 | ' ' + vendedorCobrador.NOM + '?') | 27 | ' ' + vendedorCobrador.NOM + '?') |
28 | .then(function(data) { | 28 | .then(function(data) { |
29 | if(data) { | 29 | if(data) { |
30 | focaAbmVendedorCobradorService | 30 | focaAbmVendedorCobradorService |
31 | .eliminarVendedorCobrador(vendedorCobrador.NUM) | 31 | .eliminarVendedorCobrador(vendedorCobrador.NUM) |
32 | .then(function() { | 32 | .then(function() { |
33 | $scope.search(13); | 33 | $scope.search(13); |
34 | }); | 34 | }); |
35 | } | 35 | } |
36 | }); | 36 | }); |
37 | }; | 37 | }; |
38 | 38 | ||
39 | $scope.selectPage = function(page) { | 39 | $scope.selectPage = function(page) { |
40 | var start = (page - 1) * $scope.numPerPage; | 40 | var start = (page - 1) * $scope.numPerPage; |
41 | var end = start + $scope.numPerPage; | 41 | var end = start + $scope.numPerPage; |
42 | $scope.paginas = []; | 42 | $scope.paginas = []; |
43 | $scope.paginas = calcularPages(page); | 43 | $scope.paginas = calcularPages(page); |
44 | $scope.currentPageVendedoresCobradores = | 44 | $scope.currentPageVendedoresCobradores = |
45 | $scope.vendedoresCobradores.slice(start, end); | 45 | $scope.vendedoresCobradores.slice(start, end); |
46 | $scope.currentPage = page; | 46 | $scope.currentPage = page; |
47 | }; | 47 | }; |
48 | 48 | ||
49 | $scope.resetPage = function() { | 49 | $scope.resetPage = function() { |
50 | $scope.currentPage = 1; | 50 | $scope.currentPage = 1; |
51 | $scope.selectPage(1); | 51 | $scope.selectPage(1); |
52 | }; | 52 | }; |
53 | 53 | ||
54 | $scope.search = function(key) { | 54 | $scope.search = function(key) { |
55 | if(key !== 13) return; | 55 | if(key !== 13) return; |
56 | 56 | ||
57 | focaAbmVendedorCobradorService | 57 | focaAbmVendedorCobradorService |
58 | .getVendedoresCobradores($scope.filters) | 58 | .getVendedoresCobradores($scope.filters) |
59 | .then(function(res) { | 59 | .then(function(res) { |
60 | $scope.vendedoresCobradores = res.data; | 60 | $scope.vendedoresCobradores = res.data; |
61 | 61 | ||
62 | $scope.lastPage = Math.ceil( | 62 | $scope.lastPage = Math.ceil( |
63 | $scope.vendedoresCobradores.length / $scope.numPerPage | 63 | $scope.vendedoresCobradores.length / $scope.numPerPage |
64 | ); | 64 | ); |
65 | 65 | ||
66 | $scope.resetPage(); | 66 | $scope.resetPage(); |
67 | }); | 67 | }); |
68 | }; | 68 | }; |
69 | 69 | ||
70 | function calcularPages(paginaActual) { | 70 | function calcularPages(paginaActual) { |
71 | var paginas = []; | 71 | var paginas = []; |
72 | paginas.push(paginaActual); | 72 | paginas.push(paginaActual); |
73 | 73 | ||
74 | if(paginaActual - 1 > 1) { | 74 | if(paginaActual - 1 > 1) { |
75 | 75 | ||
76 | paginas.unshift(paginaActual - 1); | 76 | paginas.unshift(paginaActual - 1); |
77 | if(paginaActual - 2 > 1) { | 77 | if(paginaActual - 2 > 1) { |
78 | paginas.unshift(paginaActual - 2); | 78 | paginas.unshift(paginaActual - 2); |
79 | } | 79 | } |
80 | } | 80 | } |
81 | 81 | ||
82 | if(paginaActual + 1 < $scope.lastPage) { | 82 | if(paginaActual + 1 < $scope.lastPage) { |
83 | paginas.push(paginaActual + 1); | 83 | paginas.push(paginaActual + 1); |
84 | if(paginaActual + 2 < $scope.lastPage) { | 84 | if(paginaActual + 2 < $scope.lastPage) { |
85 | paginas.push(paginaActual + 2); | 85 | paginas.push(paginaActual + 2); |
86 | } | 86 | } |
87 | } | 87 | } |
88 | 88 | ||
89 | if(paginaActual !== 1) { | 89 | if(paginaActual !== 1) { |
90 | paginas.unshift(1); | 90 | paginas.unshift(1); |
91 | } | 91 | } |
92 | 92 | ||
93 | if(paginaActual !== $scope.lastPage) { | 93 | if(paginaActual !== $scope.lastPage) { |
94 | paginas.push($scope.lastPage); | 94 | paginas.push($scope.lastPage); |
95 | } | 95 | } |
96 | 96 | ||
97 | return paginas; | 97 | return paginas; |
98 | } | 98 | } |
99 | 99 | // TODO: descomentar cuando se use | |
100 | function primera() { | 100 | // function primera() { |
101 | $scope.selectedClientes = 0; | 101 | // $scope.selectedClientes = 0; |
102 | } | 102 | // } |
103 | 103 | ||
104 | function anterior() { | 104 | // function anterior() { |
105 | if ($scope.selectedClientes === 0 && $scope.currentPage > 1) { | 105 | // if ($scope.selectedClientes === 0 && $scope.currentPage > 1) { |
106 | retrocederPagina(); | 106 | // retrocederPagina(); |
107 | } else { | 107 | // } else { |
108 | $scope.selectedClientes--; | 108 | // $scope.selectedClientes--; |
109 | } | 109 | // } |
110 | } | 110 | // } |
111 | 111 | ||
112 | function siguiente() { | 112 | // function siguiente() { |
113 | if ($scope.selectedClientes < $scope.currentPageVendedoresCobradores.length - 1 ) { | 113 | // if ($scope.selectedClientes < $scope.currentPageVendedoresCobradores.length - 1 ) |
114 | $scope.selectedClientes++; | 114 | //{ |
115 | } else { | 115 | // $scope.selectedClientes++; |
116 | avanzarPagina(); | 116 | // } else { |
117 | } | 117 | // avanzarPagina(); |
118 | } | 118 | // } |
119 | 119 | // } | |
120 | function retrocederPagina() { | 120 | |
121 | if ($scope.currentPage > 1) { | 121 | // function retrocederPagina() { |
122 | $scope.selectPage($scope.currentPage - 1); | 122 | // if ($scope.currentPage > 1) { |
123 | $scope.selectedClientes = $scope.numPerPage - 1; | 123 | // $scope.selectPage($scope.currentPage - 1); |
124 | } | 124 | // $scope.selectedClientes = $scope.numPerPage - 1; |
125 | } | 125 | // } |
126 | 126 | // } | |
127 | function avanzarPagina() { | 127 | |
128 | if ($scope.currentPage < $scope.lastPage) { | 128 | // function avanzarPagina() { |
129 | $scope.selectPage($scope.currentPage + 1); | 129 | // if ($scope.currentPage < $scope.lastPage) { |
130 | $scope.selectedClientes = 0; | 130 | // $scope.selectPage($scope.currentPage + 1); |
131 | } | 131 | // $scope.selectedClientes = 0; |
132 | } | 132 | // } |
133 | // } | ||
133 | } | 134 | } |
134 | ]); | 135 | ]); |
135 | 136 |
src/js/service.js
1 | angular.module('focaAbmVendedorCobrador') | 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 | return { | 4 | return { |
4 | getVendedoresCobradores: function(nombre) { | 5 | getVendedoresCobradores: function(nombre) { |
5 | return $http.post(API_ENDPOINT.URL + '/vendedor-cobrador/list', {nombre: nombre}); | 6 | return $http.post(API_ENDPOINT.URL + '/vendedor-cobrador/list', {nombre: nombre}); |
6 | }, | 7 | }, |
7 | getVendedorCobradorById: function(id) { | 8 | getVendedorCobradorById: function(id) { |
8 | return $http.get(API_ENDPOINT.URL + '/vendedor-cobrador/' + id); | 9 | return $http.get(API_ENDPOINT.URL + '/vendedor-cobrador/' + id); |
9 | }, | 10 | }, |
10 | guardarVendedorCobrador: function(vendedorCobrador) { | 11 | guardarVendedorCobrador: function(vendedorCobrador) { |
11 | return $http.post(API_ENDPOINT.URL + '/vendedor-cobrador', | 12 | return $http.post(API_ENDPOINT.URL + '/vendedor-cobrador', |
12 | {vendedorCobrador: vendedorCobrador}); | 13 | {vendedorCobrador: vendedorCobrador}); |
13 | }, | 14 | }, |
14 | eliminarVendedorCobrador: function(id) { | 15 | eliminarVendedorCobrador: function(id) { |
15 | return $http.delete(API_ENDPOINT.URL + '/vendedor-cobrador/' + id); | 16 | return $http.delete(API_ENDPOINT.URL + '/vendedor-cobrador/' + id); |
16 | }, | 17 | }, |
17 | getCodigoSiguiente: function() { | 18 | getCodigoSiguiente: function() { |
18 | return $http.get(API_ENDPOINT.URL + '/vendedor-cobrador/obtener/siguiente-codigo'); | 19 | return $http.get(API_ENDPOINT.URL + '/vendedor-cobrador/obtener/siguiente-codigo'); |
19 | } | 20 | } |
20 | }; | 21 | }; |
21 | }]); | 22 | }]); |
22 | 23 |
test.html
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/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> | ||
23 |