@@ -318,7 +318,7 @@ describe('Search Component', () => {
318318 expect ( searchStore . getState ( ) . selectedIndex ) . toBe ( 0 )
319319 } )
320320
321- it ( 'should move focus to second result on ArrowDown from input (first is already visually selected )' , async ( ) => {
321+ it ( 'should move selection to second result on ArrowDown from input (focus stays on input )' , async ( ) => {
322322 // Arrange
323323 const user = userEvent . setup ( )
324324
@@ -337,9 +337,9 @@ describe('Search Component', () => {
337337
338338 await user . keyboard ( '{ArrowDown}' )
339339
340- // Assert - focus moved to second result (first is already visually selected )
341- const secondResult = screen . getByText ( 'Test Result 2' ) . closest ( 'a' )
342- expect ( secondResult ) . toHaveFocus ( )
340+ // Assert - selection moved to second result, focus stays on input (Pattern B )
341+ expect ( searchStore . getState ( ) . selectedIndex ) . toBe ( 1 )
342+ expect ( input ) . toHaveFocus ( )
343343 } )
344344
345345 it ( 'should move focus between results with ArrowDown/ArrowUp' , async ( ) => {
@@ -372,7 +372,7 @@ describe('Search Component', () => {
372372 expect ( searchStore . getState ( ) . selectedIndex ) . toBe ( 0 )
373373 } )
374374
375- it ( 'should clear selection when ArrowUp from first item goes to input ' , async ( ) => {
375+ it ( 'should stay at first item when ArrowUp from first item (no wrap) ' , async ( ) => {
376376 // Arrange
377377 const user = userEvent . setup ( )
378378
@@ -394,12 +394,12 @@ describe('Search Component', () => {
394394
395395 await user . keyboard ( '{ArrowUp}' )
396396
397- // Assert - focus goes to input, selection is cleared
398- expect ( input ) . toHaveFocus ( )
399- expect ( searchStore . getState ( ) . selectedIndex ) . toBe ( NO_SELECTION )
397+ // Assert - stays at first item (no wrap around)
398+ expect ( firstResult ) . toHaveFocus ( )
399+ expect ( searchStore . getState ( ) . selectedIndex ) . toBe ( 0 )
400400 } )
401401
402- it ( 'should clear selection when ArrowDown from last item goes to button ' , async ( ) => {
402+ it ( 'should stay at last item when ArrowDown from last item (no wrap) ' , async ( ) => {
403403 // Arrange
404404 const user = userEvent . setup ( )
405405
@@ -422,12 +422,9 @@ describe('Search Component', () => {
422422 // Try to go down from last item
423423 await user . keyboard ( '{ArrowDown}' )
424424
425- // Assert - focus moves to button, selection is cleared
426- const button = screen . getByRole ( 'button' , {
427- name : / t e l l m e m o r e a b o u t / i,
428- } )
429- expect ( button ) . toHaveFocus ( )
430- expect ( searchStore . getState ( ) . selectedIndex ) . toBe ( NO_SELECTION )
425+ // Assert - stays at last item (no wrap around)
426+ expect ( lastResult ) . toHaveFocus ( )
427+ expect ( searchStore . getState ( ) . selectedIndex ) . toBe ( 2 )
431428 } )
432429
433430 it ( 'should render isSelected prop on the selected item' , async ( ) => {
0 commit comments