@@ -177,6 +177,7 @@ describe('useComboBoxState tests', function () {
177
177
expect ( result . current . selectionManager . selectedKeys ) . toContain ( '0' ) ;
178
178
expect ( result . current . selectionManager . selectedKeys ) . not . toContain ( '1' ) ;
179
179
180
+ act ( ( ) => { result . current . open ( ) ; } ) ;
180
181
act ( ( ) => result . current . selectionManager . replaceSelection ( '1' ) ) ;
181
182
expect ( result . current . selectionManager . selectedKeys ) . toContain ( '0' ) ;
182
183
expect ( result . current . selectionManager . selectedKeys ) . not . toContain ( '1' ) ;
@@ -190,22 +191,34 @@ describe('useComboBoxState tests', function () {
190
191
expect ( result . current . selectionManager . selectedKeys ) . toContain ( '0' ) ;
191
192
expect ( result . current . selectionManager . selectedKeys ) . not . toContain ( '1' ) ;
192
193
194
+ act ( ( ) => { result . current . open ( ) ; } ) ;
193
195
act ( ( ) => result . current . selectionManager . replaceSelection ( '1' ) ) ;
194
196
expect ( result . current . selectionManager . selectedKeys ) . toContain ( '1' ) ;
195
197
expect ( result . current . selectionManager . selectedKeys ) . not . toContain ( '0' ) ;
196
198
expect ( onSelectionChange ) . toHaveBeenCalledWith ( '1' ) ;
197
199
} ) ;
198
200
199
- it ( 'supports sdefault no selection' , function ( ) {
201
+ it ( 'supports default no selection' , function ( ) {
200
202
let initialProps = { ...defaultProps } ;
201
203
let { result} = renderHook ( ( props ) => useComboBoxState ( props ) , { initialProps} ) ;
202
204
expect ( result . current . selectionManager . selectionMode ) . toBe ( 'single' ) ;
203
205
expect ( result . current . selectionManager . selectedKeys . size ) . toBe ( 0 ) ;
204
206
207
+ act ( ( ) => { result . current . open ( ) ; } ) ;
205
208
act ( ( ) => result . current . selectionManager . replaceSelection ( '1' ) ) ;
206
209
expect ( result . current . selectionManager . selectedKeys ) . toContain ( '1' ) ;
207
210
expect ( result . current . selectionManager . selectedKeys ) . not . toContain ( '0' ) ;
208
211
expect ( onSelectionChange ) . toHaveBeenCalledWith ( '1' ) ;
209
212
} ) ;
213
+
214
+ it ( 'won\'t perform replace a selection if the combobox is closed' , function ( ) {
215
+ // This case covers if a option in the menu is clicked while the menu is closing
216
+ let initialProps = { ...defaultProps } ;
217
+ let { result} = renderHook ( ( props ) => useComboBoxState ( props ) , { initialProps} ) ;
218
+
219
+ act ( ( ) => result . current . selectionManager . replaceSelection ( '1' ) ) ;
220
+ expect ( result . current . selectionManager . selectedKeys . size ) . toEqual ( 0 ) ;
221
+ expect ( onSelectionChange ) . toHaveBeenCalledTimes ( 0 ) ;
222
+ } ) ;
210
223
} ) ;
211
224
} ) ;
0 commit comments