@@ -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 ) ;
@@ -925,5 +926,23 @@ describe('CollectionService', () => {
925
926
expect ( removeSpaces ( query ) ) . toBe ( removeSpaces ( expectation ) ) ;
926
927
expect ( currentSorters ) . toEqual ( [ { columnId : 'gender' , direction : 'DESC' } , { columnId : 'name' , direction : 'ASC' } ] ) ;
927
928
} ) ;
929
+
930
+
931
+ it ( 'should return a query without the field sorter when its field property is missing' , ( ) => {
932
+ const expectation = `query { users(first:10, offset:0, orderBy:[{field:gender, direction:DESC}]) {
933
+ totalCount, nodes { id,company,gender,name }}}` ;
934
+ const mockColumnSort = [
935
+ { columnId : 'gender' , sortCol : { id : 'gender' , field : 'gender' } , sortAsc : false } ,
936
+ { columnId : 'firstName' , sortCol : { id : 'firstName' } , sortAsc : true }
937
+ ] as ColumnSort [ ] ;
938
+
939
+ service . init ( serviceOptions , paginationOptions , gridStub ) ;
940
+ service . updateSorters ( mockColumnSort ) ;
941
+ const query = service . buildQuery ( ) ;
942
+ const currentSorters = service . getCurrentSorters ( ) ;
943
+
944
+ expect ( removeSpaces ( query ) ) . toBe ( removeSpaces ( expectation ) ) ;
945
+ expect ( currentSorters ) . toEqual ( [ { columnId : 'gender' , direction : 'DESC' } , { columnId : 'firstName' , direction : 'ASC' } ] ) ;
946
+ } ) ;
928
947
} ) ;
929
948
} ) ;
0 commit comments