-
-
Notifications
You must be signed in to change notification settings - Fork 295
/
Copy pathprops.test.ts
44 lines (38 loc) · 1.99 KB
/
props.test.ts
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
import { expect, test } from '@playwright/test'
test.describe('props', async () => {
test('results do not change when filtering is disabled', async ({ page }) => {
await page.goto('/props?shouldFilter=false')
await expect(page.locator(`[cmdk-item]`)).toHaveCount(2)
await page.locator(`[cmdk-input]`).type('z')
await expect(page.locator(`[cmdk-item]`)).toHaveCount(2)
})
test('results match against custom filter', async ({ page }) => {
await page.goto('/props?customFilter=true')
await page.locator(`[cmdk-input]`).type(`ant`)
await expect(page.locator(`[cmdk-item]`)).toHaveAttribute('data-value', 'ant')
})
test('controlled value', async ({ page }) => {
await page.goto('/props')
await expect(page.locator(`[cmdk-item][aria-selected="true"]`)).toHaveAttribute('data-value', 'ant')
await page.locator(`data-testid=controlledValue`).click()
await expect(page.locator(`[cmdk-item][aria-selected="true"]`)).toHaveAttribute('data-value', 'anteater')
})
test('keep controlled value if empty results', async ({ page }) => {
await page.goto('/props')
await expect(page.locator(`[data-testid=value]`)).toHaveText('ant')
await page.locator(`[cmdk-input]`).fill('d')
await expect(page.locator(`[data-testid=value]`)).toHaveText('')
await page.locator(`[cmdk-input]`).fill('ant')
await expect(page.locator(`[data-testid=value]`)).toHaveText('ant')
})
test('controlled search', async ({ page }) => {
await page.goto('/props')
await expect(page.locator(`[cmdk-item][aria-selected="true"]`)).toHaveAttribute('data-value', 'ant')
await page.locator(`data-testid=controlledSearch`).click()
await expect(page.locator(`[cmdk-item][aria-selected="true"]`)).toHaveAttribute('data-value', 'anteater')
})
test('keep focus on the provided initial value', async ({ page }) => {
await page.goto('/props?initialValue=anteater')
await expect(page.locator(`[cmdk-item][aria-selected="true"]`)).toHaveAttribute('data-value', 'anteater')
})
})