|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +test('sheet basic interactions', async ({ page }) => { |
| 4 | + await page.goto('http://127.0.0.1:8080/component/?name=sheet&', { timeout: 20 * 60 * 1000 }); |
| 5 | + |
| 6 | + // Open sheet from Right button |
| 7 | + await page.getByRole('button', { name: 'Right' }).click(); |
| 8 | + |
| 9 | + // Assert the sheet is open |
| 10 | + const sheet = page.locator('.sheet-root'); |
| 11 | + await expect(sheet).toHaveAttribute('data-state', 'open'); |
| 12 | + |
| 13 | + // Assert the first input is focused (focus trap) |
| 14 | + const nameInput = page.locator('#sheet-demo-name'); |
| 15 | + await expect(nameInput).toBeFocused(); |
| 16 | + |
| 17 | + // Tab through focusable elements and verify focus cycles |
| 18 | + // Tab: name input -> username input -> Save button -> Cancel button -> close button -> name input |
| 19 | + await page.keyboard.press('Tab'); |
| 20 | + const usernameInput = page.locator('#sheet-demo-username'); |
| 21 | + await expect(usernameInput).toBeFocused(); |
| 22 | + |
| 23 | + await page.keyboard.press('Tab'); |
| 24 | + const saveButton = page.getByRole('button', { name: 'Save changes' }); |
| 25 | + await expect(saveButton).toBeFocused(); |
| 26 | + |
| 27 | + await page.keyboard.press('Tab'); |
| 28 | + const cancelButton = page.getByRole('button', { name: 'Cancel' }); |
| 29 | + await expect(cancelButton).toBeFocused(); |
| 30 | + |
| 31 | + await page.keyboard.press('Tab'); |
| 32 | + const closeButton = sheet.locator('.sheet-close'); |
| 33 | + await expect(closeButton).toBeFocused(); |
| 34 | + |
| 35 | + // Tab again should cycle back to first input |
| 36 | + await page.keyboard.press('Tab'); |
| 37 | + await expect(nameInput).toBeFocused(); |
| 38 | + |
| 39 | + // Hitting escape should close the sheet |
| 40 | + await page.keyboard.press('Escape'); |
| 41 | + await expect(sheet).toHaveCount(0); |
| 42 | + |
| 43 | + // Reopen the sheet |
| 44 | + await page.getByRole('button', { name: 'Right' }).click(); |
| 45 | + await expect(sheet).toHaveAttribute('data-state', 'open'); |
| 46 | + |
| 47 | + // Click the close button |
| 48 | + await closeButton.click(); |
| 49 | + await expect(sheet).toHaveCount(0); |
| 50 | +}); |
| 51 | + |
| 52 | +test('sheet opens from different sides', async ({ page }) => { |
| 53 | + await page.goto('http://127.0.0.1:8080/component/?name=sheet&', { timeout: 20 * 60 * 1000 }); |
| 54 | + |
| 55 | + const sheet = page.locator('.sheet-root'); |
| 56 | + const sheetContent = page.locator('[data-slot="sheet-content"]'); |
| 57 | + |
| 58 | + // Test Top |
| 59 | + await page.getByRole('button', { name: 'Top' }).click(); |
| 60 | + await expect(sheet).toHaveAttribute('data-state', 'open'); |
| 61 | + await expect(sheetContent).toHaveAttribute('data-side', 'top'); |
| 62 | + await page.keyboard.press('Escape'); |
| 63 | + await expect(sheet).toHaveCount(0); |
| 64 | + |
| 65 | + // Test Bottom |
| 66 | + await page.getByRole('button', { name: 'Bottom' }).click(); |
| 67 | + await expect(sheet).toHaveAttribute('data-state', 'open'); |
| 68 | + await expect(sheetContent).toHaveAttribute('data-side', 'bottom'); |
| 69 | + await page.keyboard.press('Escape'); |
| 70 | + await expect(sheet).toHaveCount(0); |
| 71 | + |
| 72 | + // Test Left |
| 73 | + await page.getByRole('button', { name: 'Left' }).click(); |
| 74 | + await expect(sheet).toHaveAttribute('data-state', 'open'); |
| 75 | + await expect(sheetContent).toHaveAttribute('data-side', 'left'); |
| 76 | + await page.keyboard.press('Escape'); |
| 77 | + await expect(sheet).toHaveCount(0); |
| 78 | +}); |
0 commit comments