@@ -7,7 +7,7 @@ import { IgxToggleModule } from '../directives/toggle/toggle.directive';
77import { IgxComboItemComponent } from './combo-item.component' ;
88import { IgxComboComponent , IgxComboModule , IComboSelectionChangeEventArgs , IgxComboState } 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' ;
@@ -3302,6 +3302,25 @@ describe('igxCombo', () => {
33023302 fixture . detectChanges ( ) ;
33033303 expect ( component . selectedItems ) . toEqual ( [ combo . data [ 0 ] , combo . data [ 2 ] , combo . data [ 4 ] ] ) ;
33043304 } ) ) ;
3305+
3306+ it ( 'Should have correctly bound focus and blur handlers' , ( ) => {
3307+ const fixture = TestBed . createComponent ( IgxComboInTemplatedFormComponent ) ;
3308+ fixture . detectChanges ( ) ;
3309+ const combo = fixture . componentInstance . testCombo ;
3310+ const input = fixture . debugElement . query ( By . css ( `${ CSS_CLASS_INPUTGROUP } input` ) ) ;
3311+
3312+ spyOn ( combo , 'onFocus' ) ;
3313+ spyOn ( combo , 'onBlur' ) ;
3314+
3315+
3316+ input . triggerEventHandler ( 'focus' , { } ) ;
3317+ expect ( combo . onFocus ) . toHaveBeenCalled ( ) ;
3318+ expect ( combo . onFocus ) . toHaveBeenCalledWith ( ) ;
3319+
3320+ input . triggerEventHandler ( 'blur' , { } ) ;
3321+ expect ( combo . onBlur ) . toHaveBeenCalled ( ) ;
3322+ expect ( combo . onFocus ) . toHaveBeenCalledWith ( ) ;
3323+ } ) ;
33053324 } ) ;
33063325
33073326 describe ( 'Combo - Display Density' , ( ) => {
@@ -3374,6 +3393,66 @@ describe('igxCombo', () => {
33743393 } ) ;
33753394} ) ;
33763395
3396+ describe ( 'Combo ControlValueAccessor Unit' , ( ) => {
3397+ let combo : IgxComboComponent ;
3398+ it ( 'should correctly implement interface methods' , ( ) => {
3399+ const mockSelection : {
3400+ [ key : string ] : jasmine . Spy
3401+ } = jasmine . createSpyObj ( 'IgxSelectionAPIService' , [ 'get' , 'set' , 'add_items' , 'select_items' ] ) ;
3402+ const mockCdr = jasmine . createSpyObj ( 'ChangeDetectorRef' , [ 'markForCheck' ] ) ;
3403+ const mockComboService = jasmine . createSpyObj ( 'IgxComboAPIService' , [ 'register' ] ) ;
3404+ const mockNgControl = jasmine . createSpyObj ( 'NgControl' , [ 'registerOnChangeCb' , 'registerOnTouchedCb' ] ) ;
3405+ const mockInjector = jasmine . createSpyObj ( 'Injector' , {
3406+ 'get' : mockNgControl
3407+ } ) ;
3408+ mockSelection . get . and . returnValue ( new Set ( [ ] ) ) ;
3409+
3410+ // init
3411+ combo = new IgxComboComponent ( { nativeElement : null } , mockCdr , mockSelection as any , mockComboService , null , mockInjector ) ;
3412+ combo . ngOnInit ( ) ;
3413+ expect ( mockInjector . get ) . toHaveBeenCalledWith ( NgControl , null ) ;
3414+ combo . registerOnChange ( mockNgControl . registerOnChangeCb ) ;
3415+ combo . registerOnTouched ( mockNgControl . registerOnTouchedCb ) ;
3416+
3417+ // writeValue
3418+ expect ( combo . value ) . toBe ( '' ) ;
3419+ mockSelection . add_items . and . returnValue ( new Set ( [ 'test' ] ) ) ;
3420+ spyOnProperty ( combo , 'isRemote' ) . and . returnValue ( false ) ;
3421+ combo . writeValue ( [ 'test' ] ) ;
3422+ // TODO: Uncomment after fix for write value going through entire selection process
3423+ // expect(mockNgControl.registerOnChangeCb).not.toHaveBeenCalled();
3424+ expect ( mockSelection . add_items ) . toHaveBeenCalledWith ( combo . id , [ 'test' ] , true ) ;
3425+ expect ( mockSelection . select_items ) . toHaveBeenCalledWith ( combo . id , [ 'test' ] , true ) ;
3426+ expect ( combo . value ) . toBe ( 'test' ) ;
3427+
3428+ // setDisabledState
3429+ combo . setDisabledState ( true ) ;
3430+ expect ( combo . disabled ) . toBe ( true ) ;
3431+ combo . setDisabledState ( false ) ;
3432+ expect ( combo . disabled ) . toBe ( false ) ;
3433+
3434+ // OnChange callback
3435+ mockSelection . add_items . and . returnValue ( new Set ( [ 'simpleValue' ] ) ) ;
3436+ combo . selectItems ( [ 'simpleValue' ] ) ;
3437+ expect ( mockSelection . add_items ) . toHaveBeenCalledWith ( combo . id , [ 'simpleValue' ] , undefined ) ;
3438+ expect ( mockSelection . select_items ) . toHaveBeenCalledWith ( combo . id , [ 'simpleValue' ] , true ) ;
3439+ expect ( mockNgControl . registerOnChangeCb ) . toHaveBeenCalledWith ( [ 'simpleValue' ] ) ;
3440+
3441+ // OnTouched callback
3442+ spyOnProperty ( combo , 'collapsed' ) . and . returnValue ( true ) ;
3443+ spyOnProperty ( combo , 'valid' , 'set' ) ;
3444+
3445+ combo . onFocus ( ) ;
3446+ expect ( mockNgControl . registerOnTouchedCb ) . toHaveBeenCalledTimes ( 1 ) ;
3447+
3448+ combo . onBlur ( ) ;
3449+ expect ( mockNgControl . registerOnTouchedCb ) . toHaveBeenCalledTimes ( 2 ) ;
3450+ } ) ;
3451+
3452+ it ( 'should correctly handle ngControl validity' , ( ) => {
3453+ pending ( 'Convert existing form test here' ) ;
3454+ } ) ;
3455+ } ) ;
33773456@Component ( {
33783457 template : `
33793458<igx-combo #combo
0 commit comments