@@ -6,7 +6,7 @@ import { IgxToggleModule } from '../directives/toggle/toggle.directive';
66import { IgxComboItemComponent } from './combo-item.component' ;
77import { IgxComboComponent , IgxComboModule , IComboSelectionChangeEventArgs , IgxComboState } from './combo.component' ;
88import { IgxComboDropDownComponent } from './combo-dropdown.component' ;
9- import { FormGroup , FormControl , Validators , FormBuilder , ReactiveFormsModule , FormsModule } from '@angular/forms' ;
9+ import { FormGroup , FormControl , Validators , FormBuilder , ReactiveFormsModule , FormsModule , NgControl } from '@angular/forms' ;
1010import { IForOfState } from '../directives/for-of/for_of.directive' ;
1111import { BehaviorSubject , Observable } from 'rxjs' ;
1212import { take } from 'rxjs/operators' ;
@@ -3250,6 +3250,25 @@ describe('igxCombo', () => {
32503250 fixture . detectChanges ( ) ;
32513251 expect ( component . selectedItems ) . toEqual ( [ combo . data [ 0 ] , combo . data [ 2 ] , combo . data [ 4 ] ] ) ;
32523252 } ) ) ;
3253+
3254+ it ( 'Should have correctly bound focus and blur handlers' , ( ) => {
3255+ const fixture = TestBed . createComponent ( IgxComboInTemplatedFormComponent ) ;
3256+ fixture . detectChanges ( ) ;
3257+ const combo = fixture . componentInstance . testCombo ;
3258+ const input = fixture . debugElement . query ( By . css ( `${ CSS_CLASS_INPUTGROUP } input` ) ) ;
3259+
3260+ spyOn ( combo , 'onFocus' ) ;
3261+ spyOn ( combo , 'onBlur' ) ;
3262+
3263+
3264+ input . triggerEventHandler ( 'focus' , { } ) ;
3265+ expect ( combo . onFocus ) . toHaveBeenCalled ( ) ;
3266+ expect ( combo . onFocus ) . toHaveBeenCalledWith ( ) ;
3267+
3268+ input . triggerEventHandler ( 'blur' , { } ) ;
3269+ expect ( combo . onBlur ) . toHaveBeenCalled ( ) ;
3270+ expect ( combo . onFocus ) . toHaveBeenCalledWith ( ) ;
3271+ } ) ;
32533272 } ) ;
32543273
32553274 describe ( 'Combo - Display Density' , ( ) => {
@@ -3322,6 +3341,66 @@ describe('igxCombo', () => {
33223341 } ) ;
33233342} ) ;
33243343
3344+ describe ( 'Combo ControlValueAccessor Unit' , ( ) => {
3345+ let combo : IgxComboComponent ;
3346+ it ( 'should correctly implement interface methods' , ( ) => {
3347+ const mockSelection : {
3348+ [ key : string ] : jasmine . Spy
3349+ } = jasmine . createSpyObj ( 'IgxSelectionAPIService' , [ 'get' , 'set' , 'add_items' , 'select_items' ] ) ;
3350+ const mockCdr = jasmine . createSpyObj ( 'ChangeDetectorRef' , [ 'markForCheck' ] ) ;
3351+ const mockComboService = jasmine . createSpyObj ( 'IgxComboAPIService' , [ 'register' ] ) ;
3352+ const mockNgControl = jasmine . createSpyObj ( 'NgControl' , [ 'registerOnChangeCb' , 'registerOnTouchedCb' ] ) ;
3353+ const mockInjector = jasmine . createSpyObj ( 'Injector' , {
3354+ 'get' : mockNgControl
3355+ } ) ;
3356+ mockSelection . get . and . returnValue ( new Set ( [ ] ) ) ;
3357+
3358+ // init
3359+ combo = new IgxComboComponent ( { nativeElement : null } , mockCdr , mockSelection as any , mockComboService , null , mockInjector ) ;
3360+ combo . ngOnInit ( ) ;
3361+ expect ( mockInjector . get ) . toHaveBeenCalledWith ( NgControl , null ) ;
3362+ combo . registerOnChange ( mockNgControl . registerOnChangeCb ) ;
3363+ combo . registerOnTouched ( mockNgControl . registerOnTouchedCb ) ;
3364+
3365+ // writeValue
3366+ expect ( combo . value ) . toBe ( '' ) ;
3367+ mockSelection . add_items . and . returnValue ( new Set ( [ 'test' ] ) ) ;
3368+ spyOnProperty ( combo , 'isRemote' ) . and . returnValue ( false ) ;
3369+ combo . writeValue ( [ 'test' ] ) ;
3370+ // TODO: Uncomment after fix for write value going through entire selection process
3371+ // expect(mockNgControl.registerOnChangeCb).not.toHaveBeenCalled();
3372+ expect ( mockSelection . add_items ) . toHaveBeenCalledWith ( combo . id , [ 'test' ] , true ) ;
3373+ expect ( mockSelection . select_items ) . toHaveBeenCalledWith ( combo . id , [ 'test' ] , true ) ;
3374+ expect ( combo . value ) . toBe ( 'test' ) ;
3375+
3376+ // setDisabledState
3377+ combo . setDisabledState ( true ) ;
3378+ expect ( combo . disabled ) . toBe ( true ) ;
3379+ combo . setDisabledState ( false ) ;
3380+ expect ( combo . disabled ) . toBe ( false ) ;
3381+
3382+ // OnChange callback
3383+ mockSelection . add_items . and . returnValue ( new Set ( [ 'simpleValue' ] ) ) ;
3384+ combo . selectItems ( [ 'simpleValue' ] ) ;
3385+ expect ( mockSelection . add_items ) . toHaveBeenCalledWith ( combo . id , [ 'simpleValue' ] , undefined ) ;
3386+ expect ( mockSelection . select_items ) . toHaveBeenCalledWith ( combo . id , [ 'simpleValue' ] , true ) ;
3387+ expect ( mockNgControl . registerOnChangeCb ) . toHaveBeenCalledWith ( [ 'simpleValue' ] ) ;
3388+
3389+ // OnTouched callback
3390+ spyOnProperty ( combo , 'collapsed' ) . and . returnValue ( true ) ;
3391+ spyOnProperty ( combo , 'valid' , 'set' ) ;
3392+
3393+ combo . onFocus ( ) ;
3394+ expect ( mockNgControl . registerOnTouchedCb ) . toHaveBeenCalledTimes ( 1 ) ;
3395+
3396+ combo . onBlur ( ) ;
3397+ expect ( mockNgControl . registerOnTouchedCb ) . toHaveBeenCalledTimes ( 2 ) ;
3398+ } ) ;
3399+
3400+ it ( 'should correctly handle ngControl validity' , ( ) => {
3401+ pending ( 'Convert existing form test here' ) ;
3402+ } ) ;
3403+ } ) ;
33253404@Component ( {
33263405 template : `
33273406<igx-combo #combo
0 commit comments