|
| 1 | +import { expect, test } from '@nuxt/test-utils/playwright' |
| 2 | + |
| 3 | +test.describe('npmjs.com URL Compatibility', () => { |
| 4 | + test.describe('Package Pages', () => { |
| 5 | + test('/package/vue → package page', async ({ page, goto }) => { |
| 6 | + await goto('/package/vue', { waitUntil: 'domcontentloaded' }) |
| 7 | + |
| 8 | + // Should show package name |
| 9 | + await expect(page.locator('h1')).toContainText('vue') |
| 10 | + // Should have version badge |
| 11 | + await expect(page.locator('text=/v\\d+\\.\\d+/')).toBeVisible() |
| 12 | + }) |
| 13 | + |
| 14 | + test('/package/@nuxt/kit → scoped package page', async ({ page, goto }) => { |
| 15 | + await goto('/package/@nuxt/kit', { waitUntil: 'domcontentloaded' }) |
| 16 | + |
| 17 | + // Should show scoped package name |
| 18 | + await expect(page.locator('h1')).toContainText('@nuxt/kit') |
| 19 | + }) |
| 20 | + |
| 21 | + test('/package/vue/v/3.4.0 → specific version', async ({ page, goto }) => { |
| 22 | + await goto('/package/vue/v/3.4.0', { waitUntil: 'domcontentloaded' }) |
| 23 | + |
| 24 | + // Should show package name |
| 25 | + await expect(page.locator('h1')).toContainText('vue') |
| 26 | + // Should show the specific version |
| 27 | + await expect(page.locator('text=v3.4.0')).toBeVisible() |
| 28 | + }) |
| 29 | + |
| 30 | + test('/package/@nuxt/kit/v/3.0.0 → scoped package specific version', async ({ page, goto }) => { |
| 31 | + await goto('/package/@nuxt/kit/v/3.0.0', { waitUntil: 'domcontentloaded' }) |
| 32 | + |
| 33 | + // Should show scoped package name |
| 34 | + await expect(page.locator('h1')).toContainText('@nuxt/kit') |
| 35 | + // Should show the specific version (or "not latest" indicator) |
| 36 | + await expect(page.locator('text=v3.0.0').first()).toBeVisible() |
| 37 | + }) |
| 38 | + |
| 39 | + test('/package/nonexistent-pkg-12345 → 404 handling', async ({ page, goto }) => { |
| 40 | + await goto('/package/nonexistent-pkg-12345', { waitUntil: 'domcontentloaded' }) |
| 41 | + |
| 42 | + // Should show error state - look for the heading specifically |
| 43 | + await expect(page.getByRole('heading', { name: /not found/i })).toBeVisible() |
| 44 | + }) |
| 45 | + }) |
| 46 | + |
| 47 | + test.describe('Search Pages', () => { |
| 48 | + test('/search?q=vue → search results', async ({ page, goto }) => { |
| 49 | + await goto('/search?q=vue', { waitUntil: 'domcontentloaded' }) |
| 50 | + |
| 51 | + // Should show search input with query |
| 52 | + await expect(page.locator('input[type="search"]')).toHaveValue('vue') |
| 53 | + // Should show results count |
| 54 | + await expect(page.locator('text=/found \\d+/i')).toBeVisible() |
| 55 | + }) |
| 56 | + |
| 57 | + test('/search?q=keywords:framework → keyword search', async ({ page, goto }) => { |
| 58 | + await goto('/search?q=keywords:framework', { waitUntil: 'domcontentloaded' }) |
| 59 | + |
| 60 | + // Should show search input with query |
| 61 | + await expect(page.locator('input[type="search"]')).toHaveValue('keywords:framework') |
| 62 | + // Should show results |
| 63 | + await expect(page.locator('text=/found \\d+/i')).toBeVisible() |
| 64 | + }) |
| 65 | + |
| 66 | + test('/search → empty search page', async ({ page, goto }) => { |
| 67 | + await goto('/search', { waitUntil: 'domcontentloaded' }) |
| 68 | + |
| 69 | + // Should show empty state prompt |
| 70 | + await expect(page.locator('text=/start typing/i')).toBeVisible() |
| 71 | + }) |
| 72 | + }) |
| 73 | + |
| 74 | + test.describe('User Profile Pages', () => { |
| 75 | + test('/~sindresorhus → user profile', async ({ page, goto }) => { |
| 76 | + await goto('/~sindresorhus', { waitUntil: 'domcontentloaded' }) |
| 77 | + |
| 78 | + // Should show username |
| 79 | + await expect(page.locator('h1')).toContainText('@sindresorhus') |
| 80 | + // Should show packages heading (user has packages) |
| 81 | + await expect(page.getByRole('heading', { name: 'Packages' })).toBeVisible() |
| 82 | + }) |
| 83 | + |
| 84 | + test('/~nonexistent-user-12345 → empty user handling', async ({ page, goto }) => { |
| 85 | + await goto('/~nonexistent-user-12345', { waitUntil: 'domcontentloaded' }) |
| 86 | + |
| 87 | + // Should show username in header |
| 88 | + await expect(page.locator('h1')).toContainText('@nonexistent-user-12345') |
| 89 | + // Should show empty state message |
| 90 | + await expect(page.getByText('No public packages found for')).toBeVisible() |
| 91 | + }) |
| 92 | + }) |
| 93 | + |
| 94 | + test.describe('Organization Pages', () => { |
| 95 | + test('/org/nuxt → organization page', async ({ page, goto }) => { |
| 96 | + await goto('/org/nuxt', { waitUntil: 'domcontentloaded' }) |
| 97 | + |
| 98 | + // Should show org name |
| 99 | + await expect(page.locator('h1')).toContainText('@nuxt') |
| 100 | + // Should show packages heading |
| 101 | + await expect(page.getByRole('heading', { name: 'Packages' })).toBeVisible() |
| 102 | + }) |
| 103 | + |
| 104 | + test('/org/nonexistent-org-12345 → empty org handling', async ({ page, goto }) => { |
| 105 | + await goto('/org/nonexistent-org-12345', { waitUntil: 'domcontentloaded' }) |
| 106 | + |
| 107 | + // Should show org name in header |
| 108 | + await expect(page.locator('h1')).toContainText('@nonexistent-org-12345') |
| 109 | + // Should show empty state message |
| 110 | + await expect(page.getByText('No public packages found for')).toBeVisible() |
| 111 | + }) |
| 112 | + }) |
| 113 | + |
| 114 | + test.describe('Edge Cases', () => { |
| 115 | + test('package name with dots: /package/lodash.merge', async ({ page, goto }) => { |
| 116 | + await goto('/package/lodash.merge', { waitUntil: 'domcontentloaded' }) |
| 117 | + |
| 118 | + await expect(page.locator('h1')).toContainText('lodash.merge') |
| 119 | + }) |
| 120 | + |
| 121 | + test('package name with hyphens: /package/date-fns', async ({ page, goto }) => { |
| 122 | + await goto('/package/date-fns', { waitUntil: 'domcontentloaded' }) |
| 123 | + |
| 124 | + await expect(page.locator('h1')).toContainText('date-fns') |
| 125 | + }) |
| 126 | + |
| 127 | + test('scoped package with hyphens: /package/@types/node', async ({ page, goto }) => { |
| 128 | + await goto('/package/@types/node', { waitUntil: 'domcontentloaded' }) |
| 129 | + |
| 130 | + await expect(page.locator('h1')).toContainText('@types/node') |
| 131 | + }) |
| 132 | + }) |
| 133 | +}) |
0 commit comments