Skip to content

Commit f04943d

Browse files
committed
test: add missing run command tests
1 parent 3501973 commit f04943d

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

test/e2e/create-command.spec.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,56 @@ test.describe('Create Command', () => {
151151
await expect(copyButton).not.toContainText(/copied/i)
152152
})
153153
})
154+
155+
test.describe('Run Command Copy', () => {
156+
test('copy button is always visible', async ({ page, goto }) => {
157+
await goto('/package/vite', { waitUntil: 'hydration' })
158+
159+
await expect(page.locator('h1')).toContainText('vite', { timeout: 15000 })
160+
161+
await expect(page.locator('main header').locator('text=/v\\d+\\.\\d+/')).toBeVisible({
162+
timeout: 15000,
163+
})
164+
165+
// Find the run command container
166+
const runCommandContainer = page.locator('.group\\/runcmd').first()
167+
await expect(runCommandContainer).toBeVisible({ timeout: 20000 })
168+
169+
// Copy button should always be visible
170+
const copyButton = runCommandContainer.locator('button')
171+
await expect(copyButton).toHaveCSS('opacity', '1')
172+
})
173+
174+
test('clicking copy button copies run command and shows confirmation', async ({
175+
page,
176+
goto,
177+
context,
178+
}) => {
179+
// Grant clipboard permissions
180+
await context.grantPermissions(['clipboard-read', 'clipboard-write'])
181+
182+
await goto('/package/vite', { waitUntil: 'hydration' })
183+
await expect(page.locator('h1')).toContainText('vite', { timeout: 15000 })
184+
185+
await expect(page.locator('main header').locator('text=/v\\d+\\.\\d+/')).toBeVisible({
186+
timeout: 15000,
187+
})
188+
189+
const runCommandContainer = page.locator('.group\\/runcmd').first()
190+
await expect(runCommandContainer).toBeVisible({ timeout: 20000 })
191+
192+
const copyButton = runCommandContainer.locator('button')
193+
await copyButton.click()
194+
195+
// Button text should change to "copied!"
196+
await expect(copyButton).toContainText(/copied/i)
197+
198+
// Verify clipboard content contains the run command
199+
const clipboardContent = await page.evaluate(() => navigator.clipboard.readText())
200+
expect(clipboardContent).toMatch(/vite|npx vite/i)
201+
202+
await expect(copyButton).toContainText(/copy/i, { timeout: 5000 })
203+
await expect(copyButton).not.toContainText(/copied/i)
204+
})
205+
})
154206
})

0 commit comments

Comments
 (0)