1- import { DebugElement , ViewChild , Component } from '@angular/core' ;
1+ import { ViewChild , Component } from '@angular/core' ;
22import { TestBed , async , fakeAsync , tick } from '@angular/core/testing' ;
33import { By } from '@angular/platform-browser' ;
44import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
@@ -364,7 +364,7 @@ describe('Row Pinning #grid', () => {
364364 let pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
365365 expect ( pinRowContainer . length ) . toBe ( 1 ) ;
366366
367- let expectedHeight = parseInt ( grid . height , 10 ) - grid . pinnedRowHeight - 18 - grid . theadRow . nativeElement . offsetHeight ;
367+ let expectedHeight = parseInt ( grid . height , 10 ) - grid . pinnedRowHeight - 18 - grid . theadRow . nativeElement . offsetHeight ;
368368 expect ( grid . calcHeight - expectedHeight ) . toBeLessThanOrEqual ( 1 ) ;
369369
370370 grid . filter ( 'ID' , 'B' , IgxStringFilteringOperand . instance ( ) . condition ( 'startsWith' ) , false ) ;
@@ -374,7 +374,7 @@ describe('Row Pinning #grid', () => {
374374 expect ( pinRowContainer . length ) . toBe ( 0 ) ;
375375
376376 expect ( grid . pinnedRowHeight ) . toBe ( 0 ) ;
377- expectedHeight = parseInt ( grid . height , 10 ) - grid . pinnedRowHeight - 18 - grid . theadRow . nativeElement . offsetHeight ;
377+ expectedHeight = parseInt ( grid . height , 10 ) - grid . pinnedRowHeight - 18 - grid . theadRow . nativeElement . offsetHeight ;
378378 expect ( grid . calcHeight - expectedHeight ) . toBeLessThanOrEqual ( 1 ) ;
379379 } ) ;
380380
@@ -401,47 +401,6 @@ describe('Row Pinning #grid', () => {
401401 expect ( gridFilterData [ 1 ] . ID ) . toBe ( 'BERGS' ) ;
402402 } ) ;
403403
404- it ( 'should page through unpinned collection with modified pageSize = pageSize - pinnedRows.lenght.' , ( ) => {
405- // pin 2nd row
406- grid . paging = true ;
407- grid . perPage = 5 ;
408- fix . detectChanges ( ) ;
409- const paginator = fix . debugElement . query ( By . directive ( IgxPaginatorComponent ) ) ;
410- expect ( paginator . componentInstance . totalPages ) . toEqual ( 6 ) ;
411-
412- grid . getRowByIndex ( 1 ) . pin ( ) ;
413- fix . detectChanges ( ) ;
414-
415- expect ( grid . pinnedRows . length ) . toBe ( 1 ) ;
416- let pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
417- expect ( pinRowContainer . length ) . toBe ( 1 ) ;
418- expect ( grid . dataView . length ) . toBe ( 5 ) ;
419- expect ( paginator . componentInstance . totalPages ) . toEqual ( 6 ) ;
420-
421- grid . getRowByIndex ( 3 ) . pin ( ) ;
422- fix . detectChanges ( ) ;
423-
424- expect ( grid . pinnedRows . length ) . toBe ( 2 ) ;
425- pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
426- expect ( pinRowContainer . length ) . toBe ( 1 ) ;
427- expect ( grid . dataView . length ) . toBe ( 5 ) ;
428- expect ( paginator . componentInstance . totalPages ) . toEqual ( 6 ) ;
429-
430- // unpin
431- grid . getRowByIndex ( 0 ) . unpin ( ) ;
432- fix . detectChanges ( ) ;
433-
434- grid . getRowByIndex ( 0 ) . unpin ( ) ;
435- fix . detectChanges ( ) ;
436-
437- expect ( grid . pinnedRows . length ) . toBe ( 0 ) ;
438- pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
439- expect ( pinRowContainer . length ) . toBe ( 0 ) ;
440-
441- expect ( grid . dataView . length ) . toBe ( 5 ) ;
442- expect ( paginator . componentInstance . totalPages ) . toEqual ( 6 ) ;
443- } ) ;
444-
445404 it ( 'should apply sorting to both pinned and unpinned rows.' , ( ) => {
446405 grid . getRowByIndex ( 1 ) . pin ( ) ;
447406 grid . getRowByIndex ( 5 ) . pin ( ) ;
@@ -462,6 +421,7 @@ describe('Row Pinning #grid', () => {
462421 expect ( grid . getRowByIndex ( 2 ) . rowID ) . toBe ( fix . componentInstance . data [ lastIndex ] ) ;
463422 } ) ;
464423 } ) ;
424+
465425 describe ( 'Row pinning with Master Detail View' , ( ) => {
466426 beforeEach ( fakeAsync ( ( ) => {
467427 fix = TestBed . createComponent ( GridRowPinningWithMDVComponent ) ;
@@ -563,6 +523,62 @@ describe('Row Pinning #grid', () => {
563523 } ) ;
564524 } ) ;
565525
526+ describe ( 'Paging' , ( ) => {
527+ let paginator : IgxPaginatorComponent ;
528+
529+ beforeEach ( fakeAsync ( ( ) => {
530+ fix = TestBed . createComponent ( GridRowPinningComponent ) ;
531+ fix . componentInstance . createSimpleData ( 12 ) ;
532+ grid = fix . componentInstance . instance ;
533+ grid . paging = true ;
534+ grid . perPage = 5 ;
535+
536+ fix . detectChanges ( ) ;
537+ tick ( ) ;
538+
539+ paginator = fix . debugElement . query ( By . directive ( IgxPaginatorComponent ) ) . componentInstance ;
540+ } ) ) ;
541+
542+ it ( 'should correctly apply paging state for grid and paginator when there are pinned rows.' , ( ) => {
543+ // pin the first row
544+ grid . getRowByIndex ( 0 ) . pin ( ) ;
545+ fix . detectChanges ( ) ;
546+
547+ expect ( grid . rowList . length ) . toEqual ( 6 ) ;
548+ expect ( grid . perPage ) . toEqual ( 5 ) ;
549+ expect ( paginator . perPage ) . toEqual ( 5 ) ;
550+ expect ( paginator . totalRecords ) . toEqual ( 12 ) ;
551+ expect ( paginator . totalPages ) . toEqual ( 3 ) ;
552+
553+ // pin the second row
554+ grid . getRowByIndex ( 2 ) . pin ( ) ;
555+ fix . detectChanges ( ) ;
556+
557+ expect ( grid . rowList . length ) . toEqual ( 7 ) ;
558+ expect ( grid . perPage ) . toEqual ( 5 ) ;
559+ expect ( paginator . perPage ) . toEqual ( 5 ) ;
560+ expect ( paginator . totalRecords ) . toEqual ( 12 ) ;
561+ expect ( paginator . totalPages ) . toEqual ( 3 ) ;
562+ } ) ;
563+
564+ it ( 'should have the correct records shown for pages with pinned rows' , ( ) => {
565+ grid . getRowByIndex ( 0 ) . pin ( ) ;
566+ grid . getRowByIndex ( 1 ) . pin ( ) ;
567+ fix . detectChanges ( ) ;
568+
569+ let rows = grid . rowList . toArray ( ) ;
570+
571+ [ 1 , 2 , 1 , 2 , 3 , 4 , 5 ] . forEach ( ( x , index ) => expect ( rows [ index ] . cells . first . value ) . toEqual ( x ) ) ;
572+
573+ grid . paginate ( 2 ) ;
574+ fix . detectChanges ( ) ;
575+
576+ rows = grid . rowList . toArray ( ) ;
577+
578+ [ 1 , 2 , 11 , 12 ] . forEach ( ( x , index ) => expect ( rows [ index ] . cells . first . value ) . toEqual ( x ) ) ;
579+ } ) ;
580+ } ) ;
581+
566582 describe ( ' Editing ' , ( ) => {
567583 beforeEach ( fakeAsync ( ( ) => {
568584 fix = TestBed . createComponent ( GridRowPinningWithTransactionsComponent ) ;
@@ -641,6 +657,7 @@ describe('Row Pinning #grid', () => {
641657 } ) ;
642658
643659 } ) ;
660+
644661 describe ( 'Row pinning with MRL' , ( ) => {
645662 beforeEach ( fakeAsync ( ( ) => {
646663 fix = TestBed . createComponent ( GridRowPinningWithMRLComponent ) ;
@@ -727,6 +744,7 @@ describe('Row Pinning #grid', () => {
727744 GridFunctions . verifyDOMMatchesLayoutSettings ( gridUnpinnedRow , fix . componentInstance . colGroups ) ;
728745 } ) ;
729746 } ) ;
747+
730748 describe ( ' Hiding' , ( ) => {
731749 beforeEach ( fakeAsync ( ( ) => {
732750 fix = TestBed . createComponent ( GridRowPinningComponent ) ;
@@ -788,11 +806,15 @@ describe('Row Pinning #grid', () => {
788806 `
789807} )
790808export class GridRowPinningComponent {
791- public data = SampleTestData . contactInfoDataFull ( ) ;
809+ public data : any [ ] = SampleTestData . contactInfoDataFull ( ) ;
792810 public pinningConfig : IPinningConfig = { columns : ColumnPinningPosition . Start , rows : RowPinningPosition . Top } ;
793811
794812 @ViewChild ( IgxGridComponent , { read : IgxGridComponent , static : true } )
795813 public instance : IgxGridComponent ;
814+
815+ public createSimpleData ( count : number ) {
816+ this . data = Array ( count ) . fill ( { } ) . map ( ( x , idx ) => x = { 'idx' : idx + 1 } ) ;
817+ }
796818}
797819
798820@Component ( {
@@ -838,7 +860,7 @@ export class GridRowPinningWithMRLComponent extends GridRowPinningComponent {
838860 </ng-template>
839861</igx-grid>`
840862} )
841- export class GridRowPinningWithMDVComponent extends GridRowPinningComponent { }
863+ export class GridRowPinningWithMDVComponent extends GridRowPinningComponent { }
842864
843865
844866@Component ( {
@@ -854,4 +876,4 @@ export class GridRowPinningWithMDVComponent extends GridRowPinningComponent {}
854876 ` ,
855877 providers : [ { provide : IgxGridTransaction , useClass : IgxTransactionService } ]
856878} )
857- export class GridRowPinningWithTransactionsComponent extends GridRowPinningComponent { }
879+ export class GridRowPinningWithTransactionsComponent extends GridRowPinningComponent { }
0 commit comments