@@ -464,21 +464,24 @@ describe('Basic IgxHierarchicalGrid #hGrid', () => {
464
464
UIInteractions . simulateClickAndSelectEvent ( row . expander ) ;
465
465
fixture . detectChanges ( ) ;
466
466
467
- let childGrids = fixture . debugElement . queryAll ( By . css ( 'igx-child-grid-row' ) ) ;
468
- let childGrid = childGrids [ 0 ] . query ( By . css ( 'igx-hierarchical-grid' ) ) . componentInstance ;
467
+ // check by adding multiple rows
468
+ for ( let i = 0 ; i < 3 ; i ++ ) {
469
+ let childGrids = fixture . debugElement . queryAll ( By . css ( 'igx-child-grid-row' ) ) ;
470
+ let childGrid = childGrids [ 0 ] . query ( By . css ( 'igx-hierarchical-grid' ) ) . componentInstance ;
469
471
470
- fixture . componentInstance . data [ 0 ] . childData = [ ...hierarchicalGrid . data [ 0 ] . childData ?? [ ] , { ID : 10 , ProductName : 'New child' } ] ;
471
- fixture . componentInstance . data = [ ...fixture . componentInstance . data ] ;
472
- fixture . detectChanges ( ) ;
472
+ fixture . componentInstance . data [ 0 ] . childData = [ ...hierarchicalGrid . data [ 0 ] . childData ?? [ ] , { ID : i * 10 , ProductName : 'New child' + i . toString ( ) } ] ;
473
+ fixture . componentInstance . data = [ ...fixture . componentInstance . data ] ;
474
+ fixture . detectChanges ( ) ;
473
475
474
- childGrids = fixture . debugElement . queryAll ( By . css ( 'igx-child-grid-row' ) ) ;
475
- childGrid = childGrids [ 0 ] . query ( By . css ( 'igx-hierarchical-grid' ) ) . componentInstance ;
476
+ childGrids = fixture . debugElement . queryAll ( By . css ( 'igx-child-grid-row' ) ) ;
477
+ childGrid = childGrids [ 0 ] . query ( By . css ( 'igx-hierarchical-grid' ) ) . componentInstance ;
476
478
477
- const length = fixture . componentInstance . data [ 0 ] . childData . length ;
478
- const newRow = childGrid . gridAPI . get_row_by_index ( length - 1 ) as IgxHierarchicalRowComponent ;
479
+ const length = fixture . componentInstance . data [ 0 ] . childData . length ;
480
+ const newRow = childGrid . gridAPI . get_row_by_index ( length - 1 ) as IgxHierarchicalRowComponent ;
479
481
480
- expect ( newRow ) . not . toBeUndefined ( ) ;
481
- expect ( childGrid . data ) . toBe ( fixture . componentInstance . data [ 0 ] . childData ) ;
482
+ expect ( newRow ) . not . toBeUndefined ( ) ;
483
+ expect ( childGrid . data ) . toBe ( fixture . componentInstance . data [ 0 ] . childData ) ;
484
+ }
482
485
} ) ;
483
486
484
487
it ( 'when child width is in percents its width should be update if parent width changes while parent row is collapsed. ' , async ( ) => {
@@ -1182,6 +1185,32 @@ describe('Basic IgxHierarchicalGrid #hGrid', () => {
1182
1185
expect ( iconTxt ) . toBe ( 'unfold_less' ) ;
1183
1186
expect ( icon . getActive ) . toBe ( false ) ;
1184
1187
} ) ;
1188
+
1189
+ it ( 'should keep already expanded child grids\' data when expanding subsequent ones' , fakeAsync ( ( ) => {
1190
+ const hierarchicalGrid = fixture . componentInstance . instance ;
1191
+
1192
+ fixture . componentInstance . databind ( ) ;
1193
+ fixture . detectChanges ( ) ;
1194
+
1195
+ const row0 = hierarchicalGrid . gridAPI . get_row_by_index ( 0 ) as IgxHierarchicalRowComponent ;
1196
+ UIInteractions . simulateClickAndSelectEvent ( row0 . expander ) ;
1197
+ fixture . detectChanges ( ) ;
1198
+ tick ( ) ;
1199
+
1200
+ let childGrids = hierarchicalGrid . gridAPI . getChildGrids ( ) ;
1201
+ expect ( childGrids . length ) . toBe ( 1 ) ;
1202
+ expect ( childGrids [ 0 ] . data . length ) . toBeGreaterThan ( 0 ) ;
1203
+
1204
+ const row1 = hierarchicalGrid . gridAPI . get_row_by_index ( 2 ) as IgxHierarchicalRowComponent ;
1205
+ UIInteractions . simulateClickAndSelectEvent ( row1 . expander ) ;
1206
+ fixture . detectChanges ( ) ;
1207
+ tick ( ) ;
1208
+
1209
+ childGrids = hierarchicalGrid . gridAPI . getChildGrids ( ) ;
1210
+ expect ( childGrids . length ) . toBe ( 2 ) ;
1211
+ expect ( childGrids [ 0 ] . data . length ) . toBeGreaterThan ( 0 ) ;
1212
+ expect ( childGrids [ 1 ] . data . length ) . toBeGreaterThan ( 0 ) ;
1213
+ } ) ) ;
1185
1214
} ) ;
1186
1215
1187
1216
describe ( 'IgxHierarchicalGrid Template Changing Scenarios #hGrid' , ( ) => {
0 commit comments