@@ -2,7 +2,8 @@ import { fakeAsync, TestBed } from '@angular/core/testing';
22import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
33import { IgxPivotGridModule } from 'igniteui-angular' ;
44import { configureTestSuite } from '../../test-utils/configure-suite' ;
5- import { IgxPivotGridTestBaseComponent } from '../../test-utils/pivot-grid-samples.spec' ;
5+ import { GridFunctions , GridSelectionFunctions } from '../../test-utils/grid-functions.spec' ;
6+ import { IgxPivotGridTestBaseComponent , IgxPivotGridTestComplexHierarchyComponent } from '../../test-utils/pivot-grid-samples.spec' ;
67
78describe ( 'Basic IgxPivotGrid #pivotGrid' , ( ) => {
89 let fixture ;
@@ -38,3 +39,120 @@ describe('Basic IgxPivotGrid #pivotGrid', () => {
3839 expect ( cells . last . nativeElement . classList ) . not . toContain ( 'test' ) ;
3940 } ) ;
4041} ) ;
42+
43+ describe ( 'IgxPivotGrid complex hierarchy #pivotGrid' , ( ) => {
44+ let fixture ;
45+ configureTestSuite ( ( ( ) => {
46+ TestBed . configureTestingModule ( {
47+ declarations : [
48+ IgxPivotGridTestComplexHierarchyComponent
49+ ] ,
50+ imports : [
51+ NoopAnimationsModule , IgxPivotGridModule ]
52+ } ) ;
53+ } ) ) ;
54+
55+ beforeEach ( fakeAsync ( ( ) => {
56+ fixture = TestBed . createComponent ( IgxPivotGridTestComplexHierarchyComponent ) ;
57+ fixture . detectChanges ( ) ;
58+ } ) ) ;
59+
60+ it ( 'should select/deselect the correct row' , ( ) => {
61+ fixture . detectChanges ( ) ;
62+ const pivotGrid = fixture . componentInstance . pivotGrid ;
63+ const pivotRows = GridFunctions . getPivotRows ( fixture ) ;
64+ const row = pivotRows [ 2 ] . componentInstance ;
65+ row . selectPivotRow ( row . rowDimensionData [ 1 ] . column ) ;
66+ fixture . detectChanges ( ) ;
67+ expect ( row . selected ) . toBeTrue ( ) ;
68+ expect ( pivotGrid . selectedRows ) . not . toBeNull ( ) ;
69+ expect ( pivotGrid . selectedRows . length ) . toBe ( 1 ) ;
70+ const expected =
71+ {
72+ 'All cities' : 'All Cities' , 'All cities_level' : 0 ,
73+ ProductCategory : 'Bikes' , ProductCategory_level : 1 ,
74+ 'Uruguay-AmountOfSale' : 242.08 , 'Uruguay-UnitsSold' : 68
75+ } ;
76+ expect ( pivotGrid . selectedRows [ 0 ] ) . toEqual ( expected ) ;
77+
78+ //deselect
79+ row . selectPivotRow ( row . rowDimensionData [ 1 ] . column ) ;
80+ fixture . detectChanges ( ) ;
81+ expect ( row . selected ) . toBeFalse ( ) ;
82+ expect ( pivotGrid . selectedRows . length ) . toBe ( 0 ) ;
83+ } ) ;
84+
85+ it ( 'should select/deselect the correct group of rows' , ( ) => {
86+ fixture . detectChanges ( ) ;
87+ const pivotGrid = fixture . componentInstance . pivotGrid ;
88+ const pivotRows = GridFunctions . getPivotRows ( fixture ) ;
89+ const row = pivotRows [ 2 ] . componentInstance ;
90+ row . selectPivotRow ( row . rowDimensionData [ 0 ] . column ) ;
91+ fixture . detectChanges ( ) ;
92+ for ( let i = 0 ; i < 5 ; ++ i ) {
93+ expect ( pivotRows [ i ] . componentInstance . selected ) . toBeTrue ( ) ;
94+ }
95+ expect ( pivotGrid . selectedRows ) . not . toBeNull ( ) ;
96+ expect ( pivotGrid . selectedRows . length ) . toBe ( 5 ) ;
97+ const expected =
98+ [
99+ {
100+ AllProducts : 'AllProducts' , 'All cities' : 'All Cities' ,
101+ 'All cities_level' : 0 , AllProducts_level : 0 , 'Bulgaria-UnitsSold' : 774 ,
102+ 'Bulgaria-AmountOfSale' : 11509.02 , 'USA-UnitsSold' : 829 , 'USA-AmountOfSale' : 44098.85999999999 ,
103+ 'Uruguay-UnitsSold' : 524 , 'Uruguay-AmountOfSale' : 31400.56
104+ } , {
105+ ProductCategory : 'Clothing' , 'All cities' : 'All Cities' ,
106+ ProductCategory_level : 1 , 'All cities_level' : 0 , 'Bulgaria-UnitsSold' : 774 ,
107+ 'Bulgaria-AmountOfSale' : 11509.02 , 'USA-UnitsSold' : 296 , 'USA-AmountOfSale' : 14672.72 ,
108+ 'Uruguay-UnitsSold' : 456 , 'Uruguay-AmountOfSale' : 31158.48
109+ } , {
110+ ProductCategory : 'Bikes' , 'All cities' : 'All Cities' ,
111+ ProductCategory_level : 1 , 'All cities_level' : 0 ,
112+ 'Uruguay-UnitsSold' : 68 , 'Uruguay-AmountOfSale' : 242.08
113+ } , {
114+ ProductCategory : 'Accessories' , 'All cities' : 'All Cities' ,
115+ ProductCategory_level : 1 , 'All cities_level' : 0 ,
116+ 'USA-UnitsSold' : 293 , 'USA-AmountOfSale' : 25074.94
117+ } , {
118+ ProductCategory : 'Components' , 'All cities' : 'All Cities' ,
119+ ProductCategory_level : 1 , 'All cities_level' : 0 ,
120+ 'USA-UnitsSold' : 240 , 'USA-AmountOfSale' : 4351.2
121+ }
122+ ] ;
123+ expect ( pivotGrid . selectedRows ) . toEqual ( expected ) ;
124+ } ) ;
125+
126+ it ( 'should select/deselect the correct column' , ( ) => {
127+ fixture . detectChanges ( ) ;
128+ const pivotGrid = fixture . componentInstance . pivotGrid ;
129+ const unitsSold = pivotGrid . getColumnByName ( 'Bulgaria-UnitsSold' ) ;
130+ GridFunctions . clickColumnHeaderUI ( 'Bulgaria-UnitsSold' , fixture ) ;
131+ GridSelectionFunctions . verifyColumnAndCellsSelected ( unitsSold ) ;
132+ } ) ;
133+
134+ it ( 'should select/deselect the correct column group' , ( ) => {
135+ fixture . detectChanges ( ) ;
136+ const pivotGrid = fixture . componentInstance . pivotGrid ;
137+ const group = GridFunctions . getColGroup ( pivotGrid , 'Bulgaria' ) ;
138+ const unitsSold = pivotGrid . getColumnByName ( 'Bulgaria-UnitsSold' ) ;
139+ const amountOfSale = pivotGrid . getColumnByName ( 'Bulgaria-AmountOfSale' ) ;
140+ const unitsSoldUSA = pivotGrid . getColumnByName ( 'USA-UnitsSold' ) ;
141+ const amountOfSaleUSA = pivotGrid . getColumnByName ( 'USA-AmountOfSale' ) ;
142+
143+ GridFunctions . clickColumnGroupHeaderUI ( 'Bulgaria' , fixture ) ;
144+ fixture . detectChanges ( ) ;
145+
146+ GridSelectionFunctions . verifyColumnSelected ( unitsSold ) ;
147+ GridSelectionFunctions . verifyColumnSelected ( amountOfSale ) ;
148+ GridSelectionFunctions . verifyColumnGroupSelected ( fixture , group ) ;
149+
150+ GridSelectionFunctions . verifyColumnsSelected ( [ unitsSoldUSA , amountOfSaleUSA ] , false ) ;
151+
152+ GridFunctions . clickColumnGroupHeaderUI ( 'Bulgaria' , fixture ) ;
153+
154+ GridSelectionFunctions . verifyColumnSelected ( unitsSold , false ) ;
155+ GridSelectionFunctions . verifyColumnSelected ( amountOfSale , false ) ;
156+ GridSelectionFunctions . verifyColumnGroupSelected ( fixture , group , false ) ;
157+ } ) ;
158+ } ) ;
0 commit comments