-
-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathinteractions.spec.ts
More file actions
382 lines (295 loc) · 13.1 KB
/
interactions.spec.ts
File metadata and controls
382 lines (295 loc) · 13.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
import { expect, test } from './test-utils'
test.describe('Compare Page', () => {
test('no-dep column renders separately from package columns', async ({ page, goto }) => {
await goto('/compare?packages=vue,__no_dependency__', { waitUntil: 'hydration' })
const grid = page.locator('.comparison-grid')
await expect(grid).toBeVisible({ timeout: 15000 })
// Should have the no-dep column with special styling
const noDepColumn = grid.locator('.comparison-cell-nodep')
await expect(noDepColumn).toBeVisible()
// The no-dep column should not contain a link
await expect(noDepColumn.locator('a')).toHaveCount(0)
})
test('no-dep column is always last even when packages are added after', async ({
page,
goto,
}) => {
// Start with vue and no-dep
await goto('/compare?packages=vue,__no_dependency__', { waitUntil: 'hydration' })
const grid = page.locator('.comparison-grid')
await expect(grid).toBeVisible({ timeout: 15000 })
// Add another package via the input
const input = page.locator('#package-search')
await input.fill('nuxt')
// Wait for search results and click on nuxt
const nuxtOption = page.locator('button:has-text("nuxt")').first()
await expect(nuxtOption).toBeVisible({ timeout: 10000 })
await nuxtOption.click()
// URL should have no-dep at the end, not in the middle
await expect(page).toHaveURL(/packages=vue,nuxt,__no_dependency__/)
// Verify column order in the grid: vue, nuxt, then no-dep
const headerLinks = grid.locator('.comparison-cell-header a[title]')
await expect(headerLinks).toHaveCount(2)
await expect(headerLinks.nth(0)).toContainText('vue')
await expect(headerLinks.nth(1)).toContainText('nuxt')
// No-dep should still be visible as the last column
const noDepColumn = grid.locator('.comparison-cell-nodep')
await expect(noDepColumn).toBeVisible()
})
test('loads install-size data for a scoped package', async ({ page, goto }) => {
// Intercept the internal API call the browser makes for install-size.
// The browser will request /api/registry/install-size/@nuxt%2Fkit (encoded slash).
// Before the fix this would fail to parse and return an error; after it returns 200.
const installSizeResponse = page.waitForResponse(
res =>
res.url().includes('/api/registry/install-size/') &&
res.url().includes('nuxt') &&
res.request().method() === 'GET',
{ timeout: 20_000 },
)
await goto('/compare?packages=@nuxt/kit,vue', { waitUntil: 'hydration' })
const response = await installSizeResponse
expect(response.status()).toBe(200)
const body = await response.json()
// The API should return a valid install size object, not an error
expect(body).toHaveProperty('selfSize')
expect(body).toHaveProperty('totalSize')
})
test('loads analysis data for a scoped package', async ({ page, goto }) => {
const analysisResponse = page.waitForResponse(
res =>
res.url().includes('/api/registry/analysis/') &&
res.url().includes('nuxt') &&
res.request().method() === 'GET',
{ timeout: 20_000 },
)
await goto('/compare?packages=@nuxt/kit,vue', { waitUntil: 'hydration' })
const response = await analysisResponse
expect(response.status()).toBe(200)
const body = await response.json()
expect(body).toHaveProperty('package', '@nuxt/kit')
expect(body).toHaveProperty('moduleFormat', 'esm')
})
})
test.describe('Search Pages', () => {
test('/search?q=vue → keyboard navigation (arrow keys + enter)', async ({ page, goto }) => {
await goto('/search?q=vue', { waitUntil: 'hydration' })
await expect(page.locator('text=/found \\d+|showing \\d+/i').first()).toBeVisible({
timeout: 15000,
})
const firstResult = page.locator('[data-result-index="0"]').first()
await expect(firstResult).toBeVisible()
// Wait for the @vue org suggestion card to appear
const orgSuggestion = page.locator('[data-suggestion-index="0"]')
await expect(orgSuggestion).toBeVisible({ timeout: 10000 })
// ArrowDown focuses the org suggestion card
await page.keyboard.press('ArrowDown')
// ArrowUp returns to the search input
await page.keyboard.press('ArrowUp')
// ArrowDown again, then Enter navigates to the suggestion
// URL is /package/vue or /org/vue or /user/vue. Not /vue
await page.keyboard.press('ArrowDown')
await page.keyboard.press('Enter')
await expect(page).toHaveURL(/\/(package|org|user)\/vue/)
})
test('/search?q=vue → ArrowDown navigates only between results, not keyword buttons', async ({
page,
goto,
}) => {
await goto('/search?q=vue', { waitUntil: 'hydration' })
await expect(page.locator('text=/found \\d+|showing \\d+/i').first()).toBeVisible({
timeout: 15000,
})
const firstResult = page.locator('[data-result-index="0"]').first()
const secondResult = page.locator('[data-result-index="1"]').first()
await expect(firstResult).toBeVisible()
await expect(secondResult).toBeVisible()
// Wait for the @vue org suggestion card to appear
const orgSuggestion = page.locator('[data-suggestion-index="0"]')
await expect(orgSuggestion).toBeVisible({ timeout: 10000 })
// ArrowDown focuses the org suggestion first
await page.keyboard.press('ArrowDown')
await expect(orgSuggestion).toBeFocused()
// Next ArrowDown focuses the first package result
await page.keyboard.press('ArrowDown')
await expect(firstResult).toBeFocused()
// Next ArrowDown focuses the second result (not a keyword button within the first)
await page.keyboard.press('ArrowDown')
await expect(secondResult).toBeFocused()
})
test('/search?q=vue → ArrowUp from first result navigates back through suggestions to input', async ({
page,
goto,
}) => {
await goto('/search?q=vue', { waitUntil: 'hydration' })
await expect(page.locator('text=/found \\d+|showing \\d+/i').first()).toBeVisible({
timeout: 15000,
})
// Wait for the @vue org suggestion card to appear
const orgSuggestion = page.locator('[data-suggestion-index="0"]')
await expect(orgSuggestion).toBeVisible({ timeout: 10000 })
// Navigate: suggestion → first package result
await page.keyboard.press('ArrowDown')
await expect(orgSuggestion).toBeFocused()
await page.keyboard.press('ArrowDown')
await expect(page.locator('[data-result-index="0"]').first()).toBeFocused()
// ArrowUp goes back to the org suggestion
await page.keyboard.press('ArrowUp')
await expect(orgSuggestion).toBeFocused()
// ArrowUp from suggestion returns to the search input
await page.keyboard.press('ArrowUp')
await expect(page.locator('input[type="search"]')).toBeFocused()
})
test('/search?q=vue → "/" focuses the search input from results', async ({ page, goto }) => {
await goto('/search?q=vue', { waitUntil: 'hydration' })
await expect(page.locator('text=/found \\d+|showing \\d+/i').first()).toBeVisible({
timeout: 15000,
})
await page.locator('[data-result-index="0"]').first().focus()
await page.keyboard.press('/')
await expect(page.locator('input[type="search"]')).toBeFocused()
})
test('/ (homepage) → search, keeps focus on search input', async ({ page, goto }) => {
await goto('/', { waitUntil: 'hydration' })
const homeSearchInput = page.locator('#home-search')
await homeSearchInput.click()
await page.keyboard.type('vue')
// Wait for navigation to /search (debounce is 250ms)
await expect(page).toHaveURL(/\/search/, { timeout: 10000 })
await expect(page.locator('[data-result-index="0"]').first()).toBeVisible({
timeout: 15000,
})
// Home search input should be gone (we're on /search now)
await expect(homeSearchInput).not.toBeVisible()
// Header search input should now exist and be focused
const headerSearchInput = page.locator('#header-search')
await expect(headerSearchInput).toBeVisible()
await expect(headerSearchInput).toBeFocused()
})
test('/settings → search, keeps focus on search input', async ({ page, goto }) => {
await goto('/settings', { waitUntil: 'hydration' })
const searchInput = page.locator('input[type="search"]')
await expect(searchInput).toBeVisible()
await searchInput.click()
await searchInput.fill('vue')
await expect(page).toHaveURL(/\/search/, { timeout: 10000 })
await expect(page.locator('[data-result-index="0"]').first()).toBeVisible({
timeout: 15000,
})
const headerSearchInput = page.locator('#header-search')
await expect(headerSearchInput).toBeFocused()
})
})
test.describe('Keyboard Shortcuts', () => {
test('"c" navigates to /compare', async ({ page, goto }) => {
await goto('/settings', { waitUntil: 'hydration' })
await page.keyboard.press('c')
await expect(page).toHaveURL(/\/compare/)
})
test('"c" does not navigate when any modifier key is pressed', async ({ page, goto }) => {
await goto('/settings', { waitUntil: 'hydration' })
await page.keyboard.press('Shift+c')
await expect(page).toHaveURL(/\/settings/)
await page.keyboard.press('Control+c')
await expect(page).toHaveURL(/\/settings/)
await page.keyboard.press('Alt+c')
await expect(page).toHaveURL(/\/settings/)
await page.keyboard.press('Meta+c')
await expect(page).toHaveURL(/\/settings/)
await page.keyboard.press('ControlOrMeta+Shift+c')
await expect(page).toHaveURL(/\/settings/)
})
test('"c" on package page navigates to /compare with package pre-filled', async ({
page,
goto,
}) => {
await goto('/package/vue', { waitUntil: 'hydration' })
await page.keyboard.press('c')
// Should navigate to /compare with the package in the query
await expect(page).toHaveURL(/\/compare\?packages=vue/)
})
test('"c" does not navigate when search input is focused', async ({ page, goto }) => {
await goto('/settings', { waitUntil: 'hydration' })
const searchInput = page.locator('#header-search')
await searchInput.focus()
await expect(searchInput).toBeFocused()
await page.keyboard.press('c')
// Should still be on settings, not navigated to compare
await expect(page).toHaveURL(/\/settings/)
// The 'c' should have been typed into the input
await expect(searchInput).toHaveValue('c')
})
test('"c" on package page does not navigate when any modifier key is pressed', async ({
page,
goto,
}) => {
await goto('/package/vue', { waitUntil: 'hydration' })
await page.keyboard.press('Shift+c')
await expect(page).toHaveURL(/\/vue/)
await page.keyboard.press('Control+c')
await expect(page).toHaveURL(/\/vue/)
await page.keyboard.press('Alt+c')
await expect(page).toHaveURL(/\/vue/)
await page.keyboard.press('Meta+c')
await expect(page).toHaveURL(/\/vue/)
await page.keyboard.press('ControlOrMeta+Shift+c')
await expect(page).toHaveURL(/\/vue/)
})
test('"," navigates to /settings', async ({ page, goto }) => {
await goto('/compare', { waitUntil: 'hydration' })
await page.keyboard.press(',')
await expect(page).toHaveURL(/\/settings/)
})
test('"," does not navigate when any modifier key is pressed', async ({ page, goto }) => {
await goto('/settings', { waitUntil: 'hydration' })
const searchInput = page.locator('#header-search')
await searchInput.focus()
await expect(searchInput).toBeFocused()
await page.keyboard.press('Shift+,')
await expect(page).toHaveURL(/\/settings/)
await page.keyboard.press('Control+,')
await expect(page).toHaveURL(/\/settings/)
await page.keyboard.press('Alt+,')
await expect(page).toHaveURL(/\/settings/)
await page.keyboard.press('Meta+,')
await expect(page).toHaveURL(/\/settings/)
await page.keyboard.press('ControlOrMeta+Shift+,')
await expect(page).toHaveURL(/\/settings/)
})
})
test.describe('Keyboard Shortcuts disabled', () => {
test.beforeEach(async ({ page }) => {
await page.addInitScript(() => {
localStorage.setItem('npmx-settings', JSON.stringify({ keyboardShortcuts: false }))
})
})
test('"," (header) does not navigate to /settings when shortcuts are disabled', async ({
page,
goto,
}) => {
await goto('/compare', { waitUntil: 'hydration' })
await page.keyboard.press(',')
await expect(page).toHaveURL(/\/compare/)
})
test('"/" (global) does not focus search input when shortcuts are disabled', async ({
page,
goto,
}) => {
await goto('/search?q=vue', { waitUntil: 'hydration' })
await expect(page.locator('text=/found \\d+|showing \\d+/i').first()).toBeVisible({
timeout: 15000,
})
// Focus a non-input element so "/" would normally steal focus to search
await page.locator('[data-result-index="0"]').first().focus()
await page.keyboard.press('/')
await expect(page.locator('input[type="search"]')).not.toBeFocused()
})
test('"d" (package) does not navigate to docs when shortcuts are disabled', async ({
page,
goto,
}) => {
await goto('/package/vue', { waitUntil: 'hydration' })
await page.keyboard.press('d')
await expect(page).toHaveURL(/\/package\/vue$/)
})
})