Skip to content

Commit 5bb7fea

Browse files
committed
test: add playwright test for commands
1 parent 47013e9 commit 5bb7fea

1 file changed

Lines changed: 171 additions & 0 deletions

File tree

tests/create-command.spec.ts

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
import { expect, test } from '@nuxt/test-utils/playwright'
2+
3+
test.describe('Create Command', () => {
4+
test.describe('Visibility', () => {
5+
test('/vite - should show create command (same maintainers)', async ({ page, goto }) => {
6+
await goto('/vite', { waitUntil: 'domcontentloaded' })
7+
8+
// Create command section should be visible (SSR)
9+
const createCommand = page.locator('code', { hasText: /create vite/i })
10+
await expect(createCommand).toBeVisible()
11+
12+
// Link to create-vite should be present
13+
await expect(page.locator('a[href="/create-vite"]')).toBeVisible()
14+
})
15+
16+
test('/next - should show create command (shared maintainer, same repo)', async ({
17+
page,
18+
goto,
19+
}) => {
20+
await goto('/next', { waitUntil: 'domcontentloaded' })
21+
22+
// Create command section should be visible (SSR)
23+
const createCommand = page.locator('code', { hasText: /create next-app/i })
24+
await expect(createCommand).toBeVisible()
25+
26+
// Link to create-next-app should be present
27+
await expect(page.locator('a[href="/create-next-app"]')).toBeVisible()
28+
})
29+
30+
test('/nuxt - should show create command (same maintainer, same org)', async ({
31+
page,
32+
goto,
33+
}) => {
34+
await goto('/nuxt', { waitUntil: 'domcontentloaded' })
35+
36+
// Create command section should be visible (SSR)
37+
const createCommand = page.locator('code', { hasText: /nuxi init/i })
38+
await expect(createCommand).toBeVisible()
39+
})
40+
41+
test('/color - should NOT show create command (different maintainers)', async ({
42+
page,
43+
goto,
44+
}) => {
45+
await goto('/color', { waitUntil: 'domcontentloaded' })
46+
47+
// Wait for package to load
48+
await expect(page.locator('h1').filter({ hasText: 'color' })).toBeVisible()
49+
50+
// Create command should NOT be visible
51+
const createCommand = page.locator('code', { hasText: /create color/i })
52+
await expect(createCommand).not.toBeVisible()
53+
})
54+
55+
test('/lodash - should NOT show create command (no create-lodash exists)', async ({
56+
page,
57+
goto,
58+
}) => {
59+
await goto('/lodash', { waitUntil: 'domcontentloaded' })
60+
61+
// Wait for package to load
62+
await expect(page.locator('h1').filter({ hasText: 'lodash' })).toBeVisible()
63+
64+
// Create command should NOT be visible
65+
const createCommand = page.locator('code', { hasText: /create lodash/i })
66+
await expect(createCommand).not.toBeVisible()
67+
})
68+
})
69+
70+
test.describe('Copy Functionality', () => {
71+
test('hovering create command shows copy button', async ({ page, goto }) => {
72+
await goto('/vite', { waitUntil: 'hydration' })
73+
74+
// Find the create command container
75+
const createCommandContainer = page.locator('.group\\/createcmd')
76+
await expect(createCommandContainer).toBeVisible()
77+
78+
// Copy button should initially be hidden (opacity-0)
79+
const copyButton = createCommandContainer.locator('button')
80+
await expect(copyButton).toHaveCSS('opacity', '0')
81+
82+
// Hover over the container
83+
await createCommandContainer.hover()
84+
85+
// Copy button should become visible
86+
await expect(copyButton).toHaveCSS('opacity', '1')
87+
})
88+
89+
test('clicking copy button copies create command and shows confirmation', async ({
90+
page,
91+
goto,
92+
context,
93+
}) => {
94+
// Grant clipboard permissions
95+
await context.grantPermissions(['clipboard-read', 'clipboard-write'])
96+
97+
await goto('/vite', { waitUntil: 'hydration' })
98+
99+
// Find and hover over the create command container
100+
const createCommandContainer = page.locator('.group\\/createcmd')
101+
await createCommandContainer.hover()
102+
103+
// Click the copy button
104+
const copyButton = createCommandContainer.locator('button')
105+
await copyButton.click()
106+
107+
// Button text should change to "copied!"
108+
await expect(copyButton).toContainText(/copied/i)
109+
110+
// Verify clipboard content contains the create command
111+
const clipboardContent = await page.evaluate(() => navigator.clipboard.readText())
112+
expect(clipboardContent).toMatch(/create vite/i)
113+
114+
// After timeout, should revert to "copy"
115+
await page.waitForTimeout(2500)
116+
await expect(copyButton).toContainText(/copy/i)
117+
await expect(copyButton).not.toContainText(/copied/i)
118+
})
119+
})
120+
121+
test.describe('Install Command Copy', () => {
122+
test('hovering install command shows copy button', async ({ page, goto }) => {
123+
await goto('/lodash', { waitUntil: 'hydration' })
124+
125+
// Find the install command container
126+
const installCommandContainer = page.locator('.group\\/installcmd')
127+
await expect(installCommandContainer).toBeVisible()
128+
129+
// Copy button should initially be hidden
130+
const copyButton = installCommandContainer.locator('button')
131+
await expect(copyButton).toHaveCSS('opacity', '0')
132+
133+
// Hover over the container
134+
await installCommandContainer.hover()
135+
136+
// Copy button should become visible
137+
await expect(copyButton).toHaveCSS('opacity', '1')
138+
})
139+
140+
test('clicking copy button copies install command and shows confirmation', async ({
141+
page,
142+
goto,
143+
context,
144+
}) => {
145+
// Grant clipboard permissions
146+
await context.grantPermissions(['clipboard-read', 'clipboard-write'])
147+
148+
await goto('/lodash', { waitUntil: 'hydration' })
149+
150+
// Find and hover over the install command container
151+
const installCommandContainer = page.locator('.group\\/installcmd')
152+
await installCommandContainer.hover()
153+
154+
// Click the copy button
155+
const copyButton = installCommandContainer.locator('button')
156+
await copyButton.click()
157+
158+
// Button text should change to "copied!"
159+
await expect(copyButton).toContainText(/copied/i)
160+
161+
// Verify clipboard content contains the install command
162+
const clipboardContent = await page.evaluate(() => navigator.clipboard.readText())
163+
expect(clipboardContent).toMatch(/install lodash|add lodash/i)
164+
165+
// After timeout, should revert to "copy"
166+
await page.waitForTimeout(2500)
167+
await expect(copyButton).toContainText(/copy/i)
168+
await expect(copyButton).not.toContainText(/copied/i)
169+
})
170+
})
171+
})

0 commit comments

Comments
 (0)