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' ;
36import { By } from '@angular/platform-browser' ;
47import { 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' ;
218import { BehaviorSubject , Observable } from 'rxjs' ;
229import { take } from 'rxjs/operators' ;
23- import { UIInteractions , wait } from '../test-utils/ui-interactions.spec' ;
24- import { configureTestSuite } from '../test-utils/configure-suite' ;
2510import { DisplayDensity } from '../core/density' ;
26- import { AbsoluteScrollStrategy , ConnectedPositioningStrategy } from '../services/public_api' ;
2711import { IgxSelectionAPIService } from '../core/selection' ;
28- import { IgxIconService } from '../icon/public_api' ;
2912import { IBaseCancelableBrowserEventArgs } from '../core/utils' ;
3013import { 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' ;
3217import { 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' ;
3331
3432const CSS_CLASS_COMBO = 'igx-combo' ;
3533const CSS_CLASS_COMBO_DROPDOWN = 'igx-combo__drop-down' ;
@@ -2689,14 +2687,14 @@ describe('igxCombo', () => {
26892687 combo . close ( ) ;
26902688 tick ( ) ;
26912689 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 [ ] => {
26942692 if ( ! collection ) return [ ] ;
26952693 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 ) )
27002698 }
27012699 combo . open ( ) ;
27022700 tick ( ) ;
@@ -2708,11 +2706,12 @@ describe('igxCombo', () => {
27082706 fixture . detectChanges ( ) ;
27092707 expect ( combo . dropdown . items . length ) . toBeGreaterThan ( 0 ) ;
27102708
2711- combo . filterFunction = null ;
2709+ combo . filterFunction = undefined ;
2710+ combo . filteringOptions = undefined ;
27122711 fixture . detectChanges ( ) ;
27132712 expect ( combo . dropdown . items . length ) . toEqual ( 0 ) ;
27142713 } ) ) ;
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 ( ( ) => {
27162715 combo . open ( ) ;
27172716 tick ( ) ;
27182717 fixture . detectChanges ( ) ;
@@ -2726,14 +2725,14 @@ describe('igxCombo', () => {
27262725 combo . close ( ) ;
27272726 tick ( ) ;
27282727 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 [ ] => {
27312730 if ( ! collection ) return [ ] ;
27322731 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 ) )
27372736 }
27382737 combo . open ( ) ;
27392738 tick ( ) ;
@@ -2745,11 +2744,11 @@ describe('igxCombo', () => {
27452744 fixture . detectChanges ( ) ;
27462745 expect ( combo . dropdown . items . length ) . toBeGreaterThan ( 0 ) ;
27472746
2748- combo . filteringOptions = { caseSensitive : true } ;
2747+ combo . filteringOptions = Object . assign ( { } , combo . filteringOptions , { caseSensitive : true } ) ;
27492748 fixture . detectChanges ( ) ;
27502749 expect ( combo . dropdown . items . length ) . toEqual ( 0 ) ;
27512750 } ) ) ;
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 ( ( ) => {
27532752 combo . open ( ) ;
27542753 tick ( ) ;
27552754 fixture . detectChanges ( ) ;
@@ -2763,15 +2762,7 @@ describe('igxCombo', () => {
27632762 combo . close ( ) ;
27642763 tick ( ) ;
27652764 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 } ;
27752766 combo . open ( ) ;
27762767 tick ( ) ;
27772768 fixture . detectChanges ( ) ;
@@ -2787,7 +2778,7 @@ describe('igxCombo', () => {
27872778 fixture . detectChanges ( ) ;
27882779 expect ( combo . dropdown . items . length ) . toEqual ( 0 ) ;
27892780
2790- combo . filterable = false ;
2781+ combo . filteringOptions = Object . assign ( { } , combo . filteringOptions , { filterable : false } ) ;
27912782 fixture . detectChanges ( ) ;
27922783 expect ( combo . dropdown . items . length ) . toBeGreaterThan ( 0 ) ;
27932784 } ) ) ;
0 commit comments