1
- import { AfterViewInit , ChangeDetectorRef , Component , Injectable , OnInit , ViewChild , OnDestroy , DebugElement } from '@angular/core' ;
2
- import { TestBed , tick , fakeAsync , ComponentFixture , waitForAsync } from '@angular/core/testing' ;
1
+ import { AfterViewInit , ChangeDetectorRef , Component , DebugElement , Injectable , OnDestroy , OnInit , ViewChild } from '@angular/core' ;
2
+ import { ComponentFixture , fakeAsync , TestBed , tick , waitForAsync } from '@angular/core/testing' ;
3
+ import {
4
+ FormsModule , NgControl , NgForm , NgModel , ReactiveFormsModule , UntypedFormBuilder , UntypedFormControl , UntypedFormGroup , Validators
5
+ } from '@angular/forms' ;
3
6
import { By } from '@angular/platform-browser' ;
4
7
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
5
- import { UntypedFormGroup , UntypedFormControl , Validators , UntypedFormBuilder , ReactiveFormsModule ,
6
- FormsModule , NgControl , NgModel , NgForm } from '@angular/forms' ;
7
- import {
8
- IgxComboComponent ,
9
- IgxComboModule ,
10
- IComboSelectionChangingEventArgs ,
11
- IComboSearchInputEventArgs ,
12
- IComboItemAdditionEvent
13
- } from './combo.component' ;
14
- import { IgxComboItemComponent } from './combo-item.component' ;
15
- import { IgxComboDropDownComponent } from './combo-dropdown.component' ;
16
- import { IgxComboAddItemComponent } from './combo-add-item.component' ;
17
- import { IgxComboFilteringPipe } from './combo.pipes' ;
18
- import { IgxInputState } from '../directives/input/input.directive' ;
19
- import { IForOfState } from '../directives/for-of/for_of.directive' ;
20
- import { IgxToggleModule } from '../directives/toggle/toggle.directive' ;
21
8
import { BehaviorSubject , Observable } from 'rxjs' ;
22
9
import { take } from 'rxjs/operators' ;
23
- import { UIInteractions , wait } from '../test-utils/ui-interactions.spec' ;
24
- import { configureTestSuite } from '../test-utils/configure-suite' ;
25
10
import { DisplayDensity } from '../core/density' ;
26
- import { AbsoluteScrollStrategy , ConnectedPositioningStrategy } from '../services/public_api' ;
27
11
import { IgxSelectionAPIService } from '../core/selection' ;
28
- import { IgxIconService } from '../icon/public_api' ;
29
12
import { IBaseCancelableBrowserEventArgs } from '../core/utils' ;
30
13
import { SortingDirection } from '../data-operations/sorting-strategy' ;
31
- import { IgxComboState } from './combo.common' ;
14
+ import { IForOfState } from '../directives/for-of/for_of.directive' ;
15
+ import { IgxInputState } from '../directives/input/input.directive' ;
16
+ import { IgxToggleModule } from '../directives/toggle/toggle.directive' ;
32
17
import { IgxDropDownItemBaseDirective } from '../drop-down/public_api' ;
18
+ import { IgxIconService } from '../icon/public_api' ;
19
+ import { AbsoluteScrollStrategy , ConnectedPositioningStrategy } from '../services/public_api' ;
20
+ import { configureTestSuite } from '../test-utils/configure-suite' ;
21
+ import { UIInteractions , wait } from '../test-utils/ui-interactions.spec' ;
22
+ import { IgxComboAddItemComponent } from './combo-add-item.component' ;
23
+ import { IgxComboDropDownComponent } from './combo-dropdown.component' ;
24
+ import { IgxComboItemComponent } from './combo-item.component' ;
25
+ import { IComboFilteringOptions , IgxComboState } from './combo.common' ;
26
+ import {
27
+ IComboItemAdditionEvent , IComboSearchInputEventArgs , IComboSelectionChangingEventArgs , IgxComboComponent ,
28
+ IgxComboModule
29
+ } from './combo.component' ;
30
+ import { IgxComboFilteringPipe } from './combo.pipes' ;
33
31
34
32
const CSS_CLASS_COMBO = 'igx-combo' ;
35
33
const CSS_CLASS_COMBO_DROPDOWN = 'igx-combo__drop-down' ;
@@ -2689,14 +2687,14 @@ describe('igxCombo', () => {
2689
2687
combo . close ( ) ;
2690
2688
tick ( ) ;
2691
2689
fixture . detectChanges ( ) ;
2692
- // set filter function to search only on valueKyes
2693
- combo . filterFunction = ( collection : any [ ] , searchValue : any ) : any [ ] => {
2690
+ combo . filteringOptions = { caseSensitive : false , filterable : true , filteringKey : combo . groupKey } ;
2691
+ combo . filterFunction = ( collection : any [ ] , searchValue : any , filteringOptions : IComboFilteringOptions ) : any [ ] => {
2694
2692
if ( ! collection ) return [ ] ;
2695
2693
if ( ! searchValue ) return collection ;
2696
- const searchTerm = combo . filteringOptions . caseSensitive ? searchValue . trim ( ) : searchValue . toLowerCase ( ) . trim ( ) ;
2697
- return collection . filter ( i => combo . filteringOptions . caseSensitive ?
2698
- i [ combo . displayKey ] ?. includes ( searchTerm ) || i [ combo . groupKey ] ?. includes ( searchTerm ) :
2699
- i [ combo . displayKey ] ?. toString ( ) . toLowerCase ( ) . includes ( searchTerm ) || i [ combo . groupKey ] ?. toString ( ) . toLowerCase ( ) . includes ( searchTerm ) )
2694
+ const searchTerm = filteringOptions . caseSensitive ? searchValue . trim ( ) : searchValue . toLowerCase ( ) . trim ( ) ;
2695
+ return collection . filter ( i => filteringOptions . caseSensitive ?
2696
+ i [ filteringOptions . filteringKey ] ?. includes ( searchTerm ) :
2697
+ i [ filteringOptions . filteringKey ] ?. toString ( ) . toLowerCase ( ) . includes ( searchTerm ) )
2700
2698
}
2701
2699
combo . open ( ) ;
2702
2700
tick ( ) ;
@@ -2708,11 +2706,12 @@ describe('igxCombo', () => {
2708
2706
fixture . detectChanges ( ) ;
2709
2707
expect ( combo . dropdown . items . length ) . toBeGreaterThan ( 0 ) ;
2710
2708
2711
- combo . filterFunction = null ;
2709
+ combo . filterFunction = undefined ;
2710
+ combo . filteringOptions = undefined ;
2712
2711
fixture . detectChanges ( ) ;
2713
2712
expect ( combo . dropdown . items . length ) . toEqual ( 0 ) ;
2714
2713
} ) ) ;
2715
- it ( 'Should update filtering when custom filterFunction is provided and filteringOptions are changed' , fakeAsync ( ( ) => {
2714
+ it ( 'Should update filtering when custom filterFunction is provided and filteringOptions.caseSensitive is changed' , fakeAsync ( ( ) => {
2716
2715
combo . open ( ) ;
2717
2716
tick ( ) ;
2718
2717
fixture . detectChanges ( ) ;
@@ -2726,14 +2725,14 @@ describe('igxCombo', () => {
2726
2725
combo . close ( ) ;
2727
2726
tick ( ) ;
2728
2727
fixture . detectChanges ( ) ;
2729
- // set filter function to search only on valueKyes
2730
- combo . filterFunction = ( collection : any [ ] , searchValue : any ) : any [ ] => {
2728
+ combo . filteringOptions = { caseSensitive : false , filterable : true , filteringKey : combo . groupKey } ;
2729
+ combo . filterFunction = ( collection : any [ ] , searchValue : any , filteringOptions : IComboFilteringOptions ) : any [ ] => {
2731
2730
if ( ! collection ) return [ ] ;
2732
2731
if ( ! searchValue ) return collection ;
2733
- const searchTerm = combo . filteringOptions . caseSensitive ? searchValue . trim ( ) : searchValue . toLowerCase ( ) . trim ( ) ;
2734
- return collection . filter ( i => combo . filteringOptions . caseSensitive ?
2735
- i [ combo . displayKey ] ?. includes ( searchTerm ) || i [ combo . groupKey ] ?. includes ( searchTerm ) :
2736
- i [ combo . displayKey ] ?. toString ( ) . toLowerCase ( ) . includes ( searchTerm ) || i [ combo . groupKey ] ?. toString ( ) . toLowerCase ( ) . includes ( searchTerm ) )
2732
+ const searchTerm = filteringOptions . caseSensitive ? searchValue . trim ( ) : searchValue . toLowerCase ( ) . trim ( ) ;
2733
+ return collection . filter ( i => filteringOptions . caseSensitive ?
2734
+ i [ filteringOptions . filteringKey ] ?. includes ( searchTerm ) :
2735
+ i [ filteringOptions . filteringKey ] ?. toString ( ) . toLowerCase ( ) . includes ( searchTerm ) )
2737
2736
}
2738
2737
combo . open ( ) ;
2739
2738
tick ( ) ;
@@ -2745,11 +2744,11 @@ describe('igxCombo', () => {
2745
2744
fixture . detectChanges ( ) ;
2746
2745
expect ( combo . dropdown . items . length ) . toBeGreaterThan ( 0 ) ;
2747
2746
2748
- combo . filteringOptions = { caseSensitive : true } ;
2747
+ combo . filteringOptions = Object . assign ( { } , combo . filteringOptions , { caseSensitive : true } ) ;
2749
2748
fixture . detectChanges ( ) ;
2750
2749
expect ( combo . dropdown . items . length ) . toEqual ( 0 ) ;
2751
2750
} ) ) ;
2752
- it ( 'Should update filtering when custom filterFunction is provided and filterable is changed ' , fakeAsync ( ( ) => {
2751
+ it ( 'Should update filtering when custom filteringOptions are provided' , fakeAsync ( ( ) => {
2753
2752
combo . open ( ) ;
2754
2753
tick ( ) ;
2755
2754
fixture . detectChanges ( ) ;
@@ -2763,15 +2762,7 @@ describe('igxCombo', () => {
2763
2762
combo . close ( ) ;
2764
2763
tick ( ) ;
2765
2764
fixture . detectChanges ( ) ;
2766
- // set filter function to search only on valueKyes
2767
- combo . filterFunction = ( collection : any [ ] , searchValue : any ) : any [ ] => {
2768
- if ( ! collection ) return [ ] ;
2769
- if ( ! searchValue ) return collection ;
2770
- const searchTerm = combo . filteringOptions . caseSensitive ? searchValue . trim ( ) : searchValue . toLowerCase ( ) . trim ( ) ;
2771
- return collection . filter ( i => combo . filteringOptions . caseSensitive ?
2772
- i [ combo . displayKey ] ?. includes ( searchTerm ) || i [ combo . groupKey ] ?. includes ( searchTerm ) :
2773
- i [ combo . displayKey ] ?. toString ( ) . toLowerCase ( ) . includes ( searchTerm ) || i [ combo . groupKey ] ?. toString ( ) . toLowerCase ( ) . includes ( searchTerm ) )
2774
- }
2765
+ combo . filteringOptions = { caseSensitive : false , filterable : true , filteringKey : combo . groupKey } ;
2775
2766
combo . open ( ) ;
2776
2767
tick ( ) ;
2777
2768
fixture . detectChanges ( ) ;
@@ -2787,7 +2778,7 @@ describe('igxCombo', () => {
2787
2778
fixture . detectChanges ( ) ;
2788
2779
expect ( combo . dropdown . items . length ) . toEqual ( 0 ) ;
2789
2780
2790
- combo . filterable = false ;
2781
+ combo . filteringOptions = Object . assign ( { } , combo . filteringOptions , { filterable : false } ) ;
2791
2782
fixture . detectChanges ( ) ;
2792
2783
expect ( combo . dropdown . items . length ) . toBeGreaterThan ( 0 ) ;
2793
2784
} ) ) ;
0 commit comments