@@ -65,6 +65,8 @@ const CSS_CLASS_INPUT_COSY = 'igx-input-group--cosy';
6565const CSS_CLASS_INPUT_COMPACT = 'igx-input-group--compact' ;
6666const CSS_CLASS_INPUT_COMFORTABLE = 'igx-input-group--comfortable' ;
6767const CSS_CLASS_EMPTY = 'igx-combo__empty' ;
68+ const CSS_CLASS_ITEM_CHECKBOX = 'igx-combo__checkbox' ;
69+ const CSS_CLASS_ITME_CHECKBOX_CHECKED = 'igx-checkbox--checked' ;
6870const defaultDropdownItemHeight = 40 ;
6971const defaultDropdownItemMaxHeight = 400 ;
7072
@@ -1927,12 +1929,19 @@ describe('igxCombo', () => {
19271929 combo = fixture . componentInstance . combo ;
19281930 input = fixture . debugElement . query ( By . css ( `.${ CSS_CLASS_COMBO_INPUTGROUP } ` ) ) ;
19291931 } ) ;
1930- const simulateComboItemCheckboxClick = ( itemIndex : number , isHeader = false ) => {
1932+ const simulateComboItemClick = ( itemIndex : number , isHeader = false ) => {
19311933 const itemClass = isHeader ? CSS_CLASS_HEADERITEM : CSS_CLASS_DROPDOWNLISTITEM ;
19321934 const dropdownItem = fixture . debugElement . queryAll ( By . css ( '.' + itemClass ) ) [ itemIndex ] ;
19331935 dropdownItem . triggerEventHandler ( 'click' , UIInteractions . getMouseEvent ( 'click' ) ) ;
19341936 fixture . detectChanges ( ) ;
19351937 } ;
1938+ const simulateComboItemCheckboxClick = ( itemIndex : number , isHeader = false ) => {
1939+ const itemClass = isHeader ? CSS_CLASS_HEADERITEM : CSS_CLASS_DROPDOWNLISTITEM ;
1940+ const dropdownItem = fixture . debugElement . queryAll ( By . css ( '.' + itemClass ) ) [ itemIndex ] ;
1941+ const itemCheckbox = dropdownItem . query ( By . css ( '.' + CSS_CLASS_ITEM_CHECKBOX ) ) ;
1942+ itemCheckbox . triggerEventHandler ( 'click' , UIInteractions . getMouseEvent ( 'click' ) ) ;
1943+ fixture . detectChanges ( ) ;
1944+ } ;
19361945 it ( 'should append/remove selected items to the input in their selection order' , ( ) => {
19371946 let expectedOutput = 'Illinois' ;
19381947 combo . select ( [ 'Illinois' ] ) ;
@@ -2028,7 +2037,7 @@ describe('igxCombo', () => {
20282037 fixture . detectChanges ( ) ;
20292038
20302039 const selectedItem_1 = dropdown . items [ 1 ] ;
2031- simulateComboItemCheckboxClick ( 1 ) ;
2040+ simulateComboItemClick ( 1 ) ;
20322041 expect ( combo . selection [ 0 ] ) . toEqual ( selectedItem_1 . value . field ) ;
20332042 expect ( selectedItem_1 . selected ) . toBeTruthy ( ) ;
20342043 expect ( selectedItem_1 . element . nativeElement . classList . contains ( CSS_CLASS_SELECTED ) ) . toBeTruthy ( ) ;
@@ -2046,7 +2055,7 @@ describe('igxCombo', () => {
20462055 } ) ;
20472056
20482057 const selectedItem_2 = dropdown . items [ 5 ] ;
2049- simulateComboItemCheckboxClick ( 5 ) ;
2058+ simulateComboItemClick ( 5 ) ;
20502059 expect ( combo . selection [ 1 ] ) . toEqual ( selectedItem_2 . value . field ) ;
20512060 expect ( selectedItem_2 . selected ) . toBeTruthy ( ) ;
20522061 expect ( selectedItem_2 . element . nativeElement . classList . contains ( CSS_CLASS_SELECTED ) ) . toBeTruthy ( ) ;
@@ -2065,7 +2074,7 @@ describe('igxCombo', () => {
20652074
20662075 // Unselecting an item
20672076 const unselectedItem = dropdown . items [ 1 ] ;
2068- simulateComboItemCheckboxClick ( 1 ) ;
2077+ simulateComboItemClick ( 1 ) ;
20692078 expect ( combo . selection . length ) . toEqual ( 1 ) ;
20702079 expect ( unselectedItem . selected ) . toBeFalsy ( ) ;
20712080 expect ( unselectedItem . element . nativeElement . classList . contains ( CSS_CLASS_SELECTED ) ) . toBeFalsy ( ) ;
@@ -2087,10 +2096,26 @@ describe('igxCombo', () => {
20872096 combo . toggle ( ) ;
20882097 fixture . detectChanges ( ) ;
20892098
2090- simulateComboItemCheckboxClick ( 0 , true ) ;
2099+ simulateComboItemClick ( 0 , true ) ;
20912100 expect ( combo . selection . length ) . toEqual ( 0 ) ;
20922101 expect ( combo . selectionChanging . emit ) . toHaveBeenCalledTimes ( 0 ) ;
20932102 } ) ;
2103+ it ( 'should prevent selection when selectionChanging is cancelled' , ( ) => {
2104+ spyOn ( combo . selectionChanging , 'emit' ) . and . callFake ( ( event : IComboSelectionChangingEventArgs ) => event . cancel = true ) ;
2105+ combo . toggle ( ) ;
2106+ fixture . detectChanges ( ) ;
2107+
2108+ const dropdownFirstItem = fixture . debugElement . queryAll ( By . css ( `.${ CSS_CLASS_DROPDOWNLISTITEM } ` ) ) [ 0 ] . nativeElement ;
2109+ const itemCheckbox = dropdownFirstItem . querySelectorAll ( `.${ CSS_CLASS_ITEM_CHECKBOX } ` ) ;
2110+
2111+ simulateComboItemCheckboxClick ( 0 ) ;
2112+ expect ( combo . selection . length ) . toEqual ( 0 ) ;
2113+ expect ( itemCheckbox [ 0 ] . classList . contains ( CSS_CLASS_ITME_CHECKBOX_CHECKED ) ) . toBeFalsy ( ) ;
2114+
2115+ simulateComboItemClick ( 0 ) ;
2116+ expect ( combo . selection . length ) . toEqual ( 0 ) ;
2117+ expect ( itemCheckbox [ 0 ] . classList . contains ( CSS_CLASS_ITME_CHECKBOX_CHECKED ) ) . toBeFalsy ( ) ;
2118+ } ) ;
20942119 } ) ;
20952120 describe ( 'Grouping tests: ' , ( ) => {
20962121 configureTestSuite ( ) ;
0 commit comments