File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -283,4 +283,44 @@ describe('ContextMenu tests', () => {
283283
284284 component . unmount ( ) ;
285285 } ) ;
286+
287+ test ( 'should preserve the selected item after an enter' , ( ) => {
288+ const data = { position : { x : 50 , y : 50 } , id : 'CORRECT_ID' } ;
289+ const onHide = jest . fn ( ) ;
290+ const component = mount (
291+ < ContextMenu id = { data . id } onHide = { onHide } >
292+ < MenuItem onClick = { jest . fn ( ) } preventClose > Item 1</ MenuItem >
293+ < MenuItem divider />
294+ < MenuItem onClick = { jest . fn ( ) } preventClose > Item 2</ MenuItem >
295+ </ ContextMenu >
296+ ) ;
297+ const upArrow = new window . KeyboardEvent ( 'keydown' , { keyCode : 38 } ) ;
298+ const enter = new window . KeyboardEvent ( 'keydown' , { keyCode : 13 } ) ;
299+
300+ showMenu ( data ) ;
301+ // Check that it's visible and there is no selected item at first.
302+ expect ( component . state ( ) ) . toEqual (
303+ Object . assign (
304+ { isVisible : true , forceSubMenuOpen : false , selectedItem : null } ,
305+ data . position
306+ )
307+ ) ;
308+
309+ // Select the second item up arrow.
310+ document . dispatchEvent ( upArrow ) ;
311+ expect ( component . state ( ) . selectedItem ) . toEqual ( {
312+ index : 1 ,
313+ type : MenuItem
314+ } ) ;
315+
316+ // Press enter select it.
317+ document . dispatchEvent ( enter ) ;
318+ // The selected item should be preserved and not reset.
319+ expect ( component . state ( ) . selectedItem ) . toEqual ( {
320+ index : 1 ,
321+ type : MenuItem
322+ } ) ;
323+
324+ component . unmount ( ) ;
325+ } ) ;
286326} ) ;
You can’t perform that action at this time.
0 commit comments