11import { expect , test } from '@nuxt/test-utils/playwright'
22
33test . describe ( 'Search Pages' , ( ) => {
4+ // TODO: these tests depend on external npm registry API - we should add data fixtures
5+ test . describe . configure ( { retries : 2 } )
46 test ( '/search?q=vue → keyboard navigation (arrow keys + enter)' , async ( { page, goto } ) => {
5- await goto ( '/search?q=vue' , { waitUntil : 'domcontentloaded ' } )
7+ await goto ( '/search?q=vue' , { waitUntil : 'hydration ' } )
68
7- await expect ( page . locator ( 'text=/found \\d+/i' ) ) . toBeVisible ( )
9+ await expect ( page . locator ( 'text=/found \\d+|showing \\d+/i' ) . first ( ) ) . toBeVisible ( {
10+ timeout : 15000 ,
11+ } )
812
913 const firstResult = page . locator ( '[data-result-index="0"]' ) . first ( )
1014 await expect ( firstResult ) . toBeVisible ( )
1115
12- const searchInput = page . locator ( 'input[type="search"]' )
13-
14- // ArrowDown changes visual selection but keeps focus in input
16+ // Global keyboard navigation works regardless of focus
17+ // ArrowDown selects the next result
1518 await page . keyboard . press ( 'ArrowDown' )
16- await expect ( searchInput ) . toBeFocused ( )
1719
18- // ArrowUp goes back to first result
20+ // ArrowUp selects the previous result
1921 await page . keyboard . press ( 'ArrowUp' )
20- await expect ( searchInput ) . toBeFocused ( )
2122
22- // First result is selected, Enter navigates to it
23+ // Enter navigates to the selected result
2324 // URL is /vue not /package/vue (cleaner URLs)
2425 await page . keyboard . press ( 'Enter' )
2526 await expect ( page ) . toHaveURL ( / \/ v u e / )
2627 } )
2728
2829 test ( '/search?q=vue → "/" focuses the search input from results' , async ( { page, goto } ) => {
29- await goto ( '/search?q=vue' , { waitUntil : 'domcontentloaded ' } )
30+ await goto ( '/search?q=vue' , { waitUntil : 'hydration ' } )
3031
31- await expect ( page . locator ( 'text=/found \\d+/i' ) ) . toBeVisible ( )
32+ await expect ( page . locator ( 'text=/found \\d+|showing \\d+/i' ) . first ( ) ) . toBeVisible ( {
33+ timeout : 15000 ,
34+ } )
3235
3336 await page . locator ( '[data-result-index="0"]' ) . first ( ) . focus ( )
3437 await page . keyboard . press ( '/' )
3538 await expect ( page . locator ( 'input[type="search"]' ) ) . toBeFocused ( )
3639 } )
3740
3841 test ( '/ (homepage) → search, keeps focus on search input' , async ( { page, goto } ) => {
39- await goto ( '/' , { waitUntil : 'domcontentloaded ' } )
42+ await goto ( '/' , { waitUntil : 'hydration ' } )
4043
4144 const homeSearchInput = page . locator ( '#home-search' )
4245 await homeSearchInput . click ( )
4346 await page . keyboard . type ( 'vue' )
4447
4548 // Wait for navigation to /search (debounce is 250ms)
4649 await expect ( page ) . toHaveURL ( / \/ s e a r c h / , { timeout : 10000 } )
47- await expect ( page . locator ( 'text=/found \\d+/i' ) ) . toBeVisible ( { timeout : 15000 } )
50+
51+ await expect ( page . locator ( '[data-result-index="0"]' ) . first ( ) ) . toBeVisible ( { timeout : 15000 } )
4852
4953 // Home search input should be gone (we're on /search now)
5054 await expect ( homeSearchInput ) . not . toBeVisible ( )
@@ -56,15 +60,19 @@ test.describe('Search Pages', () => {
5660 } )
5761
5862 test ( '/settings → search, keeps focus on search input' , async ( { page, goto } ) => {
59- await goto ( '/settings' , { waitUntil : 'domcontentloaded ' } )
63+ await goto ( '/settings' , { waitUntil : 'hydration ' } )
6064
6165 const searchInput = page . locator ( 'input[type="search"]' )
66+ await expect ( searchInput ) . toBeVisible ( )
67+
68+ await searchInput . click ( )
6269 await searchInput . fill ( 'vue' )
6370
64- await page . waitForURL ( / \/ s e a r c h / )
71+ await expect ( page ) . toHaveURL ( / \/ s e a r c h / , { timeout : 10000 } )
6572
66- await expect ( page . locator ( 'text=/found \\d+/i' ) ) . toBeVisible ( )
73+ await expect ( page . locator ( '[data-result-index="0"]' ) . first ( ) ) . toBeVisible ( { timeout : 15000 } )
6774
68- await expect ( searchInput ) . toBeFocused ( )
75+ const headerSearchInput = page . locator ( '#header-search' )
76+ await expect ( headerSearchInput ) . toBeFocused ( )
6977 } )
7078} )
0 commit comments