@@ -65,6 +65,8 @@ const CSS_CLASS_INPUT_COSY = 'igx-input-group--cosy';
65
65
const CSS_CLASS_INPUT_COMPACT = 'igx-input-group--compact' ;
66
66
const CSS_CLASS_INPUT_COMFORTABLE = 'igx-input-group--comfortable' ;
67
67
const 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' ;
68
70
const defaultDropdownItemHeight = 40 ;
69
71
const defaultDropdownItemMaxHeight = 400 ;
70
72
@@ -1927,12 +1929,19 @@ describe('igxCombo', () => {
1927
1929
combo = fixture . componentInstance . combo ;
1928
1930
input = fixture . debugElement . query ( By . css ( `.${ CSS_CLASS_COMBO_INPUTGROUP } ` ) ) ;
1929
1931
} ) ;
1930
- const simulateComboItemCheckboxClick = ( itemIndex : number , isHeader = false ) => {
1932
+ const simulateComboItemClick = ( itemIndex : number , isHeader = false ) => {
1931
1933
const itemClass = isHeader ? CSS_CLASS_HEADERITEM : CSS_CLASS_DROPDOWNLISTITEM ;
1932
1934
const dropdownItem = fixture . debugElement . queryAll ( By . css ( '.' + itemClass ) ) [ itemIndex ] ;
1933
1935
dropdownItem . triggerEventHandler ( 'click' , UIInteractions . getMouseEvent ( 'click' ) ) ;
1934
1936
fixture . detectChanges ( ) ;
1935
1937
} ;
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
+ } ;
1936
1945
it ( 'should append/remove selected items to the input in their selection order' , ( ) => {
1937
1946
let expectedOutput = 'Illinois' ;
1938
1947
combo . select ( [ 'Illinois' ] ) ;
@@ -2028,7 +2037,7 @@ describe('igxCombo', () => {
2028
2037
fixture . detectChanges ( ) ;
2029
2038
2030
2039
const selectedItem_1 = dropdown . items [ 1 ] ;
2031
- simulateComboItemCheckboxClick ( 1 ) ;
2040
+ simulateComboItemClick ( 1 ) ;
2032
2041
expect ( combo . selection [ 0 ] ) . toEqual ( selectedItem_1 . value . field ) ;
2033
2042
expect ( selectedItem_1 . selected ) . toBeTruthy ( ) ;
2034
2043
expect ( selectedItem_1 . element . nativeElement . classList . contains ( CSS_CLASS_SELECTED ) ) . toBeTruthy ( ) ;
@@ -2046,7 +2055,7 @@ describe('igxCombo', () => {
2046
2055
} ) ;
2047
2056
2048
2057
const selectedItem_2 = dropdown . items [ 5 ] ;
2049
- simulateComboItemCheckboxClick ( 5 ) ;
2058
+ simulateComboItemClick ( 5 ) ;
2050
2059
expect ( combo . selection [ 1 ] ) . toEqual ( selectedItem_2 . value . field ) ;
2051
2060
expect ( selectedItem_2 . selected ) . toBeTruthy ( ) ;
2052
2061
expect ( selectedItem_2 . element . nativeElement . classList . contains ( CSS_CLASS_SELECTED ) ) . toBeTruthy ( ) ;
@@ -2065,7 +2074,7 @@ describe('igxCombo', () => {
2065
2074
2066
2075
// Unselecting an item
2067
2076
const unselectedItem = dropdown . items [ 1 ] ;
2068
- simulateComboItemCheckboxClick ( 1 ) ;
2077
+ simulateComboItemClick ( 1 ) ;
2069
2078
expect ( combo . selection . length ) . toEqual ( 1 ) ;
2070
2079
expect ( unselectedItem . selected ) . toBeFalsy ( ) ;
2071
2080
expect ( unselectedItem . element . nativeElement . classList . contains ( CSS_CLASS_SELECTED ) ) . toBeFalsy ( ) ;
@@ -2087,10 +2096,26 @@ describe('igxCombo', () => {
2087
2096
combo . toggle ( ) ;
2088
2097
fixture . detectChanges ( ) ;
2089
2098
2090
- simulateComboItemCheckboxClick ( 0 , true ) ;
2099
+ simulateComboItemClick ( 0 , true ) ;
2091
2100
expect ( combo . selection . length ) . toEqual ( 0 ) ;
2092
2101
expect ( combo . selectionChanging . emit ) . toHaveBeenCalledTimes ( 0 ) ;
2093
2102
} ) ;
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
+ } ) ;
2094
2119
} ) ;
2095
2120
describe ( 'Grouping tests: ' , ( ) => {
2096
2121
configureTestSuite ( ) ;
0 commit comments