40 lines
1.6 KiB
TypeScript
40 lines
1.6 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
import { setupSessionErrorMock } from './mocks';
|
|
|
|
test.describe('Toast notifications', () => {
|
|
test('shows error toast when session creation fails', async ({ page }) => {
|
|
await setupSessionErrorMock(page);
|
|
await page.goto('/');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
// Toast with a connection/session error message appears.
|
|
// In React dev StrictMode effects may fire twice — use first().
|
|
const toast = page.getByText(/Could not connect|Session creation failed|POST \/session failed/).first();
|
|
await expect(toast).toBeVisible({ timeout: 8000 });
|
|
});
|
|
|
|
test('toast auto-dismisses after 5 seconds', async ({ page }) => {
|
|
await setupSessionErrorMock(page);
|
|
await page.goto('/');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
const toast = page.getByText(/Could not connect|Session creation failed/).first();
|
|
await expect(toast).toBeVisible({ timeout: 8000 });
|
|
|
|
// Wait for auto-dismiss (5s) plus 2s buffer
|
|
await expect(toast).not.toBeVisible({ timeout: 8000 });
|
|
});
|
|
|
|
test('toast has drag="x" attribute for swipe-to-dismiss', async ({ page }) => {
|
|
await setupSessionErrorMock(page);
|
|
await page.goto('/');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
const toast = page.getByText(/Could not connect|Session creation failed/).first();
|
|
await expect(toast).toBeVisible({ timeout: 8000 });
|
|
|
|
// Framer-motion sets draggable="false" on the host element when drag="x" is active
|
|
const draggableEl = toast.locator('xpath=ancestor-or-self::div[@draggable]').first();
|
|
await expect(draggableEl).toHaveAttribute('draggable', 'false');
|
|
});
|
|
});
|