@@ -76,3 +76,63 @@ test.describe('Search Pages', () => {
7676 await expect ( headerSearchInput ) . toBeFocused ( )
7777 } )
7878} )
79+
80+ test . describe ( 'Keyboard Shortcuts' , ( ) => {
81+ test ( '"c" navigates to /compare' , async ( { page, goto } ) => {
82+ await goto ( '/settings' , { waitUntil : 'hydration' } )
83+
84+ await page . keyboard . press ( 'c' )
85+
86+ await expect ( page ) . toHaveURL ( / \/ c o m p a r e / )
87+ } )
88+
89+ test ( '"c" on package page navigates to /compare with package pre-filled' , async ( {
90+ page,
91+ goto,
92+ } ) => {
93+ await goto ( '/vue' , { waitUntil : 'hydration' } )
94+
95+ await page . keyboard . press ( 'c' )
96+
97+ // Should navigate to /compare with the package in the query
98+ await expect ( page ) . toHaveURL ( / \/ c o m p a r e \? p a c k a g e s = v u e / )
99+ } )
100+
101+ test ( '"c" does not navigate when search input is focused' , async ( { page, goto } ) => {
102+ await goto ( '/settings' , { waitUntil : 'hydration' } )
103+
104+ const searchInput = page . locator ( '#header-search' )
105+ await searchInput . focus ( )
106+ await expect ( searchInput ) . toBeFocused ( )
107+
108+ await page . keyboard . press ( 'c' )
109+
110+ // Should still be on settings, not navigated to compare
111+ await expect ( page ) . toHaveURL ( / \/ s e t t i n g s / )
112+ // The 'c' should have been typed into the input
113+ await expect ( searchInput ) . toHaveValue ( 'c' )
114+ } )
115+
116+ test ( '"," navigates to /settings' , async ( { page, goto } ) => {
117+ await goto ( '/compare' , { waitUntil : 'hydration' } )
118+
119+ await page . keyboard . press ( ',' )
120+
121+ await expect ( page ) . toHaveURL ( / \/ s e t t i n g s / )
122+ } )
123+
124+ test ( '"," does not navigate when search input is focused' , async ( { page, goto } ) => {
125+ await goto ( '/compare' , { waitUntil : 'hydration' } )
126+
127+ const searchInput = page . locator ( '#header-search' )
128+ await searchInput . focus ( )
129+ await expect ( searchInput ) . toBeFocused ( )
130+
131+ await page . keyboard . press ( ',' )
132+
133+ // Should still be on compare, not navigated to settings
134+ await expect ( page ) . toHaveURL ( / \/ c o m p a r e / )
135+ // The ',' should have been typed into the input
136+ await expect ( searchInput ) . toHaveValue ( ',' )
137+ } )
138+ } )
0 commit comments