@@ -15,6 +15,7 @@ import {
15
15
import { Filters } from '../../filters' ;
16
16
import { FilterService } from '../filter.service' ;
17
17
import { FilterFactory } from '../../filters/filterFactory' ;
18
+ import { SharedService } from '../shared.service' ;
18
19
import { SlickgridConfig , CollectionService } from '../..' ;
19
20
import { of , throwError } from 'rxjs' ;
20
21
@@ -66,6 +67,7 @@ const gridStub = {
66
67
67
68
describe ( 'FilterService' , ( ) => {
68
69
let service : FilterService ;
70
+ let sharedService : SharedService ;
69
71
let slickgridEventHandler : SlickEventHandler ;
70
72
71
73
beforeEach ( async ( ( ) => {
@@ -79,13 +81,15 @@ describe('FilterService', () => {
79
81
FilterService ,
80
82
CollectionService ,
81
83
FilterFactory ,
84
+ SharedService ,
82
85
SlickgridConfig ,
83
86
] ,
84
87
imports : [
85
88
TranslateModule . forRoot ( )
86
89
]
87
90
} ) ;
88
91
service = TestBed . get ( FilterService ) ;
92
+ sharedService = TestBed . get ( SharedService ) ;
89
93
slickgridEventHandler = service . eventHandler ;
90
94
} ) ) ;
91
95
@@ -550,7 +554,7 @@ describe('FilterService', () => {
550
554
mockItem1 = { firstName : 'John' , lastName : 'Doe' , fullName : 'John Doe' , age : 26 , address : { zip : 123456 } } ;
551
555
} ) ;
552
556
553
- it ( 'should return False when there are no column definition found' , ( ) => {
557
+ it ( 'should return True (nothing to filter, all rows will be returned) when there are no column definition found' , ( ) => {
554
558
const searchValue = 'John' ;
555
559
const mockColumn1 = { id : 'firstName' , field : 'firstName' , filterable : true } as Column ;
556
560
jest . spyOn ( gridStub , 'getColumns' ) . mockReturnValue ( [ ] ) ;
@@ -559,7 +563,7 @@ describe('FilterService', () => {
559
563
const columnFilters = { firstName : { columnDef : mockColumn1 , columnId : 'firstName' , operator : 'EQ' , searchTerms : [ searchValue ] } } ;
560
564
const output = service . customLocalFilter ( mockItem1 , { dataView : dataViewStub , grid : gridStub , columnFilters } ) ;
561
565
562
- expect ( output ) . toBe ( false ) ;
566
+ expect ( output ) . toBe ( true ) ;
563
567
} ) ;
564
568
565
569
it ( 'should return True when input value from datacontext is the same as the searchTerms' , ( ) => {
@@ -574,6 +578,19 @@ describe('FilterService', () => {
574
578
expect ( output ) . toBe ( true ) ;
575
579
} ) ;
576
580
581
+ it ( 'should work on a hidden column by using the sharedService "allColumns" and return True when input value the same as the searchTerms' , ( ) => {
582
+ const searchValue = 'John' ;
583
+ const mockColumn1 = { id : 'firstName' , field : 'firstName' , filterable : true } as Column ;
584
+ sharedService . allColumns = [ mockColumn1 ] ;
585
+ jest . spyOn ( gridStub , 'getColumns' ) . mockReturnValue ( [ ] ) ;
586
+
587
+ service . init ( gridStub ) ;
588
+ const columnFilters = { firstName : { columnDef : mockColumn1 , columnId : 'firstName' , operator : 'EQ' , searchTerms : [ searchValue ] } } ;
589
+ const output = service . customLocalFilter ( mockItem1 , { dataView : dataViewStub , grid : gridStub , columnFilters } ) ;
590
+
591
+ expect ( output ) . toBe ( true ) ;
592
+ } ) ;
593
+
577
594
it ( 'should return True when the searchTerms is an empty array' , ( ) => {
578
595
const mockColumn1 = { id : 'firstName' , field : 'firstName' , filterable : true } as Column ;
579
596
jest . spyOn ( gridStub , 'getColumns' ) . mockReturnValue ( [ mockColumn1 ] ) ;
@@ -597,6 +614,19 @@ describe('FilterService', () => {
597
614
expect ( output ) . toBe ( false ) ;
598
615
} ) ;
599
616
617
+ it ( 'should work on a hidden column by using the sharedService "allColumns" and return return False when input value is not equal to the searchTerms' , ( ) => {
618
+ const searchValue = 'Johnny' ;
619
+ const mockColumn1 = { id : 'firstName' , field : 'firstName' , filterable : true } as Column ;
620
+ sharedService . allColumns = [ mockColumn1 ] ;
621
+ jest . spyOn ( gridStub , 'getColumns' ) . mockReturnValue ( [ ] ) ;
622
+
623
+ service . init ( gridStub ) ;
624
+ const columnFilters = { firstName : { columnDef : mockColumn1 , columnId : 'firstName' , operator : 'EQ' , searchTerms : [ searchValue ] } } ;
625
+ const output = service . customLocalFilter ( mockItem1 , { dataView : dataViewStub , grid : gridStub , columnFilters } ) ;
626
+
627
+ expect ( output ) . toBe ( false ) ;
628
+ } ) ;
629
+
600
630
it ( 'should return True when input value from datacontext is a number and searchTerms is also a number' , ( ) => {
601
631
const searchValue = 26 ;
602
632
const mockColumn1 = { id : 'age' , field : 'age' , filterable : true } as Column ;
0 commit comments