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' ;
@@ -365,7 +365,7 @@ describe('Row Pinning #grid', () => {
365365 let pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
366366 expect ( pinRowContainer . length ) . toBe ( 1 ) ;
367367
368- let expectedHeight = parseInt ( grid . height , 10 ) - grid . pinnedRowHeight - 18 - grid . theadRow . nativeElement . offsetHeight ;
368+ let expectedHeight = parseInt ( grid . height , 10 ) - grid . pinnedRowHeight - 18 - grid . theadRow . nativeElement . offsetHeight ;
369369 expect ( grid . calcHeight - expectedHeight ) . toBeLessThanOrEqual ( 1 ) ;
370370
371371 grid . filter ( 'ID' , 'B' , IgxStringFilteringOperand . instance ( ) . condition ( 'startsWith' ) , false ) ;
@@ -375,7 +375,7 @@ describe('Row Pinning #grid', () => {
375375 expect ( pinRowContainer . length ) . toBe ( 0 ) ;
376376
377377 expect ( grid . pinnedRowHeight ) . toBe ( 0 ) ;
378- expectedHeight = parseInt ( grid . height , 10 ) - grid . pinnedRowHeight - 18 - grid . theadRow . nativeElement . offsetHeight ;
378+ expectedHeight = parseInt ( grid . height , 10 ) - grid . pinnedRowHeight - 18 - grid . theadRow . nativeElement . offsetHeight ;
379379 expect ( grid . calcHeight - expectedHeight ) . toBeLessThanOrEqual ( 1 ) ;
380380 } ) ;
381381
@@ -402,47 +402,6 @@ describe('Row Pinning #grid', () => {
402402 expect ( gridFilterData [ 1 ] . ID ) . toBe ( 'BERGS' ) ;
403403 } ) ;
404404
405- it ( 'should page through unpinned collection with modified pageSize = pageSize - pinnedRows.lenght.' , ( ) => {
406- // pin 2nd row
407- grid . paging = true ;
408- grid . perPage = 5 ;
409- fix . detectChanges ( ) ;
410- const paginator = fix . debugElement . query ( By . directive ( IgxPaginatorComponent ) ) ;
411- expect ( paginator . componentInstance . totalPages ) . toEqual ( 6 ) ;
412-
413- grid . getRowByIndex ( 1 ) . pin ( ) ;
414- fix . detectChanges ( ) ;
415-
416- expect ( grid . pinnedRows . length ) . toBe ( 1 ) ;
417- let pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
418- expect ( pinRowContainer . length ) . toBe ( 1 ) ;
419- expect ( grid . dataView . length ) . toBe ( 5 ) ;
420- expect ( paginator . componentInstance . totalPages ) . toEqual ( 6 ) ;
421-
422- grid . getRowByIndex ( 3 ) . pin ( ) ;
423- fix . detectChanges ( ) ;
424-
425- expect ( grid . pinnedRows . length ) . toBe ( 2 ) ;
426- pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
427- expect ( pinRowContainer . length ) . toBe ( 1 ) ;
428- expect ( grid . dataView . length ) . toBe ( 5 ) ;
429- expect ( paginator . componentInstance . totalPages ) . toEqual ( 6 ) ;
430-
431- // unpin
432- grid . getRowByIndex ( 0 ) . unpin ( ) ;
433- fix . detectChanges ( ) ;
434-
435- grid . getRowByIndex ( 0 ) . unpin ( ) ;
436- fix . detectChanges ( ) ;
437-
438- expect ( grid . pinnedRows . length ) . toBe ( 0 ) ;
439- pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
440- expect ( pinRowContainer . length ) . toBe ( 0 ) ;
441-
442- expect ( grid . dataView . length ) . toBe ( 5 ) ;
443- expect ( paginator . componentInstance . totalPages ) . toEqual ( 6 ) ;
444- } ) ;
445-
446405 it ( 'should apply sorting to both pinned and unpinned rows.' , ( ) => {
447406 grid . getRowByIndex ( 1 ) . pin ( ) ;
448407 grid . getRowByIndex ( 5 ) . pin ( ) ;
@@ -463,6 +422,7 @@ describe('Row Pinning #grid', () => {
463422 expect ( grid . getRowByIndex ( 2 ) . rowID ) . toBe ( fix . componentInstance . data [ lastIndex ] ) ;
464423 } ) ;
465424 } ) ;
425+
466426 describe ( 'Row pinning with Master Detail View' , ( ) => {
467427 beforeEach ( fakeAsync ( ( ) => {
468428 fix = TestBed . createComponent ( GridRowPinningWithMDVComponent ) ;
@@ -564,6 +524,62 @@ describe('Row Pinning #grid', () => {
564524 } ) ;
565525 } ) ;
566526
527+ describe ( 'Paging' , ( ) => {
528+ let paginator : IgxPaginatorComponent ;
529+
530+ beforeEach ( fakeAsync ( ( ) => {
531+ fix = TestBed . createComponent ( GridRowPinningComponent ) ;
532+ fix . componentInstance . createSimpleData ( 12 ) ;
533+ grid = fix . componentInstance . instance ;
534+ grid . paging = true ;
535+ grid . perPage = 5 ;
536+
537+ fix . detectChanges ( ) ;
538+ tick ( ) ;
539+
540+ paginator = fix . debugElement . query ( By . directive ( IgxPaginatorComponent ) ) . componentInstance ;
541+ } ) ) ;
542+
543+ it ( 'should correctly apply paging state for grid and paginator when there are pinned rows.' , ( ) => {
544+ // pin the first row
545+ grid . getRowByIndex ( 0 ) . pin ( ) ;
546+ fix . detectChanges ( ) ;
547+
548+ expect ( grid . rowList . length ) . toEqual ( 6 ) ;
549+ expect ( grid . perPage ) . toEqual ( 5 ) ;
550+ expect ( paginator . perPage ) . toEqual ( 5 ) ;
551+ expect ( paginator . totalRecords ) . toEqual ( 12 ) ;
552+ expect ( paginator . totalPages ) . toEqual ( 3 ) ;
553+
554+ // pin the second row
555+ grid . getRowByIndex ( 2 ) . pin ( ) ;
556+ fix . detectChanges ( ) ;
557+
558+ expect ( grid . rowList . length ) . toEqual ( 7 ) ;
559+ expect ( grid . perPage ) . toEqual ( 5 ) ;
560+ expect ( paginator . perPage ) . toEqual ( 5 ) ;
561+ expect ( paginator . totalRecords ) . toEqual ( 12 ) ;
562+ expect ( paginator . totalPages ) . toEqual ( 3 ) ;
563+ } ) ;
564+
565+ it ( 'should have the correct records shown for pages with pinned rows' , ( ) => {
566+ grid . getRowByIndex ( 0 ) . pin ( ) ;
567+ grid . getRowByIndex ( 1 ) . pin ( ) ;
568+ fix . detectChanges ( ) ;
569+
570+ let rows = grid . rowList . toArray ( ) ;
571+
572+ [ 1 , 2 , 1 , 2 , 3 , 4 , 5 ] . forEach ( ( x , index ) => expect ( rows [ index ] . cells . first . value ) . toEqual ( x ) ) ;
573+
574+ grid . paginate ( 2 ) ;
575+ fix . detectChanges ( ) ;
576+
577+ rows = grid . rowList . toArray ( ) ;
578+
579+ [ 1 , 2 , 11 , 12 ] . forEach ( ( x , index ) => expect ( rows [ index ] . cells . first . value ) . toEqual ( x ) ) ;
580+ } ) ;
581+ } ) ;
582+
567583 describe ( ' Editing ' , ( ) => {
568584 beforeEach ( fakeAsync ( ( ) => {
569585 fix = TestBed . createComponent ( GridRowPinningWithTransactionsComponent ) ;
@@ -642,6 +658,7 @@ describe('Row Pinning #grid', () => {
642658 } ) ;
643659
644660 } ) ;
661+
645662 describe ( 'Row pinning with MRL' , ( ) => {
646663 beforeEach ( fakeAsync ( ( ) => {
647664 fix = TestBed . createComponent ( GridRowPinningWithMRLComponent ) ;
@@ -728,6 +745,7 @@ describe('Row Pinning #grid', () => {
728745 verifyDOMMatchesLayoutSettings ( gridUnpinnedRow , fix . componentInstance . colGroups ) ;
729746 } ) ;
730747 } ) ;
748+
731749 describe ( ' Hiding' , ( ) => {
732750 beforeEach ( fakeAsync ( ( ) => {
733751 fix = TestBed . createComponent ( GridRowPinningComponent ) ;
@@ -789,11 +807,15 @@ describe('Row Pinning #grid', () => {
789807 `
790808} )
791809export class GridRowPinningComponent {
792- public data = SampleTestData . contactInfoDataFull ( ) ;
810+ public data : any [ ] = SampleTestData . contactInfoDataFull ( ) ;
793811 public pinningConfig : IPinningConfig = { columns : ColumnPinningPosition . Start , rows : RowPinningPosition . Top } ;
794812
795813 @ViewChild ( IgxGridComponent , { read : IgxGridComponent , static : true } )
796814 public instance : IgxGridComponent ;
815+
816+ public createSimpleData ( count : number ) {
817+ this . data = Array ( count ) . fill ( { } ) . map ( ( x , idx ) => x = { 'idx' : idx + 1 } ) ;
818+ }
797819}
798820
799821@Component ( {
@@ -839,7 +861,7 @@ export class GridRowPinningWithMRLComponent extends GridRowPinningComponent {
839861 </ng-template>
840862</igx-grid>`
841863} )
842- export class GridRowPinningWithMDVComponent extends GridRowPinningComponent { }
864+ export class GridRowPinningWithMDVComponent extends GridRowPinningComponent { }
843865
844866
845867@Component ( {
@@ -855,4 +877,4 @@ export class GridRowPinningWithMDVComponent extends GridRowPinningComponent {}
855877 ` ,
856878 providers : [ { provide : IgxGridTransaction , useClass : IgxTransactionService } ]
857879} )
858- export class GridRowPinningWithTransactionsComponent extends GridRowPinningComponent { }
880+ export class GridRowPinningWithTransactionsComponent extends GridRowPinningComponent { }
0 commit comments