@@ -18,6 +18,7 @@ import { configureTestSuite } from '../test-utils/configure-suite';
18
18
import { DisplayDensity } from '../core/density' ;
19
19
import { AbsoluteScrollStrategy , ConnectedPositioningStrategy } from '../services/public_api' ;
20
20
import { IgxSelectionAPIService } from '../core/selection' ;
21
+ import { CancelableEventArgs } from '../core/utils' ;
21
22
22
23
const CSS_CLASS_COMBO = 'igx-combo' ;
23
24
const CSS_CLASS_COMBO_DROPDOWN = 'igx-combo__drop-down' ;
@@ -530,21 +531,41 @@ describe('igxCombo', () => {
530
531
expect ( matchSpy ) . toHaveBeenCalledTimes ( 1 ) ;
531
532
expect ( combo . onSearchInput . emit ) . toHaveBeenCalledTimes ( 0 ) ;
532
533
534
+ const args = {
535
+ change : 'Fake' ,
536
+ cancel : false
537
+ } ;
533
538
combo . handleInputChange ( 'Fake' ) ;
534
539
expect ( matchSpy ) . toHaveBeenCalledTimes ( 2 ) ;
535
540
expect ( combo . onSearchInput . emit ) . toHaveBeenCalledTimes ( 1 ) ;
536
- expect ( combo . onSearchInput . emit ) . toHaveBeenCalledWith ( 'Fake' ) ;
541
+ expect ( combo . onSearchInput . emit ) . toHaveBeenCalledWith ( args ) ;
537
542
543
+ args . change = '' ;
538
544
combo . handleInputChange ( '' ) ;
539
545
expect ( matchSpy ) . toHaveBeenCalledTimes ( 3 ) ;
540
546
expect ( combo . onSearchInput . emit ) . toHaveBeenCalledTimes ( 2 ) ;
541
- expect ( combo . onSearchInput . emit ) . toHaveBeenCalledWith ( '' ) ;
547
+ expect ( combo . onSearchInput . emit ) . toHaveBeenCalledWith ( args ) ;
542
548
543
549
combo . filterable = false ;
544
550
combo . handleInputChange ( ) ;
545
551
expect ( matchSpy ) . toHaveBeenCalledTimes ( 4 ) ;
546
552
expect ( combo . onSearchInput . emit ) . toHaveBeenCalledTimes ( 2 ) ;
547
553
} ) ;
554
+ it ( 'should be able to cancel onSearchInput' , ( ) => {
555
+ combo = new IgxComboComponent ( { nativeElement : null } , mockCdr , mockSelection as any , mockComboService , null , mockInjector ) ;
556
+ combo . ngOnInit ( ) ;
557
+ combo . data = data ;
558
+ combo . filterable = true ;
559
+ combo . onSearchInput . subscribe ( ( e ) => {
560
+ e . cancel = true ;
561
+ } ) ;
562
+ const matchSpy = spyOn < any > ( combo , 'checkMatch' ) . and . callThrough ( ) ;
563
+ spyOn ( combo . onSearchInput , 'emit' ) . and . callThrough ( ) ;
564
+
565
+ combo . handleInputChange ( 'Item1' ) ;
566
+ expect ( combo . onSearchInput . emit ) . toHaveBeenCalledTimes ( 1 ) ;
567
+ expect ( matchSpy ) . toHaveBeenCalledTimes ( 0 ) ;
568
+ } ) ;
548
569
} ) ;
549
570
describe ( 'Initialization and rendering tests: ' , ( ) => {
550
571
configureTestSuite ( ) ;
0 commit comments