@@ -143,4 +143,24 @@ describe('Discover flyout', function () {
143143 expect ( props . setExpandedDoc ) . toHaveBeenCalledTimes ( 1 ) ;
144144 expect ( props . setExpandedDoc . mock . calls [ 0 ] [ 0 ] . _id ) . toBe ( '4' ) ;
145145 } ) ;
146+
147+ it ( 'allows navigating with arrow keys through documents' , ( ) => {
148+ const props = getProps ( ) ;
149+ const component = mountWithIntl ( < DiscoverGridFlyout { ...props } /> ) ;
150+ findTestSubject ( component , 'docTableDetailsFlyout' ) . simulate ( 'keydown' , { key : 'ArrowRight' } ) ;
151+ expect ( props . setExpandedDoc ) . toHaveBeenCalledWith ( expect . objectContaining ( { _id : '2' } ) ) ;
152+ component . setProps ( { ...props , hit : props . hits [ 1 ] } ) ;
153+ findTestSubject ( component , 'docTableDetailsFlyout' ) . simulate ( 'keydown' , { key : 'ArrowLeft' } ) ;
154+ expect ( props . setExpandedDoc ) . toHaveBeenCalledWith ( expect . objectContaining ( { _id : '1' } ) ) ;
155+ } ) ;
156+
157+ it ( 'should not navigate with keypresses when already at the border of documents' , ( ) => {
158+ const props = getProps ( ) ;
159+ const component = mountWithIntl ( < DiscoverGridFlyout { ...props } /> ) ;
160+ findTestSubject ( component , 'docTableDetailsFlyout' ) . simulate ( 'keydown' , { key : 'ArrowLeft' } ) ;
161+ expect ( props . setExpandedDoc ) . not . toHaveBeenCalled ( ) ;
162+ component . setProps ( { ...props , hit : props . hits [ props . hits . length - 1 ] } ) ;
163+ findTestSubject ( component , 'docTableDetailsFlyout' ) . simulate ( 'keydown' , { key : 'ArrowRight' } ) ;
164+ expect ( props . setExpandedDoc ) . not . toHaveBeenCalled ( ) ;
165+ } ) ;
146166} ) ;
0 commit comments