1
1
import { TestBed , waitForAsync } from '@angular/core/testing' ;
2
- import { Component , ViewChild } from '@angular/core' ;
3
2
import { IgxGridModule } from '../../grids/grid/public_api' ;
4
3
import { IgxGridComponent } from '../../grids/grid/grid.component' ;
5
4
import { IColumnExportingEventArgs , IRowExportingEventArgs } from '../exporter-common/base-export-service' ;
@@ -15,7 +14,9 @@ import {
15
14
ProductsComponent ,
16
15
GridIDNameJobTitleHireDataPerformanceComponent ,
17
16
GridHireDateComponent ,
18
- GridExportGroupedDataComponent
17
+ GridExportGroupedDataComponent ,
18
+ MultiColumnHeadersExportComponent ,
19
+ GridWithEmptyColumnsComponent
19
20
} from '../../test-utils/grid-samples.spec' ;
20
21
import { SampleTestData } from '../../test-utils/sample-test-data.spec' ;
21
22
import { first } from 'rxjs/operators' ;
@@ -30,11 +31,14 @@ import { UIInteractions, wait } from '../../test-utils/ui-interactions.spec';
30
31
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
31
32
import { FilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree' ;
32
33
import { FilteringLogic } from '../../data-operations/filtering-expression.interface' ;
33
- import { IgxHierarchicalGridExportComponent } from '../../test-utils/hierarchical-grid-components.spec' ;
34
+ import { IgxHierarchicalGridExportComponent ,
35
+ IgxHierarchicalGridMultiColumnHeadersExportComponent
36
+ } from '../../test-utils/hierarchical-grid-components.spec' ;
34
37
import { IgxHierarchicalGridModule ,
35
38
IgxHierarchicalGridComponent ,
36
39
} from '../../grids/hierarchical-grid/public_api' ;
37
40
import { IgxHierarchicalRowComponent } from '../../grids/hierarchical-grid/hierarchical-row.component' ;
41
+ import { GridFunctions } from '../../test-utils/grid-functions.spec' ;
38
42
39
43
describe ( 'Excel Exporter' , ( ) => {
40
44
configureTestSuite ( ) ;
@@ -53,7 +57,9 @@ describe('Excel Exporter', () => {
53
57
GridIDNameJobTitleHireDataPerformanceComponent ,
54
58
GridHireDateComponent ,
55
59
GridExportGroupedDataComponent ,
56
- IgxHierarchicalGridExportComponent
60
+ IgxHierarchicalGridExportComponent ,
61
+ MultiColumnHeadersExportComponent ,
62
+ IgxHierarchicalGridMultiColumnHeadersExportComponent
57
63
] ,
58
64
imports : [ IgxGridModule , IgxTreeGridModule , IgxHierarchicalGridModule , NoopAnimationsModule ]
59
65
} ) . compileComponents ( ) ;
@@ -689,8 +695,7 @@ describe('Excel Exporter', () => {
689
695
690
696
describe ( '' , ( ) => {
691
697
let fix ;
692
- let hGrid : IgxHierarchicalGridComponent ;
693
-
698
+ let hGrid ;
694
699
beforeEach ( waitForAsync ( ( ) => {
695
700
options = createExportOptions ( 'HierarchicalGridExcelExport' ) ;
696
701
fix = TestBed . createComponent ( IgxHierarchicalGridExportComponent ) ;
@@ -705,12 +710,12 @@ describe('Excel Exporter', () => {
705
710
706
711
it ( 'should export hierarchical grid respecting options width.' , async ( ) => {
707
712
options = createExportOptions ( 'HierarchicalGridExcelExport' , 50 ) ;
713
+
708
714
await exportAndVerify ( hGrid , options , actualData . exportHierarchicalDataWithColumnWidth ) ;
709
715
} ) ;
710
716
711
717
it ( 'should export sorted hierarchical grid data' , async ( ) => {
712
718
hGrid . sort ( { fieldName : 'GrammyNominations' , dir : SortingDirection . Desc } ) ;
713
-
714
719
fix . detectChanges ( ) ;
715
720
716
721
await exportAndVerify ( hGrid , options , actualData . exportSortedHierarchicalData ) ;
@@ -782,6 +787,17 @@ describe('Excel Exporter', () => {
782
787
} ) ;
783
788
} ) ;
784
789
790
+ describe ( '' , ( ) => {
791
+ it ( 'should export hierarchical grid with multi column headers' , async ( ) => {
792
+ const fix = TestBed . createComponent ( IgxHierarchicalGridMultiColumnHeadersExportComponent ) ;
793
+ fix . detectChanges ( ) ;
794
+
795
+ const hGrid = fix . componentInstance . hGrid ;
796
+ options = createExportOptions ( 'HierarchicalGridMCHExcelExport' ) ;
797
+ await exportAndVerify ( hGrid , options , actualData . exportHierarchicalDataWithMultiColumnHeaders ) ;
798
+ } ) ;
799
+ } ) ;
800
+
785
801
describe ( '' , ( ) => {
786
802
let fix ;
787
803
let treeGrid : IgxTreeGridComponent ;
@@ -911,7 +927,7 @@ describe('Excel Exporter', () => {
911
927
expect ( error ) . toMatch ( 'Can create an outline of up to eight levels!' ) ;
912
928
} ) ;
913
929
914
- it ( 'should skip the formatter when columnExproting skipFormatter is true' , async ( ) => {
930
+ it ( 'should skip the formatter when columnExporting skipFormatter is true' , async ( ) => {
915
931
treeGrid . columns [ 4 ] . formatter = ( ( val : number ) => {
916
932
const t = Math . floor ( val / 10 ) ;
917
933
const o = val % 10 ;
@@ -958,6 +974,66 @@ describe('Excel Exporter', () => {
958
974
} ) ;
959
975
} ) ;
960
976
977
+ describe ( '' , ( ) => {
978
+ let fix ;
979
+ let grid : IgxGridComponent ;
980
+
981
+ beforeEach ( waitForAsync ( ( ) => {
982
+ options = createExportOptions ( 'MultiColumnHeaderGridExcelExport' ) ;
983
+ fix = TestBed . createComponent ( MultiColumnHeadersExportComponent ) ;
984
+ fix . detectChanges ( ) ;
985
+
986
+ grid = fix . componentInstance . grid ;
987
+ } ) ) ;
988
+
989
+ it ( 'should export grid with multi column headers' , async ( ) => {
990
+ await exportAndVerify ( grid , options , actualData . exportMultiColumnHeadersData , false ) ;
991
+ } ) ;
992
+
993
+ it ( 'should export grid with multi column headers and moved column' , async ( ) => {
994
+ grid . columns [ 0 ] . move ( 2 ) ;
995
+ fix . detectChanges ( ) ;
996
+
997
+ await exportAndVerify ( grid , options , actualData . exportMultiColumnHeadersDataWithMovedColumn , false ) ;
998
+ } ) ;
999
+
1000
+ it ( 'should export grid with hidden column' , async ( ) => {
1001
+ grid . columns [ 0 ] . hidden = true ;
1002
+ fix . detectChanges ( ) ;
1003
+
1004
+ await exportAndVerify ( grid , options , actualData . exportMultiColumnHeadersDataWithHiddenColumn , false ) ;
1005
+ } ) ;
1006
+
1007
+ it ( 'should export grid with hidden column and ignoreColumnVisibility set to true' , async ( ) => {
1008
+ grid . columns [ 0 ] . hidden = true ;
1009
+ options . ignoreColumnsVisibility = true ;
1010
+ fix . detectChanges ( ) ;
1011
+
1012
+ await exportAndVerify ( grid , options , actualData . exportMultiColumnHeadersDataWithIgnoreColumnVisibility , false ) ;
1013
+ } ) ;
1014
+
1015
+ it ( 'should export grid with pinned column group' , async ( ) => {
1016
+ grid . columns [ 1 ] . pinned = true ;
1017
+ fix . detectChanges ( ) ;
1018
+
1019
+ await exportAndVerify ( grid , options , actualData . exportMultiColumnHeadersDataWithPinnedColumn , false ) ;
1020
+ } ) ;
1021
+
1022
+ it ( 'should export grid with collapsed and expanded multi column headers' , async ( ) => {
1023
+ GridFunctions . clickGroupExpandIndicator ( fix , grid . columns [ 1 ] ) ;
1024
+ GridFunctions . clickGroupExpandIndicator ( fix , grid . columns [ 7 ] ) ;
1025
+ fix . detectChanges ( ) ;
1026
+ await exportAndVerify ( grid , options , actualData . exportCollapsedAndExpandedMultiColumnHeadersData , false ) ;
1027
+ } ) ;
1028
+
1029
+ it ( 'should respect ignoreMultiColumnHeaders when set to true' , async ( ) => {
1030
+ options . ignoreMultiColumnHeaders = true ;
1031
+ fix . detectChanges ( ) ;
1032
+
1033
+ await exportAndVerify ( grid , options , actualData . exportMultiColumnHeadersDataWithoutMultiColumnHeaders ) ;
1034
+ } ) ;
1035
+ } ) ;
1036
+
961
1037
const getExportedData = ( grid , exportOptions : IgxExcelExporterOptions ) => {
962
1038
const exportData = new Promise < JSZipWrapper > ( ( resolve ) => {
963
1039
exporter . exportEnded . pipe ( first ( ) ) . subscribe ( ( value ) => {
@@ -1004,31 +1080,12 @@ describe('Excel Exporter', () => {
1004
1080
return opts ;
1005
1081
} ;
1006
1082
1007
- const exportAndVerify = async ( component , exportOptions , expectedData ) => {
1083
+ const exportAndVerify = async ( component , exportOptions , expectedData , exportTable : boolean = true ) => {
1008
1084
const isHGrid = component instanceof IgxHierarchicalGridComponent ;
1085
+ const shouldNotExportTable = isHGrid || ! exportTable ;
1086
+
1009
1087
const wrapper = await getExportedData ( component , exportOptions ) ;
1010
- await wrapper . verifyStructure ( isHGrid ) ;
1011
- await wrapper . verifyDataFilesContent ( expectedData , '' , isHGrid ) ;
1088
+ await wrapper . verifyStructure ( shouldNotExportTable ) ;
1089
+ await wrapper . verifyDataFilesContent ( expectedData , '' , shouldNotExportTable ) ;
1012
1090
} ;
1013
1091
} ) ;
1014
-
1015
- @Component ( {
1016
- template : `
1017
- <igx-grid #grid1 [data]="data">
1018
- <igx-column>
1019
- <ng-template igxCell>
1020
- <button>SimpleBtn</button>
1021
- </ng-template>
1022
- </igx-column>
1023
- <igx-column header="" field="ID"></igx-column>
1024
- <igx-column header=" " field=""></igx-column>
1025
- <igx-column header="Name" field="Name"></igx-column>
1026
- <igx-column header="JobTitle" field="JobTitle"></igx-column>
1027
- </igx-grid>`
1028
- } )
1029
-
1030
- export class GridWithEmptyColumnsComponent {
1031
- @ViewChild ( 'grid1' , { static : true } ) public grid : IgxGridComponent ;
1032
-
1033
- public data = SampleTestData . personJobDataFull ( ) ;
1034
- }
0 commit comments