@@ -45,7 +45,7 @@ const gridStub = {
45
45
setSortColumns : jest . fn ( ) ,
46
46
} ;
47
47
48
- describe ( 'CollectionService ' , ( ) => {
48
+ describe ( 'GraphqlService ' , ( ) => {
49
49
let mockColumns : Column [ ] ;
50
50
let service : GraphqlService ;
51
51
let paginationOptions : Pagination ;
@@ -203,10 +203,11 @@ describe('CollectionService', () => {
203
203
gridOptionMock . enablePagination = false ;
204
204
205
205
service . init ( { datasetName : 'users' , columnDefinitions : columns } , paginationOptions , gridStub ) ;
206
+ service . updatePagination ( 3 , 20 ) ;
206
207
const query = service . buildQuery ( ) ;
207
- gridOptionMock . enablePagination = true ; // reset it for the next test
208
208
209
209
expect ( removeSpaces ( query ) ) . toBe ( removeSpaces ( expectation ) ) ;
210
+ gridOptionMock . enablePagination = true ; // reset it for the next test
210
211
} ) ;
211
212
212
213
it ( 'should have a different pagination offset when it is updated before calling the buildQuery query (presets does that)' , ( ) => {
@@ -480,7 +481,7 @@ describe('CollectionService', () => {
480
481
expect ( currentPagination ) . toEqual ( { pageNumber : 3 , pageSize : 20 } ) ;
481
482
} ) ;
482
483
483
- it ( 'should return a query with the new pagination and use default pagination size when not provided as argument' , ( ) => {
484
+ it ( 'should return a query with the new pagination and use pagination size options that was passed to service options when it is not provided as argument to "processOnPaginationChanged" ' , ( ) => {
484
485
const expectation = `query{users(first:10, offset:20) { totalCount,nodes { id, field1, field2 }}}` ;
485
486
const querySpy = jest . spyOn ( service , 'buildQuery' ) ;
486
487
@@ -589,12 +590,12 @@ describe('CollectionService', () => {
589
590
} ) ;
590
591
591
592
it ( 'should return a query with multiple filters when the filters object has multiple search and they are passed as a filter trigger by a filter event and is of type ColumnFilters' , ( ) => {
592
- const expectation = `query{users(first:10, offset:0, filterBy:[{field:gender, operator:EQ, value:"female"}, {field:company, operator:Contains , value:"abc"}]) { totalCount,nodes{ id,company,gender,name } }}` ;
593
+ const expectation = `query{users(first:10, offset:0, filterBy:[{field:gender, operator:EQ, value:"female"}, {field:company, operator:Not_Contains , value:"abc"}]) { totalCount,nodes{ id,company,gender,name } }}` ;
593
594
const mockColumnGender = { id : 'gender' , field : 'gender' } as Column ;
594
595
const mockColumnCompany = { id : 'company' , field : 'company' } as Column ;
595
596
const mockColumnFilters = {
596
597
gender : { columnId : 'gender' , columnDef : mockColumnGender , searchTerms : [ 'female' ] , operator : 'EQ' } ,
597
- company : { columnId : 'company' , columnDef : mockColumnCompany , searchTerms : [ 'abc' ] , operator : 'Contains' } ,
598
+ company : { columnId : 'company' , columnDef : mockColumnCompany , searchTerms : [ 'abc' ] , operator : OperatorType . notContains } ,
598
599
} as ColumnFilters ;
599
600
600
601
service . init ( serviceOptions , paginationOptions , gridStub ) ;
@@ -807,10 +808,10 @@ describe('CollectionService', () => {
807
808
} ) ;
808
809
809
810
it ( 'should return a query using a different field to query when the column has a "queryField" defined in its definition' , ( ) => {
810
- const expectation = `query{users(first:10, offset:0, filterBy:[{field:isMale, operator:EQ, value:"female "}]) { totalCount,nodes{ id,company,gender,name } }}` ;
811
+ const expectation = `query{users(first:10, offset:0, filterBy:[{field:isMale, operator:EQ, value:"true "}]) { totalCount,nodes{ id,company,gender,name } }}` ;
811
812
const mockColumn = { id : 'gender' , field : 'gender' , queryField : 'isMale' } as Column ;
812
813
const mockColumnFilters = {
813
- gender : { columnId : 'gender' , columnDef : mockColumn , searchTerms : [ 'female' ] , operator : 'EQ' } ,
814
+ gender : { columnId : 'gender' , columnDef : mockColumn , searchTerms : [ true ] , operator : 'EQ' } ,
814
815
} as ColumnFilters ;
815
816
816
817
service . init ( serviceOptions , paginationOptions , gridStub ) ;
@@ -847,6 +848,23 @@ describe('CollectionService', () => {
847
848
848
849
expect ( removeSpaces ( query ) ) . toBe ( removeSpaces ( expectation ) ) ;
849
850
} ) ;
851
+
852
+ it ( 'should return a query without any sorting after clearFilters was called' , ( ) => {
853
+ const expectation = `query{ users(first:10,offset:0) { totalCount,nodes{id, company, gender,name} }}` ;
854
+ const mockColumn = { id : 'gender' , field : 'gender' } as Column ;
855
+ const mockColumnFilters = {
856
+ gender : { columnId : 'gender' , columnDef : mockColumn , searchTerms : [ 'female' ] , operator : 'EQ' } ,
857
+ } as ColumnFilters ;
858
+
859
+ service . init ( serviceOptions , paginationOptions , gridStub ) ;
860
+ service . updateFilters ( mockColumnFilters , false ) ;
861
+ service . clearFilters ( ) ;
862
+ const currentFilters = service . getCurrentFilters ( ) ;
863
+ const query = service . buildQuery ( ) ;
864
+
865
+ expect ( removeSpaces ( query ) ) . toBe ( removeSpaces ( expectation ) ) ;
866
+ expect ( currentFilters ) . toEqual ( [ ] ) ;
867
+ } ) ;
850
868
} ) ;
851
869
852
870
describe ( 'updateSorters method' , ( ) => {
@@ -925,5 +943,40 @@ describe('CollectionService', () => {
925
943
expect ( removeSpaces ( query ) ) . toBe ( removeSpaces ( expectation ) ) ;
926
944
expect ( currentSorters ) . toEqual ( [ { columnId : 'gender' , direction : 'DESC' } , { columnId : 'name' , direction : 'ASC' } ] ) ;
927
945
} ) ;
946
+
947
+ it ( 'should return a query without the field sorter when its field property is missing' , ( ) => {
948
+ const expectation = `query { users(first:10, offset:0, orderBy:[{field:gender, direction:DESC}]) {
949
+ totalCount, nodes { id,company,gender,name }}}` ;
950
+ const mockColumnSort = [
951
+ { columnId : 'gender' , sortCol : { id : 'gender' , field : 'gender' } , sortAsc : false } ,
952
+ { columnId : 'firstName' , sortCol : { id : 'firstName' } , sortAsc : true }
953
+ ] as ColumnSort [ ] ;
954
+
955
+ service . init ( serviceOptions , paginationOptions , gridStub ) ;
956
+ service . updateSorters ( mockColumnSort ) ;
957
+ const query = service . buildQuery ( ) ;
958
+ const currentSorters = service . getCurrentSorters ( ) ;
959
+
960
+ expect ( removeSpaces ( query ) ) . toBe ( removeSpaces ( expectation ) ) ;
961
+ expect ( currentSorters ) . toEqual ( [ { columnId : 'gender' , direction : 'DESC' } , { columnId : 'firstName' , direction : 'ASC' } ] ) ;
962
+ } ) ;
963
+
964
+ it ( 'should return a query without any sorting after clearSorters was called' , ( ) => {
965
+ const expectation = `query { users(first:10, offset:0) {
966
+ totalCount, nodes { id,company,gender,name }}}` ;
967
+ const mockColumnSort = [
968
+ { columnId : 'gender' , sortCol : { id : 'gender' , field : 'gender' } , sortAsc : false } ,
969
+ { columnId : 'firstName' , sortCol : { id : 'firstName' , field : 'firstName' } , sortAsc : true }
970
+ ] as ColumnSort [ ] ;
971
+
972
+ service . init ( serviceOptions , paginationOptions , gridStub ) ;
973
+ service . updateSorters ( mockColumnSort ) ;
974
+ service . clearSorters ( ) ;
975
+ const query = service . buildQuery ( ) ;
976
+ const currentSorters = service . getCurrentSorters ( ) ;
977
+
978
+ expect ( removeSpaces ( query ) ) . toBe ( removeSpaces ( expectation ) ) ;
979
+ expect ( currentSorters ) . toEqual ( [ ] ) ;
980
+ } ) ;
928
981
} ) ;
929
982
} ) ;
0 commit comments