@@ -9,10 +9,11 @@ describe('ui.grid.exporter uiGridExporterService', function () {
9
9
var $scope ;
10
10
var $document ;
11
11
12
- beforeEach ( module ( 'ui.grid.exporter' , 'ui.grid.selection' ) ) ;
12
+ beforeEach ( module ( 'ui.grid.exporter' , 'ui.grid.selection' , 'ui.grid.pinning' ) ) ;
13
13
14
14
15
- beforeEach ( inject ( function ( _uiGridExporterService_ , _uiGridSelectionService_ , _gridClassFactory_ , _uiGridExporterConstants_ ,
15
+ beforeEach ( inject ( function ( _uiGridExporterService_ , _uiGridSelectionService_ , _uiGridPinningService_ , _gridClassFactory_ , _uiGridExporterConstants_ ,
16
+ _uiGridPinningConstants_ ,
16
17
_$compile_ , _$rootScope_ , _$document_ , _uiGridSelectionConstants_ ) {
17
18
uiGridExporterService = _uiGridExporterService_ ;
18
19
uiGridSelectionService = _uiGridSelectionService_ ;
@@ -25,14 +26,15 @@ describe('ui.grid.exporter uiGridExporterService', function () {
25
26
26
27
grid = gridClassFactory . createGrid ( { } ) ;
27
28
grid . options . columnDefs = [
28
- { field : 'col1' , name : 'col1' , displayName : 'Col1' , width : 50 } ,
29
+ { field : 'col1' , name : 'col1' , displayName : 'Col1' , width : 50 , pinnedLeft : true } ,
29
30
{ field : 'col2' , name : 'col2' , displayName : 'Col2' , width : '*' , type : 'number' } ,
30
31
{ field : 'col3' , name : 'col3' , displayName : 'Col3' , width : 100 } ,
31
32
{ field : 'col4' , name : 'col4' , displayName : 'Col4' , width : 200 }
32
33
] ;
33
34
34
35
_uiGridExporterService_ . initializeGrid ( grid ) ;
35
36
_uiGridSelectionService_ . initializeGrid ( grid ) ;
37
+ _uiGridPinningService_ . initializeGrid ( grid ) ;
36
38
var data = [ ] ;
37
39
for ( var i = 0 ; i < 3 ; i ++ ) {
38
40
data . push ( { col1 :'a_' + i , col2 :'b_' + i , col3 :'c_' + i , col4 :'d_' + i } ) ;
@@ -48,21 +50,22 @@ describe('ui.grid.exporter uiGridExporterService', function () {
48
50
49
51
grid . api . selection . clearSelectedRows ( ) ;
50
52
grid . api . selection . selectRow ( grid . rows [ 0 ] . entity ) ;
51
-
53
+
52
54
grid . gridWidth = 500 ;
53
- grid . columns [ 0 ] . drawnWidth = 50 ;
54
- grid . columns [ 1 ] . drawnWidth = '*' ;
55
- grid . columns [ 2 ] . drawnWidth = 100 ;
56
- grid . columns [ 3 ] . drawnWidth = 200 ;
55
+ grid . columns [ 0 ] . drawnWidth = 50 ;
56
+ grid . columns [ 1 ] . drawnWidth = '*' ;
57
+ grid . columns [ 2 ] . drawnWidth = 100 ;
58
+ grid . columns [ 3 ] . drawnWidth = 200 ;
59
+
57
60
} ) ) ;
58
-
61
+
59
62
60
63
describe ( 'defaultGridOptions' , function ( ) {
61
64
var options ;
62
65
beforeEach ( function ( ) {
63
66
options = { } ;
64
67
} ) ;
65
-
68
+
66
69
it ( 'set all options to default' , function ( ) {
67
70
uiGridExporterService . defaultGridOptions ( options ) ;
68
71
expect ( options ) . toEqual ( {
@@ -87,7 +90,7 @@ describe('ui.grid.exporter uiGridExporterService', function () {
87
90
exporterMenuPdf : true ,
88
91
exporterFieldCallback : jasmine . any ( Function ) ,
89
92
exporterAllDataFn : null ,
90
- exporterSuppressColumns : [ ]
93
+ exporterSuppressColumns : [ ]
91
94
} ) ;
92
95
} ) ;
93
96
@@ -143,7 +146,7 @@ describe('ui.grid.exporter uiGridExporterService', function () {
143
146
exporterAllDataPromise : callback ,
144
147
exporterSuppressColumns : [ 'buttons' ]
145
148
} ) ;
146
- } ) ;
149
+ } ) ;
147
150
} ) ;
148
151
149
152
@@ -254,7 +257,7 @@ describe('ui.grid.exporter uiGridExporterService', function () {
254
257
expect ( uiGridExporterService . getData ( grid , uiGridExporterConstants . SELECTED , uiGridExporterConstants . VISIBLE ) ) . toEqual ( [
255
258
[ { value : 'a_0' } , { value : 'b_0' } , { value : 'd_0' } ]
256
259
] ) ;
257
- } ) ;
260
+ } ) ;
258
261
259
262
it ( 'maps data using objectCallback' , function ( ) {
260
263
grid . options . exporterFieldCallback = function ( grid , row , col , value ) {
@@ -279,7 +282,7 @@ describe('ui.grid.exporter uiGridExporterService', function () {
279
282
var columnHeaders = [ ] ;
280
283
var data = [ ] ;
281
284
var separator = ',' ;
282
-
285
+
283
286
expect ( uiGridExporterService . formatAsCsv ( columnHeaders , data , separator ) ) . toEqual (
284
287
"\n"
285
288
) ;
@@ -302,12 +305,12 @@ describe('ui.grid.exporter uiGridExporterService', function () {
302
305
] ;
303
306
304
307
var separator = ',' ;
305
-
308
+
306
309
expect ( uiGridExporterService . formatAsCsv ( columnHeaders , data , separator ) ) . toEqual (
307
310
'"Col1","Col2","Col3","12345234"\n"a string","a string","A string","a string"\n"","45","A string",FALSE\n"' + date . toISOString ( ) + '",45,"A string",TRUE'
308
311
) ;
309
312
} ) ;
310
-
313
+
311
314
it ( 'formats a mix of data as a csv with custom separator' , function ( ) {
312
315
var columnHeaders = [
313
316
{ name : 'col1' , displayName : 'Col1' , width : 50 , align : 'left' } ,
@@ -323,9 +326,9 @@ describe('ui.grid.exporter uiGridExporterService', function () {
323
326
[ { value : '' } , { value : '45' } , { value : 'A string' } , { value : false } ] ,
324
327
[ { value : date } , { value : 45 } , { value : 'A string' } , { value : true } ]
325
328
] ;
326
-
329
+
327
330
var separator = ';' ;
328
-
331
+
329
332
expect ( uiGridExporterService . formatAsCsv ( columnHeaders , data , separator ) ) . toEqual (
330
333
'"Col1";"Col2";"Col3";"12345234"\n"a string";"a string";"A string";"a string"\n"";"45";"A string";FALSE\n"' + date . toISOString ( ) + '";45;"A string";TRUE'
331
334
) ;
@@ -353,51 +356,51 @@ describe('ui.grid.exporter uiGridExporterService', function () {
353
356
[ { value : '' } , { value : '45' } , { value : 'A string' } , { value : false } ] ,
354
357
[ { value : date } , { value : 45 } , { value : 'A string' } , { value : true } ]
355
358
] ;
356
-
359
+
357
360
var result = uiGridExporterService . prepareAsPdf ( grid , columnHeaders , data ) ;
358
361
expect ( result ) . toEqual ( {
359
362
pageOrientation : 'landscape' ,
360
- pageSize : 'A4' ,
361
- content : [ {
363
+ pageSize : 'A4' ,
364
+ content : [ {
362
365
style : 'tableStyle' ,
363
- table : {
364
- headerRows : 1 ,
365
- widths : [ 50 * 720 / 450 , '*' , 100 * 720 / 450 , 200 * 720 / 450 ] ,
366
+ table : {
367
+ headerRows : 1 ,
368
+ widths : [ 50 * 720 / 450 , '*' , 100 * 720 / 450 , 200 * 720 / 450 ] ,
366
369
body : [
367
- [
368
- { text : 'Col1' , style : 'tableHeader' } ,
369
- { text : 'Col2' , style : 'tableHeader' } ,
370
- { text : 'Col3' , style : 'tableHeader' } ,
370
+ [
371
+ { text : 'Col1' , style : 'tableHeader' } ,
372
+ { text : 'Col2' , style : 'tableHeader' } ,
373
+ { text : 'Col3' , style : 'tableHeader' } ,
371
374
{ text : '12345234' , style : 'tableHeader' }
372
- ] ,
373
- [ 'a string' , 'a string' , 'A string' , 'a string' ] ,
374
- [ '' , '45' , 'A string' , 'FALSE' ] ,
375
- [ date . toISOString ( ) , '45' , 'A string' , 'TRUE' ]
376
- ]
377
- }
378
- } ] ,
379
- styles : {
380
- tableStyle : {
381
- margin : [ 0 , 5 , 0 , 15 ]
382
- } ,
383
- tableHeader : {
384
- bold : true , fontSize : 12 , color : 'black'
385
- }
386
- } ,
387
- defaultStyle : {
388
- fontSize : 11
375
+ ] ,
376
+ [ 'a string' , 'a string' , 'A string' , 'a string' ] ,
377
+ [ '' , '45' , 'A string' , 'FALSE' ] ,
378
+ [ date . toISOString ( ) , '45' , 'A string' , 'TRUE' ]
379
+ ]
380
+ }
381
+ } ] ,
382
+ styles : {
383
+ tableStyle : {
384
+ margin : [ 0 , 5 , 0 , 15 ]
385
+ } ,
386
+ tableHeader : {
387
+ bold : true , fontSize : 12 , color : 'black'
388
+ }
389
+ } ,
390
+ defaultStyle : {
391
+ fontSize : 11
389
392
}
390
- } ) ;
393
+ } ) ;
391
394
392
395
} ) ;
393
-
396
+
394
397
it ( 'prepares standard grid using overrides' , function ( ) {
395
398
/*
396
399
* Note that you can test the results from prepareAsPdf using
397
400
* http://pdfmake.org/playground.html#, which verifies
398
401
* that it creates a genuine pdf
399
402
*/
400
-
403
+
401
404
grid . options . exporterPdfDefaultStyle = { fontSize : 10 } ;
402
405
grid . options . exporterPdfTableStyle = { margin : [ 30 , 30 , 30 , 30 ] } ;
403
406
grid . options . exporterPdfTableHeaderStyle = { fontSize : 11 , bold : true , italic : true } ;
@@ -410,7 +413,7 @@ describe('ui.grid.exporter uiGridExporterService', function () {
410
413
grid . options . exporterPdfOrientation = 'portrait' ;
411
414
grid . options . exporterPdfPageSize = 'LETTER' ;
412
415
grid . options . exporterPdfMaxGridWidth = 500 ;
413
-
416
+
414
417
var columnHeaders = [
415
418
{ name : 'col1' , displayName : 'Col1' , width : 100 , exporterPdfAlign : 'right' } ,
416
419
{ name : 'col2' , displayName : 'Col2' , width : '*' , exporterPdfAlign : 'left' } ,
@@ -425,50 +428,50 @@ describe('ui.grid.exporter uiGridExporterService', function () {
425
428
[ { value : '' , alignment : 'right' } , { value : '45' , alignment : 'center' } , { value : 'A string' , alignment : 'left' } , { value : false } ] ,
426
429
[ { value : date , alignment : 'right' } , { value : 45 , alignment : 'center' } , { value : 'A string' , alignment : 'left' } , { value : true } ]
427
430
] ;
428
-
431
+
429
432
var result = uiGridExporterService . prepareAsPdf ( grid , columnHeaders , data ) ;
430
433
expect ( result ) . toEqual ( {
431
434
pageOrientation : 'portrait' ,
432
- pageSize : 'LETTER' ,
435
+ pageSize : 'LETTER' ,
433
436
content : [
434
- {
435
- style : 'tableStyle' ,
436
- table : {
437
- headerRows : 1 ,
438
- widths : [ 100 , '*' , 100 , 200 ] ,
439
- body : [
440
- [
441
- { text : 'Col1' , style : 'tableHeader' } ,
442
- { text : 'Col2' , style : 'tableHeader' } ,
443
- { text : 'Col3' , style : 'tableHeader' } ,
444
- { text : '12345234' , style : 'tableHeader' }
445
- ] ,
446
- [ { text : 'a string' , alignment : 'right' } , { text : 'a string' , alignment : 'center' } , { text : 'A string' , alignment : 'left' } , 'a string' ] ,
447
- [ { text : '' , alignment : 'right' } , { text : '45' , alignment : 'center' } , { text : 'A string' , alignment : 'left' } , 'FALSE' ] ,
448
- [ { text : date . toISOString ( ) , alignment : 'right' } , { text : '45' , alignment : 'center' } , { text : 'A string' , alignment : 'left' } , 'TRUE' ]
449
- ]
450
- }
437
+ {
438
+ style : 'tableStyle' ,
439
+ table : {
440
+ headerRows : 1 ,
441
+ widths : [ 100 , '*' , 100 , 200 ] ,
442
+ body : [
443
+ [
444
+ { text : 'Col1' , style : 'tableHeader' } ,
445
+ { text : 'Col2' , style : 'tableHeader' } ,
446
+ { text : 'Col3' , style : 'tableHeader' } ,
447
+ { text : '12345234' , style : 'tableHeader' }
448
+ ] ,
449
+ [ { text : 'a string' , alignment : 'right' } , { text : 'a string' , alignment : 'center' } , { text : 'A string' , alignment : 'left' } , 'a string' ] ,
450
+ [ { text : '' , alignment : 'right' } , { text : '45' , alignment : 'center' } , { text : 'A string' , alignment : 'left' } , 'FALSE' ] ,
451
+ [ { text : date . toISOString ( ) , alignment : 'right' } , { text : '45' , alignment : 'center' } , { text : 'A string' , alignment : 'left' } , 'TRUE' ]
452
+ ]
453
+ }
451
454
}
452
455
] ,
453
456
header : "My Header" ,
454
- footer : "My Footer" ,
455
- styles : {
456
- tableStyle : {
457
- margin : [ 30 , 30 , 30 , 30 ]
458
- } ,
459
- tableHeader : {
460
- fontSize : 11 , bold : true , italic : true
457
+ footer : "My Footer" ,
458
+ styles : {
459
+ tableStyle : {
460
+ margin : [ 30 , 30 , 30 , 30 ]
461
+ } ,
462
+ tableHeader : {
463
+ fontSize : 11 , bold : true , italic : true
461
464
} ,
462
465
headerStyle : { fontSize : 10 }
463
- } ,
464
- defaultStyle : {
465
- fontSize : 10
466
+ } ,
467
+ defaultStyle : {
468
+ fontSize : 10
466
469
}
467
- } ) ;
468
-
469
- } ) ;
470
+ } ) ;
471
+
472
+ } ) ;
470
473
} ) ;
471
-
474
+
472
475
describe ( 'calculatePdfHeaderWidths' , function ( ) {
473
476
it ( 'calculates mix of widths' , function ( ) {
474
477
var headers = [
@@ -479,19 +482,19 @@ describe('ui.grid.exporter uiGridExporterService', function () {
479
482
{ width : 150 } ,
480
483
{ width : 100 }
481
484
] ;
482
-
485
+
483
486
grid . options . exporterPdfMaxGridWidth = 410 ;
484
-
487
+
485
488
// baseGridWidth = 600
486
489
// extra 120 for 20%
487
490
// extra 100 for '*'
488
491
// total gridWidth 820
489
-
490
-
492
+
493
+
491
494
expect ( uiGridExporterService . calculatePdfHeaderWidths ( grid , headers ) ) . toEqual (
492
495
[ 60 , '*' , 75 , 100 , 75 , 50 ]
493
496
) ;
494
497
} ) ;
495
498
} ) ;
496
-
497
- } ) ;
499
+
500
+ } ) ;
0 commit comments