@@ -20,7 +20,7 @@ import {
20
20
SharedService ,
21
21
SortService ,
22
22
} from '../../services' ;
23
- import { Column , CurrentFilter , CurrentSorter , GridOption , GridState , GridStateChange , GridStateType , Pagination } from '../../models' ;
23
+ import { Column , CurrentFilter , CurrentSorter , GridOption , GridState , GridStateChange , GridStateType , Pagination , GraphqlServiceApi , GraphqlServiceOption } from '../../models' ;
24
24
import { Filters } from '../../filters' ;
25
25
import { Editors } from '../../editors' ;
26
26
import * as utilities from '../../services/backend-utilities' ;
@@ -490,6 +490,24 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
490
490
491
491
expect ( syncSpy ) . toHaveBeenCalledWith ( component . grid , true , false ) ;
492
492
} ) ;
493
+
494
+ it ( 'should bind local filter when "enableFiltering" is set' , ( ) => {
495
+ const bindLocalSpy = jest . spyOn ( filterServiceStub , 'bindLocalOnFilter' ) ;
496
+
497
+ component . gridOptions = { enableFiltering : true } as GridOption ;
498
+ component . ngAfterViewInit ( ) ;
499
+
500
+ expect ( bindLocalSpy ) . toHaveBeenCalledWith ( mockGrid , mockDataView ) ;
501
+ } ) ;
502
+
503
+ it ( 'should bind local sort when "enableSorting" is set' , ( ) => {
504
+ const bindLocalSpy = jest . spyOn ( sortServiceStub , 'bindLocalOnSort' ) ;
505
+
506
+ component . gridOptions = { enableSorting : true } as GridOption ;
507
+ component . ngAfterViewInit ( ) ;
508
+
509
+ expect ( bindLocalSpy ) . toHaveBeenCalledWith ( mockGrid , mockDataView ) ;
510
+ } ) ;
493
511
} ) ;
494
512
495
513
describe ( 'flag checks' , ( ) => {
@@ -820,7 +838,7 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
820
838
821
839
it ( 'should execute backend service "init" method when set' , ( ) => {
822
840
const mockPagination = { pageNumber : 1 , pageSizes : [ 10 , 25 , 50 ] , pageSize : 10 , totalItems : 100 } ;
823
- const mockGraphqlOptions = { extraQueryArguments : [ { field : 'userId' , value : 123 } ] } ;
841
+ const mockGraphqlOptions = { datasetName : 'users' , extraQueryArguments : [ { field : 'userId' , value : 123 } ] } as GraphqlServiceOption ;
824
842
const bindBackendSpy = jest . spyOn ( sortServiceStub , 'bindBackendOnSort' ) ;
825
843
const mockGraphqlService2 = { ...mockGraphqlService , init : jest . fn ( ) } as unknown as GraphqlService ;
826
844
const initSpy = jest . spyOn ( mockGraphqlService2 , 'init' ) ;
@@ -831,8 +849,8 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
831
849
service : mockGraphqlService2 ,
832
850
options : mockGraphqlOptions ,
833
851
preProcess : ( ) => jest . fn ( ) ,
834
- process : ( query ) => new Promise ( ( resolve ) => resolve ( 'process resolved' ) ) ,
835
- } ,
852
+ process : ( query ) => new Promise ( ( resolve ) => resolve ( { data : { users : { nodes : [ ] , totalCount : 100 } } } ) ) ,
853
+ } as GraphqlServiceApi ,
836
854
pagination : mockPagination ,
837
855
} as GridOption ;
838
856
component . ngAfterViewInit ( ) ;
@@ -841,32 +859,40 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
841
859
expect ( initSpy ) . toHaveBeenCalledWith ( mockGraphqlOptions , mockPagination , mockGrid ) ;
842
860
} ) ;
843
861
844
- it ( 'should bind local sort when "enableSorting" is set' , ( ) => {
845
- const bindLocalSpy = jest . spyOn ( sortServiceStub , 'bindLocalOnSort ' ) ;
862
+ it ( 'should call bind backend sorting when "enableSorting" is set' , ( ) => {
863
+ const bindBackendSpy = jest . spyOn ( sortServiceStub , 'bindBackendOnSort ' ) ;
846
864
847
- component . gridOptions = { enableSorting : true } as GridOption ;
865
+ component . gridOptions = {
866
+ enableSorting : true ,
867
+ backendServiceApi : {
868
+ service : mockGraphqlService ,
869
+ preProcess : ( ) => jest . fn ( ) ,
870
+ process : ( query ) => new Promise ( ( resolve ) => resolve ( 'process resolved' ) ) ,
871
+ }
872
+ } as GridOption ;
848
873
component . ngAfterViewInit ( ) ;
849
874
850
- expect ( bindLocalSpy ) . toHaveBeenCalledWith ( mockGrid , mockDataView ) ;
875
+ expect ( bindBackendSpy ) . toHaveBeenCalledWith ( mockGrid , mockDataView ) ;
851
876
} ) ;
852
877
853
- it ( 'should reflect column filters when "enableSorting" is set' , ( ) => {
854
- const bindBackendSpy = jest . spyOn ( sortServiceStub , 'bindBackendOnSort ' ) ;
878
+ it ( 'should call bind local sorting when "enableSorting" is set and "useLocalSorting" is set as well ' , ( ) => {
879
+ const bindLocalSpy = jest . spyOn ( sortServiceStub , 'bindLocalOnSort ' ) ;
855
880
856
881
component . gridOptions = {
857
882
enableSorting : true ,
858
883
backendServiceApi : {
859
884
service : mockGraphqlService ,
885
+ useLocalSorting : true ,
860
886
preProcess : ( ) => jest . fn ( ) ,
861
887
process : ( query ) => new Promise ( ( resolve ) => resolve ( 'process resolved' ) ) ,
862
888
}
863
889
} as GridOption ;
864
890
component . ngAfterViewInit ( ) ;
865
891
866
- expect ( bindBackendSpy ) . toHaveBeenCalledWith ( mockGrid , mockDataView ) ;
892
+ expect ( bindLocalSpy ) . toHaveBeenCalledWith ( mockGrid , mockDataView ) ;
867
893
} ) ;
868
894
869
- it ( 'should reflect column filters when "enableFiltering" is set' , ( ) => {
895
+ it ( 'should call bind backend filtering when "enableFiltering" is set' , ( ) => {
870
896
const initSpy = jest . spyOn ( filterServiceStub , 'init' ) ;
871
897
const bindLocalSpy = jest . spyOn ( filterServiceStub , 'bindLocalOnFilter' ) ;
872
898
const populateSpy = jest . spyOn ( filterServiceStub , 'populateColumnFilterSearchTermPresets' ) ;
@@ -879,6 +905,23 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
879
905
expect ( populateSpy ) . not . toHaveBeenCalled ( ) ;
880
906
} ) ;
881
907
908
+ it ( 'should call bind local filtering when "enableFiltering" is set and "useLocalFiltering" is set as well' , ( ) => {
909
+ const bindLocalSpy = jest . spyOn ( filterServiceStub , 'bindLocalOnFilter' ) ;
910
+
911
+ component . gridOptions = {
912
+ enableFiltering : true ,
913
+ backendServiceApi : {
914
+ service : mockGraphqlService ,
915
+ useLocalFiltering : true ,
916
+ preProcess : ( ) => jest . fn ( ) ,
917
+ process : ( query ) => new Promise ( ( resolve ) => resolve ( 'process resolved' ) ) ,
918
+ }
919
+ } as GridOption ;
920
+ component . ngAfterViewInit ( ) ;
921
+
922
+ expect ( bindLocalSpy ) . toHaveBeenCalledWith ( mockGrid , mockDataView ) ;
923
+ } ) ;
924
+
882
925
it ( 'should reflect column filters when "enableFiltering" is set' , ( ) => {
883
926
const initSpy = jest . spyOn ( filterServiceStub , 'init' ) ;
884
927
const bindBackendSpy = jest . spyOn ( filterServiceStub , 'bindBackendOnFilter' ) ;
0 commit comments