Skip to content

Commit 0c147e4

Browse files
committed
test: add an e2e test for recently viewed feature
1 parent 71aaf4a commit 0c147e4

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/e2e/recently-viewed.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { expect, test } from './test-utils'
2+
3+
test.describe('Recently Viewed', () => {
4+
test('visiting package, org, and user pages populates recently viewed on homepage', async ({
5+
page,
6+
goto,
7+
}) => {
8+
// Start with empty homepage — no recently viewed items
9+
await goto('/', { waitUntil: 'hydration' })
10+
await expect(page.locator('#recently-viewed-label')).not.toBeVisible()
11+
12+
// Visit a package page — wait for install command to confirm data loaded
13+
await goto('/package/nuxt', { waitUntil: 'hydration' })
14+
await expect(page.locator('#get-started')).toBeVisible({ timeout: 15000 })
15+
16+
// Visit an org page — wait for the package list to confirm data loaded
17+
await goto('/@nuxt', { waitUntil: 'hydration' })
18+
await expect(page.getByText(/public packages?/i)).toBeVisible({ timeout: 15000 })
19+
20+
// Visit a user page — wait for package count to confirm data loaded
21+
await goto('/~qwerzl', { waitUntil: 'hydration' })
22+
await expect(page.getByText(/public packages?/i)).toBeVisible({ timeout: 15000 })
23+
24+
// Go back to homepage — should see all three recently viewed items
25+
await goto('/', { waitUntil: 'hydration' })
26+
27+
const recentNav = page.locator('nav[aria-labelledby="recently-viewed-label"]')
28+
await expect(recentNav).toBeVisible({ timeout: 10000 })
29+
30+
const links = recentNav.locator('a')
31+
await expect(links).toHaveCount(3)
32+
33+
// Most recent first
34+
await expect(links.nth(0)).toContainText('~qwerzl')
35+
await expect(links.nth(1)).toContainText('@nuxt')
36+
await expect(links.nth(2)).toContainText('nuxt')
37+
})
38+
})

0 commit comments

Comments
 (0)