@@ -97,16 +97,12 @@ describe('PaginationService', () => {
97
97
98
98
it ( 'should initialize the service and call "refreshPagination" and trigger "onPaginationChanged" event' , ( ) => {
99
99
const refreshSpy = jest . spyOn ( service , 'refreshPagination' ) ;
100
- const paginationSpy = jest . spyOn ( service . onPaginationChanged , 'next' ) ;
101
100
service . init ( gridStub , dataviewStub , mockGridOption . pagination , mockGridOption . backendServiceApi ) ;
102
101
103
102
expect ( service . paginationOptions ) . toEqual ( mockGridOption . pagination ) ;
104
103
expect ( service . pager ) . toBeTruthy ( ) ;
105
104
expect ( refreshSpy ) . toHaveBeenCalled ( ) ;
106
105
expect ( service . getCurrentPageNumber ( ) ) . toBe ( 2 ) ;
107
- expect ( paginationSpy ) . toHaveBeenCalledWith ( {
108
- from : 26 , to : 50 , itemsPerPage : 25 , pageCount : 4 , pageNumber : 2 , totalItems : 85 , availablePageSizes : mockGridOption . pagination . pageSizes
109
- } ) ;
110
106
} ) ;
111
107
112
108
it ( 'should initialize the service and be able to change the grid options by the SETTER and expect the GETTER to have updated options' , ( ) => {
@@ -126,7 +122,7 @@ describe('PaginationService', () => {
126
122
expect ( service . totalItems ) . toEqual ( 125 ) ;
127
123
expect ( service . pager ) . toBeTruthy ( ) ;
128
124
expect ( service . getCurrentPageNumber ( ) ) . toBe ( 2 ) ;
129
- expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ; // called 1x time inside the init() only
125
+ expect ( spy ) . toHaveBeenCalledWith ( false , false ) ;
130
126
} ) ;
131
127
132
128
it ( 'should be able to change the totalItems by the SETTER after the initialization and expect the "refreshPagination" method to be called' , ( ) => {
@@ -494,31 +490,43 @@ describe('PaginationService', () => {
494
490
} ) ;
495
491
496
492
it ( 'should call refreshPagination when "onFilterCleared" is triggered' , ( ) => {
497
- const spy = jest . spyOn ( service , 'refreshPagination' ) ;
493
+ const resetSpy = jest . spyOn ( service , 'resetPagination' ) ;
494
+ const refreshSpy = jest . spyOn ( service , 'refreshPagination' ) ;
498
495
499
496
service . init ( gridStub , dataviewStub , mockGridOption . pagination , mockGridOption . backendServiceApi ) ;
500
497
filterServiceStub . onFilterCleared . next ( true ) ;
501
498
502
- expect ( spy ) . toHaveBeenCalledWith ( true ) ;
499
+ expect ( resetSpy ) . toHaveBeenCalled ( ) ;
500
+ expect ( refreshSpy ) . toHaveBeenCalledWith ( true , true ) ;
503
501
} ) ;
504
502
505
503
it ( 'should call refreshPagination when "onFilterChanged" is triggered' , ( ) => {
504
+ const resetSpy = jest . spyOn ( service , 'resetPagination' ) ;
506
505
const spy = jest . spyOn ( service , 'refreshPagination' ) ;
507
506
508
507
service . init ( gridStub , dataviewStub , mockGridOption . pagination , mockGridOption . backendServiceApi ) ;
509
508
filterServiceStub . onFilterChanged . next ( [ { columnId : 'field1' , operator : '=' , searchTerms : [ ] } ] ) ;
510
509
511
- expect ( spy ) . toHaveBeenCalledWith ( true ) ;
510
+ expect ( resetSpy ) . toHaveBeenCalled ( ) ;
511
+ expect ( spy ) . toHaveBeenCalledWith ( true , true ) ;
512
512
} ) ;
513
513
} ) ;
514
514
515
515
describe ( 'resetPagination method' , ( ) => {
516
- it ( 'should call "refreshPagination" with argument True when calling the method' , ( ) => {
516
+ it ( 'should call "refreshPagination" with 2 arguments True when calling the method' , ( ) => {
517
517
const spy = jest . spyOn ( service , 'refreshPagination' ) ;
518
518
service . init ( gridStub , dataviewStub , mockGridOption . pagination , mockGridOption . backendServiceApi ) ;
519
519
service . resetPagination ( ) ;
520
520
521
- expect ( spy ) . toHaveBeenCalledWith ( true ) ;
521
+ expect ( spy ) . toHaveBeenCalledWith ( true , true ) ;
522
+ } ) ;
523
+
524
+ it ( 'should call "refreshPagination" with True and False arguments when calling the method with False being passed as input argument' , ( ) => {
525
+ const spy = jest . spyOn ( service , 'refreshPagination' ) ;
526
+ service . init ( gridStub , dataviewStub , mockGridOption . pagination , mockGridOption . backendServiceApi ) ;
527
+ service . resetPagination ( false ) ;
528
+
529
+ expect ( spy ) . toHaveBeenCalledWith ( true , false ) ;
522
530
} ) ;
523
531
} ) ;
524
532
@@ -540,8 +548,7 @@ describe('PaginationService', () => {
540
548
gridServiceStub . onItemAdded . next ( mockItems ) ;
541
549
542
550
setTimeout ( ( ) => {
543
- // called 2x times by init() then by processOnItemAddedOrRemoved()
544
- expect ( paginationSpy ) . toHaveBeenCalledTimes ( 2 ) ;
551
+ expect ( paginationSpy ) . toHaveBeenCalledTimes ( 1 ) ;
545
552
expect ( recalculateSpy ) . toHaveBeenCalledTimes ( 2 ) ;
546
553
expect ( service . pager . from ) . toBe ( 26 ) ;
547
554
expect ( service . pager . to ) . toBe ( 50 + 1 ) ;
@@ -558,8 +565,7 @@ describe('PaginationService', () => {
558
565
gridServiceStub . onItemAdded . next ( mockItems ) ;
559
566
560
567
setTimeout ( ( ) => {
561
- // called 2x times by init() then by processOnItemAddedOrRemoved()
562
- expect ( paginationSpy ) . toHaveBeenCalledTimes ( 2 ) ;
568
+ expect ( paginationSpy ) . toHaveBeenCalledTimes ( 1 ) ;
563
569
expect ( recalculateSpy ) . toHaveBeenCalledTimes ( 2 ) ;
564
570
expect ( service . pager . from ) . toBe ( 26 ) ;
565
571
expect ( service . pager . to ) . toBe ( 50 + mockItems . length ) ;
@@ -575,8 +581,7 @@ describe('PaginationService', () => {
575
581
gridServiceStub . onItemAdded . next ( null ) ;
576
582
577
583
setTimeout ( ( ) => {
578
- // called 1x time by init() only
579
- expect ( paginationSpy ) . toHaveBeenCalledTimes ( 1 ) ;
584
+ expect ( paginationSpy ) . not . toHaveBeenCalled ( ) ;
580
585
expect ( recalculateSpy ) . toHaveBeenCalledTimes ( 1 ) ;
581
586
expect ( service . pager . from ) . toBe ( 26 ) ;
582
587
expect ( service . pager . to ) . toBe ( 50 ) ;
@@ -593,8 +598,7 @@ describe('PaginationService', () => {
593
598
gridServiceStub . onItemDeleted . next ( mockItems ) ;
594
599
595
600
setTimeout ( ( ) => {
596
- // called 2x times by init() then by processOnItemAddedOrRemoved()
597
- expect ( paginationSpy ) . toHaveBeenCalledTimes ( 2 ) ;
601
+ expect ( paginationSpy ) . toHaveBeenCalledTimes ( 1 ) ;
598
602
expect ( recalculateSpy ) . toHaveBeenCalledTimes ( 2 ) ;
599
603
expect ( service . pager . from ) . toBe ( 26 ) ;
600
604
expect ( service . pager . to ) . toBe ( 50 - 1 ) ;
@@ -611,8 +615,7 @@ describe('PaginationService', () => {
611
615
gridServiceStub . onItemDeleted . next ( mockItems ) ;
612
616
613
617
setTimeout ( ( ) => {
614
- // called 2x times by init() then by processOnItemAddedOrRemoved()
615
- expect ( paginationSpy ) . toHaveBeenCalledTimes ( 2 ) ;
618
+ expect ( paginationSpy ) . toHaveBeenCalledTimes ( 1 ) ;
616
619
expect ( recalculateSpy ) . toHaveBeenCalledTimes ( 2 ) ;
617
620
expect ( service . pager . from ) . toBe ( 26 ) ;
618
621
expect ( service . pager . to ) . toBe ( 50 - mockItems . length ) ;
@@ -629,8 +632,7 @@ describe('PaginationService', () => {
629
632
gridServiceStub . onItemDeleted . next ( null ) ;
630
633
631
634
setTimeout ( ( ) => {
632
- // called 1x time by init() only
633
- expect ( paginationSpy ) . toHaveBeenCalledTimes ( 1 ) ;
635
+ expect ( paginationSpy ) . not . toHaveBeenCalled ( ) ;
634
636
expect ( recalculateSpy ) . toHaveBeenCalledTimes ( 1 ) ;
635
637
expect ( service . pager . from ) . toBe ( 26 ) ;
636
638
expect ( service . pager . to ) . toBe ( 50 ) ;
@@ -662,7 +664,6 @@ describe('PaginationService', () => {
662
664
663
665
it ( 'should initialize the service and call "refreshPagination" with some DataView calls' , ( ) => {
664
666
const refreshSpy = jest . spyOn ( service , 'refreshPagination' ) ;
665
- const paginationSpy = jest . spyOn ( service . onPaginationChanged , 'next' ) ;
666
667
const onPagingSpy = jest . spyOn ( dataviewStub . onPagingInfoChanged , 'subscribe' ) ;
667
668
const setRefreshSpy = jest . spyOn ( dataviewStub , 'setRefreshHints' ) ;
668
669
const setPagingSpy = jest . spyOn ( dataviewStub , 'setPagingOptions' ) ;
@@ -675,9 +676,6 @@ describe('PaginationService', () => {
675
676
expect ( setRefreshSpy ) . toHaveBeenCalled ( ) ;
676
677
expect ( setPagingSpy ) . toHaveBeenCalledWith ( { pageSize : 25 , pageNum : 0 } ) ;
677
678
expect ( service . getCurrentPageNumber ( ) ) . toBe ( 2 ) ;
678
- expect ( paginationSpy ) . toHaveBeenCalledWith ( {
679
- from : 26 , to : 50 , itemsPerPage : 25 , pageCount : 4 , pageNumber : 2 , totalItems : 85 , availablePageSizes : mockGridOption . pagination . pageSizes
680
- } ) ;
681
679
} ) ;
682
680
683
681
it ( 'should change the totalItems when "onPagingInfoChanged" from the DataView is triggered with a different total' , ( ) => {
0 commit comments