@@ -5,6 +5,7 @@ import {Grid} from './grid';
55import { GridRow } from './grid-row' ;
66import { GridCell } from './grid-cell' ;
77import { GridCellWidget } from './grid-cell-widget' ;
8+ import { GRID_ROW , GRID_CELL } from './grid-tokens' ;
89import { waitForMicrotasks } from '../private/testing/test-helpers' ;
910
1011interface ModifierKeys {
@@ -1174,6 +1175,23 @@ describe('Grid directives', () => {
11741175 expect ( consoleSpy ) . toHaveBeenCalledWith ( 'ngGridRow must contain at least one ngGridCell.' ) ;
11751176 } ) ;
11761177 } ) ;
1178+
1179+ describe ( 'subclassing and custom providers' , ( ) => {
1180+ it ( 'should support subclassing GridRow and GridCell using exported injection tokens' , async ( ) => {
1181+ TestBed . resetTestingModule ( ) ;
1182+ TestBed . configureTestingModule ( {
1183+ imports : [ SubclassGridTestComponent ] ,
1184+ } ) ;
1185+ const subclassFixture = TestBed . createComponent ( SubclassGridTestComponent ) ;
1186+ subclassFixture . detectChanges ( ) ;
1187+ await subclassFixture . whenStable ( ) ;
1188+
1189+ const cells = subclassFixture . debugElement . queryAll ( By . directive ( MyCustomCell ) ) ;
1190+ expect ( cells . length ) . toBe ( 2 ) ;
1191+ expect ( cells [ 0 ] . nativeElement . getAttribute ( 'role' ) ) . toBe ( 'gridcell' ) ;
1192+ expect ( cells [ 1 ] . nativeElement . getAttribute ( 'role' ) ) . toBe ( 'gridcell' ) ;
1193+ } ) ;
1194+ } ) ;
11771195} ) ;
11781196
11791197@Component ( {
@@ -1261,3 +1279,31 @@ class GridTestComponent {
12611279 changeDetection : ChangeDetectionStrategy . Eager ,
12621280} )
12631281class GridRowWithoutCells { }
1282+
1283+ @Component ( {
1284+ selector : 'my-custom-cell' ,
1285+ template : `<ng-content></ng-content>` ,
1286+ providers : [ { provide : GRID_CELL , useExisting : MyCustomCell } ] ,
1287+ } )
1288+ class MyCustomCell extends GridCell { }
1289+
1290+ @Component ( {
1291+ selector : 'my-custom-row' ,
1292+ template : `<ng-content></ng-content>` ,
1293+ providers : [ { provide : GRID_ROW , useExisting : MyCustomRow } ] ,
1294+ } )
1295+ class MyCustomRow extends GridRow { }
1296+
1297+ @Component ( {
1298+ template : `
1299+ <table ngGrid>
1300+ <my-custom-row>
1301+ <my-custom-cell>Cell 1</my-custom-cell>
1302+ <my-custom-cell>Cell 2</my-custom-cell>
1303+ </my-custom-row>
1304+ </table>
1305+ ` ,
1306+ imports : [ Grid , MyCustomRow , MyCustomCell ] ,
1307+ changeDetection : ChangeDetectionStrategy . Eager ,
1308+ } )
1309+ class SubclassGridTestComponent { }
0 commit comments