Skip to content

Commit 1e88684

Browse files
committed
test: add coverage for c and , keyboard shortcuts
1 parent 097c8c4 commit 1e88684

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

test/e2e/interactions.spec.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/\/compare/)
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(/\/compare\?packages=vue/)
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(/\/settings/)
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(/\/settings/)
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(/\/compare/)
135+
// The ',' should have been typed into the input
136+
await expect(searchInput).toHaveValue(',')
137+
})
138+
})

0 commit comments

Comments
 (0)