-
-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathcreate-command.spec.ts
More file actions
191 lines (148 loc) · 7.44 KB
/
create-command.spec.ts
File metadata and controls
191 lines (148 loc) · 7.44 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
import { expect, test } from '@nuxt/test-utils/playwright'
test.describe('Create Command', () => {
// TODO: these tests depend on external npm registry API - we should add data fixtures
test.describe.configure({ retries: 2 })
test.describe('Visibility', () => {
test('/vite - should show create command (same maintainers)', async ({ page, goto }) => {
await goto('/vite', { waitUntil: 'domcontentloaded' })
// Create command section should be visible (SSR)
// Use specific container to avoid matching README code blocks
const createCommandSection = page.locator('.group\\/createcmd').first()
await expect(createCommandSection).toBeVisible()
await expect(createCommandSection.locator('code')).toContainText(/create vite/i)
// Link to create-vite should be present (uses sr-only text, so check attachment not visibility)
await expect(page.locator('a[href="/create-vite"]').first()).toBeAttached()
})
test('/next - should show create command (shared maintainer, same repo)', async ({
page,
goto,
}) => {
await goto('/next', { waitUntil: 'domcontentloaded' })
// Create command section should be visible (SSR)
// Use specific container to avoid matching README code blocks
const createCommandSection = page.locator('.group\\/createcmd').first()
await expect(createCommandSection).toBeVisible()
await expect(createCommandSection.locator('code')).toContainText(/create next-app/i)
// Link to create-next-app should be present (uses sr-only text, so check attachment not visibility)
await expect(page.locator('a[href="/create-next-app"]').first()).toBeAttached()
})
test('/nuxt - should show create command (same maintainer, same org)', async ({
page,
goto,
}) => {
await goto('/nuxt', { waitUntil: 'domcontentloaded' })
// Create command section should be visible (SSR)
// nuxt has create-nuxt package, so command is "npm create nuxt"
// Use specific container to avoid matching README code blocks
const createCommandSection = page.locator('.group\\/createcmd').first()
await expect(createCommandSection).toBeVisible()
await expect(createCommandSection.locator('code')).toContainText(/create nuxt/i)
})
test('/color - should NOT show create command (different maintainers)', async ({
page,
goto,
}) => {
await goto('/color', { waitUntil: 'domcontentloaded' })
// Wait for package to load
await expect(page.locator('h1').filter({ hasText: 'color' })).toBeVisible()
// Create command section should NOT be visible (different maintainers)
// Use .first() for consistency, though none should exist
const createCommandSection = page.locator('.group\\/createcmd').first()
await expect(createCommandSection).not.toBeVisible()
})
test('/lodash - should NOT show create command (no create-lodash exists)', async ({
page,
goto,
}) => {
await goto('/lodash', { waitUntil: 'domcontentloaded' })
// Wait for package to load
await expect(page.locator('h1').filter({ hasText: 'lodash' })).toBeVisible()
// Create command section should NOT be visible (no create-lodash exists)
// Use .first() for consistency, though none should exist
const createCommandSection = page.locator('.group\\/createcmd').first()
await expect(createCommandSection).not.toBeVisible()
})
})
test.describe('Copy Functionality', () => {
test('hovering create command shows copy button', async ({ page, goto }) => {
await goto('/vite', { waitUntil: 'hydration' })
await expect(page.locator('h1')).toContainText('vite', { timeout: 15000 })
await expect(page.locator('main header').locator('text=/v\\d+\\.\\d+/')).toBeVisible({
timeout: 15000,
})
// Find the create command container (wait longer for API response)
const createCommandContainer = page.locator('.group\\/createcmd').first()
await expect(createCommandContainer).toBeVisible({ timeout: 20000 })
// Copy button should initially be hidden (opacity-0)
const copyButton = createCommandContainer.locator('button')
await expect(copyButton).toHaveCSS('opacity', '0')
// Hover over the container
await createCommandContainer.hover()
// Copy button should become visible
await expect(copyButton).toHaveCSS('opacity', '1')
})
test('clicking copy button copies create command and shows confirmation', async ({
page,
goto,
context,
}) => {
// Grant clipboard permissions
await context.grantPermissions(['clipboard-read', 'clipboard-write'])
await goto('/vite', { waitUntil: 'hydration' })
await expect(page.locator('h1')).toContainText('vite', { timeout: 15000 })
await expect(page.locator('main header').locator('text=/v\\d+\\.\\d+/')).toBeVisible({
timeout: 15000,
})
const createCommandContainer = page.locator('.group\\/createcmd').first()
await expect(createCommandContainer).toBeVisible({ timeout: 20000 })
await createCommandContainer.hover()
// Click the copy button
const copyButton = createCommandContainer.locator('button')
await copyButton.click()
// Button text should change to "copied!"
await expect(copyButton).toContainText(/copied/i)
// Verify clipboard content contains the create command
const clipboardContent = await page.evaluate(() => navigator.clipboard.readText())
expect(clipboardContent).toMatch(/create vite/i)
await expect(copyButton).toContainText(/copy/i, { timeout: 5000 })
await expect(copyButton).not.toContainText(/copied/i)
})
})
test.describe('Install Command Copy', () => {
test('hovering install command shows copy button', async ({ page, goto }) => {
await goto('/lodash', { waitUntil: 'hydration' })
// Find the install command container
const installCommandContainer = page.locator('.group\\/installcmd').first()
await expect(installCommandContainer).toBeVisible()
// Copy button should initially be hidden
const copyButton = installCommandContainer.locator('button')
await expect(copyButton).toHaveCSS('opacity', '0')
// Hover over the container
await installCommandContainer.hover()
// Copy button should become visible
await expect(copyButton).toHaveCSS('opacity', '1')
})
test('clicking copy button copies install command and shows confirmation', async ({
page,
goto,
context,
}) => {
// Grant clipboard permissions
await context.grantPermissions(['clipboard-read', 'clipboard-write'])
await goto('/lodash', { waitUntil: 'hydration' })
// Find and hover over the install command container
const installCommandContainer = page.locator('.group\\/installcmd').first()
await installCommandContainer.hover()
// Click the copy button
const copyButton = installCommandContainer.locator('button')
await copyButton.click()
// Button text should change to "copied!"
await expect(copyButton).toContainText(/copied/i)
// Verify clipboard content contains the install command
const clipboardContent = await page.evaluate(() => navigator.clipboard.readText())
expect(clipboardContent).toMatch(/install lodash|add lodash/i)
await expect(copyButton).toContainText(/copy/i, { timeout: 5000 })
await expect(copyButton).not.toContainText(/copied/i)
})
})
})