@@ -7,7 +7,7 @@ import { IgxToggleModule } from '../directives/toggle/toggle.directive';
77import { IgxComboItemComponent } from './combo-item.component' ;
88import { IgxComboComponent , IgxComboModule , IgxComboState , IComboSelectionChangeEventArgs } from './combo.component' ;
99import { IgxComboDropDownComponent } from './combo-dropdown.component' ;
10- import { FormGroup , FormControl , Validators , FormBuilder , ReactiveFormsModule , FormsModule } from '@angular/forms' ;
10+ import { FormGroup , FormControl , Validators , FormBuilder , ReactiveFormsModule , FormsModule , NgControl } from '@angular/forms' ;
1111import { IForOfState } from '../directives/for-of/for_of.directive' ;
1212import { BehaviorSubject , Observable } from 'rxjs' ;
1313import { take } from 'rxjs/operators' ;
@@ -3196,6 +3196,25 @@ describe('igxCombo', () => {
31963196 fixture . detectChanges ( ) ;
31973197 expect ( fixture . componentInstance . comboSelectedItems ) . toEqual ( [ ...data ] . splice ( 1 , 3 ) ) ;
31983198 } ) ) ;
3199+
3200+ it ( 'Should have correctly bound focus and blur handlers' , ( ) => {
3201+ const fixture = TestBed . createComponent ( SimpleBindComboComponent ) ;
3202+ fixture . detectChanges ( ) ;
3203+ const combo = fixture . componentInstance . combo ;
3204+ const input = fixture . debugElement . query ( By . css ( `${ CSS_CLASS_INPUTGROUP } input` ) ) ;
3205+
3206+ spyOn ( combo , 'onFocus' ) ;
3207+ spyOn ( combo , 'onBlur' ) ;
3208+
3209+
3210+ input . triggerEventHandler ( 'focus' , { } ) ;
3211+ expect ( combo . onFocus ) . toHaveBeenCalled ( ) ;
3212+ expect ( combo . onFocus ) . toHaveBeenCalledWith ( ) ;
3213+
3214+ input . triggerEventHandler ( 'blur' , { } ) ;
3215+ expect ( combo . onBlur ) . toHaveBeenCalled ( ) ;
3216+ expect ( combo . onFocus ) . toHaveBeenCalledWith ( ) ;
3217+ } ) ;
31993218 } ) ;
32003219
32013220 describe ( 'Combo - Display Density' , ( ) => {
@@ -3268,6 +3287,65 @@ describe('igxCombo', () => {
32683287 } ) ;
32693288} ) ;
32703289
3290+ describe ( 'Combo ControlValueAccessor Unit' , ( ) => {
3291+ let combo : IgxComboComponent ;
3292+ it ( 'should correctly implement interface methods' , ( ) => {
3293+ const mockSelection : {
3294+ [ key : string ] : jasmine . Spy
3295+ } = jasmine . createSpyObj ( 'IgxSelectionAPIService' , [ 'get' , 'set' , 'add_items' , 'select_items' ] ) ;
3296+ const mockCdr = jasmine . createSpyObj ( 'ChangeDetectorRef' , [ 'markForCheck' ] ) ;
3297+ const mockComboService = jasmine . createSpyObj ( 'IgxComboAPIService' , [ 'register' ] ) ;
3298+ const mockNgControl = jasmine . createSpyObj ( 'NgControl' , [ 'registerOnChangeCb' , 'registerOnTouchedCb' ] ) ;
3299+ const mockInjector = jasmine . createSpyObj ( 'Injector' , {
3300+ 'get' : mockNgControl
3301+ } ) ;
3302+ mockSelection . get . and . returnValue ( new Set ( [ ] ) ) ;
3303+
3304+ // init
3305+ combo = new IgxComboComponent ( { nativeElement : null } , mockCdr , mockSelection as any , mockComboService , null , mockInjector ) ;
3306+ combo . ngOnInit ( ) ;
3307+ expect ( mockInjector . get ) . toHaveBeenCalledWith ( NgControl , null ) ;
3308+ combo . registerOnChange ( mockNgControl . registerOnChangeCb ) ;
3309+ combo . registerOnTouched ( mockNgControl . registerOnTouchedCb ) ;
3310+
3311+ // writeValue
3312+ expect ( combo . value ) . toBe ( '' ) ;
3313+ mockSelection . add_items . and . returnValue ( new Set ( [ 'test' ] ) ) ;
3314+ spyOnProperty ( combo , 'isRemote' ) . and . returnValue ( false ) ;
3315+ combo . writeValue ( [ 'test' ] ) ;
3316+ // TODO: Uncomment after fix for write value going through entire selection process
3317+ // expect(mockNgControl.registerOnChangeCb).not.toHaveBeenCalled();
3318+ expect ( mockSelection . add_items ) . toHaveBeenCalledWith ( combo . id , [ 'test' ] , true ) ;
3319+ expect ( mockSelection . select_items ) . toHaveBeenCalledWith ( combo . id , [ 'test' ] , true ) ;
3320+ expect ( combo . value ) . toBe ( 'test' ) ;
3321+
3322+ // setDisabledState
3323+ combo . setDisabledState ( true ) ;
3324+ expect ( combo . disabled ) . toBe ( true ) ;
3325+ combo . setDisabledState ( false ) ;
3326+ expect ( combo . disabled ) . toBe ( false ) ;
3327+
3328+ // OnChange callback
3329+ mockSelection . add_items . and . returnValue ( new Set ( [ 'simpleValue' ] ) ) ;
3330+ combo . selectItems ( [ 'simpleValue' ] ) ;
3331+ expect ( mockSelection . add_items ) . toHaveBeenCalledWith ( combo . id , [ 'simpleValue' ] , undefined ) ;
3332+ expect ( mockSelection . select_items ) . toHaveBeenCalledWith ( combo . id , [ 'simpleValue' ] , true ) ;
3333+ expect ( mockNgControl . registerOnChangeCb ) . toHaveBeenCalledWith ( [ 'simpleValue' ] ) ;
3334+
3335+ // OnTouched callback
3336+ spyOnProperty ( combo , 'collapsed' ) . and . returnValue ( true ) ;
3337+
3338+ combo . onFocus ( ) ;
3339+ expect ( mockNgControl . registerOnTouchedCb ) . toHaveBeenCalledTimes ( 1 ) ;
3340+
3341+ combo . onBlur ( ) ;
3342+ expect ( mockNgControl . registerOnTouchedCb ) . toHaveBeenCalledTimes ( 2 ) ;
3343+ } ) ;
3344+
3345+ it ( 'should correctly handle ngControl validity' , ( ) => {
3346+ pending ( 'Convert existing form test here' ) ;
3347+ } ) ;
3348+ } ) ;
32713349@Component ( {
32723350 template : `
32733351<igx-combo #combo
0 commit comments