@@ -102,15 +102,19 @@ test.describe('Search Pages', () => {
102102 const firstResult = page . locator ( '[data-result-index="0"]' ) . first ( )
103103 await expect ( firstResult ) . toBeVisible ( )
104104
105- // Global keyboard navigation works regardless of focus
106- // ArrowDown selects the next result
105+ // Wait for the @vue org suggestion card to appear
106+ const orgSuggestion = page . locator ( '[data-suggestion-index="0"]' )
107+ await expect ( orgSuggestion ) . toBeVisible ( { timeout : 10000 } )
108+
109+ // ArrowDown focuses the org suggestion card
107110 await page . keyboard . press ( 'ArrowDown' )
108111
109- // ArrowUp selects the previous result
112+ // ArrowUp returns to the search input
110113 await page . keyboard . press ( 'ArrowUp' )
111114
112- // Enter navigates to the selected result
115+ // ArrowDown again, then Enter navigates to the suggestion
113116 // URL is /package/vue or /org/vue or /user/vue. Not /vue
117+ await page . keyboard . press ( 'ArrowDown' )
114118 await page . keyboard . press ( 'Enter' )
115119 await expect ( page ) . toHaveURL ( / \/ ( p a c k a g e | o r g | u s e r ) \/ v u e / )
116120 } )
@@ -130,16 +134,24 @@ test.describe('Search Pages', () => {
130134 await expect ( firstResult ) . toBeVisible ( )
131135 await expect ( secondResult ) . toBeVisible ( )
132136
133- // ArrowDown from input focuses the first result
137+ // Wait for the @vue org suggestion card to appear
138+ const orgSuggestion = page . locator ( '[data-suggestion-index="0"]' )
139+ await expect ( orgSuggestion ) . toBeVisible ( { timeout : 10000 } )
140+
141+ // ArrowDown focuses the org suggestion first
142+ await page . keyboard . press ( 'ArrowDown' )
143+ await expect ( orgSuggestion ) . toBeFocused ( )
144+
145+ // Next ArrowDown focuses the first package result
134146 await page . keyboard . press ( 'ArrowDown' )
135147 await expect ( firstResult ) . toBeFocused ( )
136148
137- // Second ArrowDown focuses the second result (not a keyword button within the first)
149+ // Next ArrowDown focuses the second result (not a keyword button within the first)
138150 await page . keyboard . press ( 'ArrowDown' )
139151 await expect ( secondResult ) . toBeFocused ( )
140152 } )
141153
142- test ( '/search?q=vue → ArrowUp from first result returns focus to search input' , async ( {
154+ test ( '/search?q=vue → ArrowUp from first result navigates back through suggestions to input' , async ( {
143155 page,
144156 goto,
145157 } ) => {
@@ -149,11 +161,22 @@ test.describe('Search Pages', () => {
149161 timeout : 15000 ,
150162 } )
151163
152- // Navigate to first result
164+ // Wait for the @vue org suggestion card to appear
165+ const orgSuggestion = page . locator ( '[data-suggestion-index="0"]' )
166+ await expect ( orgSuggestion ) . toBeVisible ( { timeout : 10000 } )
167+
168+ // Navigate: suggestion → first package result
169+ await page . keyboard . press ( 'ArrowDown' )
170+ await expect ( orgSuggestion ) . toBeFocused ( )
171+
153172 await page . keyboard . press ( 'ArrowDown' )
154173 await expect ( page . locator ( '[data-result-index="0"]' ) . first ( ) ) . toBeFocused ( )
155174
156- // ArrowUp returns to the search input
175+ // ArrowUp goes back to the org suggestion
176+ await page . keyboard . press ( 'ArrowUp' )
177+ await expect ( orgSuggestion ) . toBeFocused ( )
178+
179+ // ArrowUp from suggestion returns to the search input
157180 await page . keyboard . press ( 'ArrowUp' )
158181 await expect ( page . locator ( 'input[type="search"]' ) ) . toBeFocused ( )
159182 } )
0 commit comments