@@ -8,6 +8,7 @@ import { configureTestSuite } from '../../test-utils/configure-suite';
8
8
import { ColumnPinningPosition , RowPinningPosition } from '../common/enums' ;
9
9
import { IPinningConfig } from '../common/grid.interface' ;
10
10
import { SampleTestData } from '../../test-utils/sample-test-data.spec' ;
11
+ import { verifyLayoutHeadersAreAligned , verifyDOMMatchesLayoutSettings } from '../../test-utils/helper-utils.spec' ;
11
12
12
13
describe ( 'Row Pinning #grid' , ( ) => {
13
14
const FIXED_ROW_CONTAINER = '.igx-grid__tr--pinned ' ;
@@ -18,7 +19,8 @@ describe('Row Pinning #grid', () => {
18
19
beforeAll ( async ( ( ) => {
19
20
TestBed . configureTestingModule ( {
20
21
declarations : [
21
- GridRowPinningComponent
22
+ GridRowPinningComponent ,
23
+ GridRowPinningWithMRLComponent
22
24
] ,
23
25
imports : [
24
26
NoopAnimationsModule ,
@@ -217,6 +219,92 @@ describe('Row Pinning #grid', () => {
217
219
expect ( grid . getRowByIndex ( 1 ) . rowID ) . toBe ( fix . componentInstance . data [ 1 ] ) ;
218
220
} ) ;
219
221
} ) ;
222
+ describe ( 'Row pinning with MRL' , ( ) => {
223
+ beforeEach ( fakeAsync ( ( ) => {
224
+ fix = TestBed . createComponent ( GridRowPinningWithMRLComponent ) ;
225
+ fix . detectChanges ( ) ;
226
+ grid = fix . componentInstance . instance ;
227
+ tick ( ) ;
228
+ fix . detectChanges ( ) ;
229
+ } ) ) ;
230
+
231
+ it ( 'should pin/unpin correctly to top' , ( ) => {
232
+ // pin
233
+ grid . pinRow ( fix . componentInstance . data [ 1 ] ) ;
234
+ fix . detectChanges ( ) ;
235
+
236
+ expect ( grid . pinnedRecords . length ) . toBe ( 1 ) ;
237
+ const pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
238
+ expect ( pinRowContainer . length ) . toBe ( 1 ) ;
239
+ expect ( pinRowContainer [ 0 ] . children . length ) . toBe ( 1 ) ;
240
+ expect ( pinRowContainer [ 0 ] . children [ 0 ] . context . rowID ) . toBe ( fix . componentInstance . data [ 1 ] ) ;
241
+ expect ( pinRowContainer [ 0 ] . children [ 0 ] . nativeElement ) . toBe ( grid . getRowByIndex ( 0 ) . nativeElement ) ;
242
+
243
+ expect ( grid . getRowByIndex ( 0 ) . pinned ) . toBeTruthy ( ) ;
244
+ const gridPinnedRow = grid . pinnedRows [ 0 ] ;
245
+ const pinnedRowCells = gridPinnedRow . cells . toArray ( ) ;
246
+ const headerCells = grid . headerGroups . first . children . toArray ( ) ;
247
+
248
+ // headers are aligned to cells
249
+ verifyLayoutHeadersAreAligned ( headerCells , pinnedRowCells ) ;
250
+ verifyDOMMatchesLayoutSettings ( gridPinnedRow , fix . componentInstance . colGroups ) ;
251
+
252
+ // unpin
253
+ const row = grid . pinnedRows [ 0 ] ;
254
+ row . pinned = false ;
255
+ fix . detectChanges ( ) ;
256
+
257
+ expect ( grid . pinnedRecords . length ) . toBe ( 0 ) ;
258
+ expect ( row . pinned ) . toBeFalsy ( ) ;
259
+
260
+ const gridUnpinnedRow = grid . getRowByIndex ( 1 ) ;
261
+ const unpinnedRowCells = gridUnpinnedRow . cells . toArray ( ) ;
262
+
263
+ verifyLayoutHeadersAreAligned ( headerCells , unpinnedRowCells ) ;
264
+ verifyDOMMatchesLayoutSettings ( gridUnpinnedRow , fix . componentInstance . colGroups ) ;
265
+ } ) ;
266
+
267
+ it ( 'should pin/unpin correctly to bottom' , ( ) => {
268
+
269
+ fix . componentInstance . pinningConfig = { columns : ColumnPinningPosition . Start , rows : RowPinningPosition . Bottom } ;
270
+ fix . detectChanges ( ) ;
271
+
272
+ // pin
273
+ grid . pinRow ( fix . componentInstance . data [ 1 ] ) ;
274
+ fix . detectChanges ( ) ;
275
+
276
+ expect ( grid . pinnedRecords . length ) . toBe ( 1 ) ;
277
+ const pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
278
+ expect ( pinRowContainer . length ) . toBe ( 1 ) ;
279
+ expect ( pinRowContainer [ 0 ] . children . length ) . toBe ( 1 ) ;
280
+ expect ( pinRowContainer [ 0 ] . children [ 0 ] . context . rowID ) . toBe ( fix . componentInstance . data [ 1 ] ) ;
281
+ expect ( pinRowContainer [ 0 ] . children [ 0 ] . nativeElement )
282
+ . toBe ( grid . getRowByIndex ( fix . componentInstance . data . length - 1 ) . nativeElement ) ;
283
+
284
+ expect ( grid . getRowByIndex ( fix . componentInstance . data . length - 1 ) . pinned ) . toBeTruthy ( ) ;
285
+ const gridPinnedRow = grid . pinnedRows [ 0 ] ;
286
+ const pinnedRowCells = gridPinnedRow . cells . toArray ( ) ;
287
+ const headerCells = grid . headerGroups . first . children . toArray ( ) ;
288
+
289
+ // headers are aligned to cells
290
+ verifyLayoutHeadersAreAligned ( headerCells , pinnedRowCells ) ;
291
+ verifyDOMMatchesLayoutSettings ( gridPinnedRow , fix . componentInstance . colGroups ) ;
292
+
293
+ // unpin
294
+ const row = grid . pinnedRows [ 0 ] ;
295
+ row . pinned = false ;
296
+ fix . detectChanges ( ) ;
297
+
298
+ expect ( grid . pinnedRecords . length ) . toBe ( 0 ) ;
299
+ expect ( row . pinned ) . toBeFalsy ( ) ;
300
+
301
+ const gridUnpinnedRow = grid . getRowByIndex ( 1 ) ;
302
+ const unpinnedRowCells = gridUnpinnedRow . cells . toArray ( ) ;
303
+
304
+ verifyLayoutHeadersAreAligned ( headerCells , unpinnedRowCells ) ;
305
+ verifyDOMMatchesLayoutSettings ( gridUnpinnedRow , fix . componentInstance . colGroups ) ;
306
+ } ) ;
307
+ } ) ;
220
308
} ) ;
221
309
222
310
@Component ( {
@@ -237,3 +325,36 @@ export class GridRowPinningComponent {
237
325
@ViewChild ( IgxGridComponent , { read : IgxGridComponent , static : true } )
238
326
public instance : IgxGridComponent ;
239
327
}
328
+
329
+ @Component ( {
330
+ template : `
331
+ <igx-grid [data]="data" height="500px" [pinning]='pinningConfig'>
332
+ <igx-column-group header="General Information">
333
+ <igx-column field="CompanyName"></igx-column>
334
+ <igx-column-group [movable]="true" header="Person Details">
335
+ <igx-column field="ContactName"></igx-column>
336
+ <igx-column field="ContactTitle"></igx-column>
337
+ </igx-column-group>
338
+ </igx-column-group>
339
+ <igx-column-layout *ngFor='let group of colGroups'>
340
+ <igx-column *ngFor='let col of group.columns'
341
+ [rowStart]="col.rowStart" [colStart]="col.colStart" [width]='col.width'
342
+ [colEnd]="col.colEnd" [rowEnd]="col.rowEnd" [field]='col.field'></igx-column>
343
+ </igx-column-layout>
344
+ </igx-grid>
345
+ `
346
+ } )
347
+ export class GridRowPinningWithMRLComponent extends GridRowPinningComponent {
348
+ cols : Array < any > = [
349
+ { field : 'ID' , rowStart : 1 , colStart : 1 } ,
350
+ { field : 'CompanyName' , rowStart : 1 , colStart : 2 } ,
351
+ { field : 'ContactName' , rowStart : 1 , colStart : 3 } ,
352
+ { field : 'ContactTitle' , rowStart : 2 , colStart : 1 , rowEnd : 4 , colEnd : 4 } ,
353
+ ] ;
354
+ colGroups = [
355
+ {
356
+ group : 'group1' ,
357
+ columns : this . cols
358
+ }
359
+ ] ;
360
+ }
0 commit comments