@@ -30,7 +30,7 @@ describe('GridColumn factory', function () {
30
30
31
31
buildCols ( ) ;
32
32
} ) ) ;
33
-
33
+
34
34
describe ( 'buildColumns' , function ( ) {
35
35
it ( 'should not remove existing sort details on a column' , function ( ) {
36
36
var sort = { priority : 0 , direction : 'asc' } ;
@@ -192,7 +192,7 @@ describe('GridColumn factory', function () {
192
192
expect ( col . colDef . visible ) . toBe ( false ) ;
193
193
} ) ;
194
194
} ) ;
195
-
195
+
196
196
describe ( 'aggregation' , function ( ) {
197
197
beforeEach ( function ( ) {
198
198
grid . options . data = [
@@ -202,19 +202,19 @@ describe('GridColumn factory', function () {
202
202
{ name : 'matthew' , value : 4 } ,
203
203
{ name : 'murray' , value : 5 }
204
204
] ;
205
- grid . options . columnDefs = [ { name : 'name' } , { name : 'value' } ] ;
205
+ grid . options . columnDefs = [ { name : 'name' } , { name : 'value' } ] ;
206
206
} ) ;
207
-
207
+
208
208
it ( 'count, with label' , function ( ) {
209
209
grid . options . columnDefs [ 0 ] . aggregationType = uiGridConstants . aggregationTypes . count ;
210
-
210
+
211
211
buildCols ( ) ;
212
212
grid . modifyRows ( grid . options . data ) ;
213
213
214
- // this would be called by the footer cell if it were rendered
214
+ // this would be called by the footer cell if it were rendered
215
215
var deregFn = grid . api . core . on . rowsRendered ( null , grid . columns [ 0 ] . updateAggregationValue ) ;
216
216
grid . setVisibleRows ( grid . rows ) ;
217
-
217
+
218
218
expect ( grid . columns [ 0 ] . getAggregationValue ( ) ) . toEqual ( 5 ) ;
219
219
expect ( grid . columns [ 0 ] . getAggregationText ( ) ) . toEqual ( 'total rows: ' ) ;
220
220
deregFn ( ) ;
@@ -223,29 +223,29 @@ describe('GridColumn factory', function () {
223
223
it ( 'count, without label' , function ( ) {
224
224
grid . options . columnDefs [ 0 ] . aggregationType = uiGridConstants . aggregationTypes . count ;
225
225
grid . options . columnDefs [ 0 ] . aggregationHideLabel = true ;
226
-
226
+
227
227
buildCols ( ) ;
228
228
grid . modifyRows ( grid . options . data ) ;
229
229
230
- // this would be called by the footer cell if it were rendered
230
+ // this would be called by the footer cell if it were rendered
231
231
var deregFn = grid . api . core . on . rowsRendered ( null , grid . columns [ 0 ] . updateAggregationValue ) ;
232
232
grid . setVisibleRows ( grid . rows ) ;
233
-
233
+
234
234
expect ( grid . columns [ 0 ] . getAggregationValue ( ) ) . toEqual ( 5 ) ;
235
235
expect ( grid . columns [ 0 ] . getAggregationText ( ) ) . toEqual ( '' ) ;
236
236
deregFn ( ) ;
237
237
} ) ;
238
238
239
239
it ( 'sum, with label' , function ( ) {
240
240
grid . options . columnDefs [ 1 ] . aggregationType = uiGridConstants . aggregationTypes . sum ;
241
-
241
+
242
242
buildCols ( ) ;
243
243
grid . modifyRows ( grid . options . data ) ;
244
244
245
- // this would be called by the footer cell if it were rendered
245
+ // this would be called by the footer cell if it were rendered
246
246
var deregFn = grid . api . core . on . rowsRendered ( null , grid . columns [ 1 ] . updateAggregationValue ) ;
247
247
grid . setVisibleRows ( grid . rows ) ;
248
-
248
+
249
249
expect ( grid . columns [ 1 ] . getAggregationValue ( ) ) . toEqual ( 15 ) ;
250
250
expect ( grid . columns [ 1 ] . getAggregationText ( ) ) . toEqual ( 'total: ' ) ;
251
251
deregFn ( ) ;
@@ -254,29 +254,29 @@ describe('GridColumn factory', function () {
254
254
it ( 'sum, without label' , function ( ) {
255
255
grid . options . columnDefs [ 1 ] . aggregationType = uiGridConstants . aggregationTypes . sum ;
256
256
grid . options . columnDefs [ 1 ] . aggregationHideLabel = true ;
257
-
257
+
258
258
buildCols ( ) ;
259
259
grid . modifyRows ( grid . options . data ) ;
260
260
261
- // this would be called by the footer cell if it were rendered
261
+ // this would be called by the footer cell if it were rendered
262
262
var deregFn = grid . api . core . on . rowsRendered ( null , grid . columns [ 1 ] . updateAggregationValue ) ;
263
263
grid . setVisibleRows ( grid . rows ) ;
264
-
264
+
265
265
expect ( grid . columns [ 1 ] . getAggregationValue ( ) ) . toEqual ( 15 ) ;
266
266
expect ( grid . columns [ 1 ] . getAggregationText ( ) ) . toEqual ( '' ) ;
267
267
deregFn ( ) ;
268
268
} ) ;
269
269
270
270
it ( 'avg, with label' , function ( ) {
271
271
grid . options . columnDefs [ 1 ] . aggregationType = uiGridConstants . aggregationTypes . avg ;
272
-
272
+
273
273
buildCols ( ) ;
274
274
grid . modifyRows ( grid . options . data ) ;
275
275
276
- // this would be called by the footer cell if it were rendered
276
+ // this would be called by the footer cell if it were rendered
277
277
var deregFn = grid . api . core . on . rowsRendered ( null , grid . columns [ 1 ] . updateAggregationValue ) ;
278
278
grid . setVisibleRows ( grid . rows ) ;
279
-
279
+
280
280
expect ( grid . columns [ 1 ] . getAggregationValue ( ) ) . toEqual ( 3 ) ;
281
281
expect ( grid . columns [ 1 ] . getAggregationText ( ) ) . toEqual ( 'avg: ' ) ;
282
282
deregFn ( ) ;
@@ -285,29 +285,29 @@ describe('GridColumn factory', function () {
285
285
it ( 'avg, without label' , function ( ) {
286
286
grid . options . columnDefs [ 1 ] . aggregationType = uiGridConstants . aggregationTypes . avg ;
287
287
grid . options . columnDefs [ 1 ] . aggregationHideLabel = true ;
288
-
288
+
289
289
buildCols ( ) ;
290
290
grid . modifyRows ( grid . options . data ) ;
291
291
292
- // this would be called by the footer cell if it were rendered
292
+ // this would be called by the footer cell if it were rendered
293
293
var deregFn = grid . api . core . on . rowsRendered ( null , grid . columns [ 1 ] . updateAggregationValue ) ;
294
294
grid . setVisibleRows ( grid . rows ) ;
295
-
295
+
296
296
expect ( grid . columns [ 1 ] . getAggregationValue ( ) ) . toEqual ( 3 ) ;
297
297
expect ( grid . columns [ 1 ] . getAggregationText ( ) ) . toEqual ( '' ) ;
298
298
deregFn ( ) ;
299
- } ) ;
299
+ } ) ;
300
300
301
301
it ( 'min, with label' , function ( ) {
302
302
grid . options . columnDefs [ 1 ] . aggregationType = uiGridConstants . aggregationTypes . min ;
303
-
303
+
304
304
buildCols ( ) ;
305
305
grid . modifyRows ( grid . options . data ) ;
306
306
307
- // this would be called by the footer cell if it were rendered
307
+ // this would be called by the footer cell if it were rendered
308
308
var deregFn = grid . api . core . on . rowsRendered ( null , grid . columns [ 1 ] . updateAggregationValue ) ;
309
309
grid . setVisibleRows ( grid . rows ) ;
310
-
310
+
311
311
expect ( grid . columns [ 1 ] . getAggregationValue ( ) ) . toEqual ( 1 ) ;
312
312
expect ( grid . columns [ 1 ] . getAggregationText ( ) ) . toEqual ( 'min: ' ) ;
313
313
deregFn ( ) ;
@@ -316,29 +316,29 @@ describe('GridColumn factory', function () {
316
316
it ( 'min, without label' , function ( ) {
317
317
grid . options . columnDefs [ 1 ] . aggregationType = uiGridConstants . aggregationTypes . min ;
318
318
grid . options . columnDefs [ 1 ] . aggregationHideLabel = true ;
319
-
319
+
320
320
buildCols ( ) ;
321
321
grid . modifyRows ( grid . options . data ) ;
322
322
323
- // this would be called by the footer cell if it were rendered
323
+ // this would be called by the footer cell if it were rendered
324
324
var deregFn = grid . api . core . on . rowsRendered ( null , grid . columns [ 1 ] . updateAggregationValue ) ;
325
325
grid . setVisibleRows ( grid . rows ) ;
326
-
326
+
327
327
expect ( grid . columns [ 1 ] . getAggregationValue ( ) ) . toEqual ( 1 ) ;
328
328
expect ( grid . columns [ 1 ] . getAggregationText ( ) ) . toEqual ( '' ) ;
329
329
deregFn ( ) ;
330
330
} ) ;
331
331
332
332
it ( 'max, with label' , function ( ) {
333
333
grid . options . columnDefs [ 1 ] . aggregationType = uiGridConstants . aggregationTypes . max ;
334
-
334
+
335
335
buildCols ( ) ;
336
336
grid . modifyRows ( grid . options . data ) ;
337
337
338
- // this would be called by the footer cell if it were rendered
338
+ // this would be called by the footer cell if it were rendered
339
339
var deregFn = grid . api . core . on . rowsRendered ( null , grid . columns [ 1 ] . updateAggregationValue ) ;
340
340
grid . setVisibleRows ( grid . rows ) ;
341
-
341
+
342
342
expect ( grid . columns [ 1 ] . getAggregationValue ( ) ) . toEqual ( 5 ) ;
343
343
expect ( grid . columns [ 1 ] . getAggregationText ( ) ) . toEqual ( 'max: ' ) ;
344
344
deregFn ( ) ;
@@ -347,14 +347,14 @@ describe('GridColumn factory', function () {
347
347
it ( 'max, without label' , function ( ) {
348
348
grid . options . columnDefs [ 1 ] . aggregationType = uiGridConstants . aggregationTypes . max ;
349
349
grid . options . columnDefs [ 1 ] . aggregationHideLabel = true ;
350
-
350
+
351
351
buildCols ( ) ;
352
352
grid . modifyRows ( grid . options . data ) ;
353
353
354
- // this would be called by the footer cell if it were rendered
354
+ // this would be called by the footer cell if it were rendered
355
355
var deregFn = grid . api . core . on . rowsRendered ( null , grid . columns [ 1 ] . updateAggregationValue ) ;
356
356
grid . setVisibleRows ( grid . rows ) ;
357
-
357
+
358
358
expect ( grid . columns [ 1 ] . getAggregationValue ( ) ) . toEqual ( 5 ) ;
359
359
expect ( grid . columns [ 1 ] . getAggregationText ( ) ) . toEqual ( '' ) ;
360
360
deregFn ( ) ;
@@ -370,7 +370,7 @@ describe('GridColumn factory', function () {
370
370
buildCols ( ) ;
371
371
grid . modifyRows ( grid . options . data ) ;
372
372
373
- // this would be called by the footer cell if it were rendered
373
+ // this would be called by the footer cell if it were rendered
374
374
var deregFn = grid . api . core . on . rowsRendered ( null , grid . columns [ 1 ] . updateAggregationValue ) ;
375
375
grid . setVisibleRows ( grid . rows ) ;
376
376
@@ -389,7 +389,7 @@ describe('GridColumn factory', function () {
389
389
buildCols ( ) ;
390
390
grid . modifyRows ( grid . options . data ) ;
391
391
392
- // this would be called by the footer cell if it were rendered
392
+ // this would be called by the footer cell if it were rendered
393
393
var deregFn = grid . api . core . on . rowsRendered ( null , grid . columns [ 1 ] . updateAggregationValue ) ;
394
394
grid . setVisibleRows ( grid . rows ) ;
395
395
@@ -408,13 +408,13 @@ describe('GridColumn factory', function () {
408
408
{ name : 'matthew' , value : 4 } ,
409
409
{ name : 'murray' , value : 5 }
410
410
] ;
411
- grid . options . columnDefs = [ { name : 'name' } , { name : 'value' } ] ;
411
+ grid . options . columnDefs = [ { name : 'name' } , { name : 'value' } ] ;
412
412
} ) ;
413
-
413
+
414
414
it ( 'raise event' , function ( ) {
415
415
var sortChanged = false ;
416
416
grid . api . core . on . sortChanged ( $scope , function ( ) { sortChanged = true ; } ) ;
417
-
417
+
418
418
grid . columns [ 0 ] . unsort ( ) ;
419
419
expect ( sortChanged ) . toEqual ( true ) ;
420
420
} ) ;
@@ -560,6 +560,52 @@ describe('GridColumn factory', function () {
560
560
expect ( updateCol ( colDef . width ) ) . toThrow ( ) ;
561
561
} ) ;
562
562
563
+ it ( 'should set the value of minWidth to 30 when colDef.minWidth is undefined' , invalidMinOrMaxWidthDef ( undefined , 'minWidth' ) ) ;
564
+ it ( 'should set the value of minWidth to 30 when colDef.minWidth is null' , invalidMinOrMaxWidthDef ( null , 'minWidth' ) ) ;
565
+ it ( 'should set the value of minWidth to 30 when colDef.minWidth is an object' , invalidMinOrMaxWidthDef ( { } , 'minWidth' ) ) ;
566
+
567
+ it ( 'should set the value of minWidth to the parsed integer colDef.minWidth when it is a string' , function ( ) {
568
+ colDef . minWidth = '90' ;
569
+ col . updateColumnDef ( colDef ) ;
570
+ expect ( col . minWidth ) . toBe ( 90 ) ;
571
+ } ) ;
572
+
573
+ it ( 'should set the value of minWidth to colDef.minWidth when it is a number' , function ( ) {
574
+ colDef . minWidth = 90 ;
575
+ col . updateColumnDef ( colDef ) ;
576
+ expect ( col . minWidth ) . toBe ( 90 ) ;
577
+ } ) ;
578
+
579
+ it ( 'should throw when colDef.minWidth is an invalid string' , function ( ) {
580
+ colDef . minWidth = 'e1%' ;
581
+ expect ( col . updateColumnDef ( colDef ) ) . toThrow ( ) ;
582
+ colDef . minWidth = '#FFF' ;
583
+ expect ( col . updateColumnDef ( colDef ) ) . toThrow ( ) ;
584
+ } ) ;
585
+
586
+ it ( 'should set the value of maxWidth to 9000 when colDef.maxWidth is undefined' , invalidMinOrMaxWidthDef ( undefined , 'maxWidth' ) ) ;
587
+ it ( 'should set the value of maxWidth to 9000 when colDef.maxWidth is null' , invalidMinOrMaxWidthDef ( null , 'maxWidth' ) ) ;
588
+ it ( 'should set the value of maxWidth to 9000 when colDef.maxWidth is an object' , invalidMinOrMaxWidthDef ( { } , 'maxWidth' ) ) ;
589
+
590
+ it ( 'should set the value of maxWidth to the parsed integer colDef.maxWidth when it is a string' , function ( ) {
591
+ colDef . maxWidth = '200' ;
592
+ col . updateColumnDef ( colDef ) ;
593
+ expect ( col . maxWidth ) . toBe ( 200 ) ;
594
+ } ) ;
595
+
596
+ it ( 'should set the value of maxWidth to colDef.maxWidth when it is a number' , function ( ) {
597
+ colDef . maxWidth = 200 ;
598
+ col . updateColumnDef ( colDef ) ;
599
+ expect ( col . maxWidth ) . toBe ( 200 ) ;
600
+ } ) ;
601
+
602
+ it ( 'should throw when colDef.maxWidth is an invalid string' , function ( ) {
603
+ colDef . maxWidth = 'e1%' ;
604
+ expect ( col . updateColumnDef ( colDef ) ) . toThrow ( ) ;
605
+ colDef . maxWidth = '#FFF' ;
606
+ expect ( col . updateColumnDef ( colDef ) ) . toThrow ( ) ;
607
+ } ) ;
608
+
563
609
function widthEqualsColDefWidth ( expected ) {
564
610
return function ( ) {
565
611
colDef . width = expected ;
@@ -581,5 +627,13 @@ describe('GridColumn factory', function () {
581
627
col . updateColumnDef ( colDef ) ;
582
628
} ;
583
629
}
630
+
631
+ function invalidMinOrMaxWidthDef ( width , minOrMax ) {
632
+ return function ( ) {
633
+ colDef [ minOrMax ] = width ;
634
+ col . updateColumnDef ( colDef ) ;
635
+ expect ( col [ minOrMax ] ) . toBe ( minOrMax === 'minWidth' ? 30 : 9000 ) ;
636
+ } ;
637
+ }
584
638
} ) ;
585
- } ) ;
639
+ } ) ;
0 commit comments