@@ -2693,6 +2693,122 @@ describe('igxCombo', () => {
2693
2693
expect ( combo . searchValue ) . toEqual ( 'Test' ) ;
2694
2694
cancelSub . unsubscribe ( ) ;
2695
2695
} ) ;
2696
+ it ( 'Should filter the data when custom filterFunction is provided' , fakeAsync ( ( ) => {
2697
+ combo . open ( ) ;
2698
+ tick ( ) ;
2699
+ fixture . detectChanges ( ) ;
2700
+ expect ( combo . dropdown . items . length ) . toBeGreaterThan ( 0 ) ;
2701
+
2702
+ combo . searchValue = 'new england' ;
2703
+ combo . handleInputChange ( ) ;
2704
+ fixture . detectChanges ( ) ;
2705
+ expect ( combo . dropdown . items . length ) . toEqual ( 0 ) ;
2706
+
2707
+ combo . close ( ) ;
2708
+ tick ( ) ;
2709
+ fixture . detectChanges ( ) ;
2710
+ // set filter function to search only on valueKyes
2711
+ combo . filterFunction = ( collection : any [ ] , searchValue : any ) : any [ ] => {
2712
+ if ( ! collection ) return [ ] ;
2713
+ if ( ! searchValue ) return collection ;
2714
+ const searchTerm = combo . filteringOptions . caseSensitive ? searchValue . trim ( ) : searchValue . toLowerCase ( ) . trim ( ) ;
2715
+ return collection . filter ( i => combo . filteringOptions . caseSensitive ?
2716
+ i [ combo . displayKey ] ?. includes ( searchTerm ) || i [ combo . groupKey ] ?. includes ( searchTerm ) :
2717
+ i [ combo . displayKey ] ?. toString ( ) . toLowerCase ( ) . includes ( searchTerm ) || i [ combo . groupKey ] ?. toString ( ) . toLowerCase ( ) . includes ( searchTerm ) )
2718
+ }
2719
+ combo . open ( ) ;
2720
+ tick ( ) ;
2721
+ fixture . detectChanges ( ) ;
2722
+ expect ( combo . dropdown . items . length ) . toBeGreaterThan ( 0 ) ;
2723
+
2724
+ combo . searchValue = 'new england' ;
2725
+ combo . handleInputChange ( ) ;
2726
+ fixture . detectChanges ( ) ;
2727
+ expect ( combo . dropdown . items . length ) . toBeGreaterThan ( 0 ) ;
2728
+
2729
+ combo . filterFunction = undefined ;
2730
+ fixture . detectChanges ( ) ;
2731
+ expect ( combo . dropdown . items . length ) . toEqual ( 0 ) ;
2732
+ } ) ) ;
2733
+ it ( 'Should update filtering when custom filterFunction is provided and filteringOptions are changed' , fakeAsync ( ( ) => {
2734
+ combo . open ( ) ;
2735
+ tick ( ) ;
2736
+ fixture . detectChanges ( ) ;
2737
+ expect ( combo . dropdown . items . length ) . toBeGreaterThan ( 0 ) ;
2738
+
2739
+ combo . searchValue = 'new england' ;
2740
+ combo . handleInputChange ( ) ;
2741
+ fixture . detectChanges ( ) ;
2742
+ expect ( combo . dropdown . items . length ) . toEqual ( 0 ) ;
2743
+
2744
+ combo . close ( ) ;
2745
+ tick ( ) ;
2746
+ fixture . detectChanges ( ) ;
2747
+ // set filter function to search only on valueKyes
2748
+ combo . filterFunction = ( collection : any [ ] , searchValue : any ) : any [ ] => {
2749
+ if ( ! collection ) return [ ] ;
2750
+ if ( ! searchValue ) return collection ;
2751
+ const searchTerm = combo . filteringOptions . caseSensitive ? searchValue . trim ( ) : searchValue . toLowerCase ( ) . trim ( ) ;
2752
+ return collection . filter ( i => combo . filteringOptions . caseSensitive ?
2753
+ i [ combo . displayKey ] ?. includes ( searchTerm ) || i [ combo . groupKey ] ?. includes ( searchTerm ) :
2754
+ i [ combo . displayKey ] ?. toString ( ) . toLowerCase ( ) . includes ( searchTerm ) || i [ combo . groupKey ] ?. toString ( ) . toLowerCase ( ) . includes ( searchTerm ) )
2755
+ }
2756
+ combo . open ( ) ;
2757
+ tick ( ) ;
2758
+ fixture . detectChanges ( ) ;
2759
+ expect ( combo . dropdown . items . length ) . toBeGreaterThan ( 0 ) ;
2760
+
2761
+ combo . searchValue = 'new england' ;
2762
+ combo . handleInputChange ( ) ;
2763
+ fixture . detectChanges ( ) ;
2764
+ expect ( combo . dropdown . items . length ) . toBeGreaterThan ( 0 ) ;
2765
+
2766
+ combo . filteringOptions = { caseSensitive : true } ;
2767
+ fixture . detectChanges ( ) ;
2768
+ expect ( combo . dropdown . items . length ) . toEqual ( 0 ) ;
2769
+ } ) ) ;
2770
+ it ( 'Should update filtering when custom filterFunction is provided and filterable is changed' , fakeAsync ( ( ) => {
2771
+ combo . open ( ) ;
2772
+ tick ( ) ;
2773
+ fixture . detectChanges ( ) ;
2774
+ expect ( combo . dropdown . items . length ) . toBeGreaterThan ( 0 ) ;
2775
+
2776
+ combo . searchValue = 'new england' ;
2777
+ combo . handleInputChange ( ) ;
2778
+ fixture . detectChanges ( ) ;
2779
+ expect ( combo . dropdown . items . length ) . toEqual ( 0 ) ;
2780
+
2781
+ combo . close ( ) ;
2782
+ tick ( ) ;
2783
+ fixture . detectChanges ( ) ;
2784
+ // set filter function to search only on valueKyes
2785
+ combo . filterFunction = ( collection : any [ ] , searchValue : any ) : any [ ] => {
2786
+ if ( ! collection ) return [ ] ;
2787
+ if ( ! searchValue ) return collection ;
2788
+ const searchTerm = combo . filteringOptions . caseSensitive ? searchValue . trim ( ) : searchValue . toLowerCase ( ) . trim ( ) ;
2789
+ return collection . filter ( i => combo . filteringOptions . caseSensitive ?
2790
+ i [ combo . displayKey ] ?. includes ( searchTerm ) || i [ combo . groupKey ] ?. includes ( searchTerm ) :
2791
+ i [ combo . displayKey ] ?. toString ( ) . toLowerCase ( ) . includes ( searchTerm ) || i [ combo . groupKey ] ?. toString ( ) . toLowerCase ( ) . includes ( searchTerm ) )
2792
+ }
2793
+ combo . open ( ) ;
2794
+ tick ( ) ;
2795
+ fixture . detectChanges ( ) ;
2796
+ expect ( combo . dropdown . items . length ) . toBeGreaterThan ( 0 ) ;
2797
+
2798
+ combo . searchValue = 'new england' ;
2799
+ combo . handleInputChange ( ) ;
2800
+ fixture . detectChanges ( ) ;
2801
+ expect ( combo . dropdown . items . length ) . toBeGreaterThan ( 0 ) ;
2802
+
2803
+ combo . searchValue = 'value not in the list' ;
2804
+ combo . handleInputChange ( ) ;
2805
+ fixture . detectChanges ( ) ;
2806
+ expect ( combo . dropdown . items . length ) . toEqual ( 0 ) ;
2807
+
2808
+ combo . filterable = false ;
2809
+ fixture . detectChanges ( ) ;
2810
+ expect ( combo . dropdown . items . length ) . toBeGreaterThan ( 0 ) ;
2811
+ } ) ) ;
2696
2812
} ) ;
2697
2813
describe ( 'Form control tests: ' , ( ) => {
2698
2814
describe ( 'Reactive form tests: ' , ( ) => {
0 commit comments