|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +const randomEmail = () => `dashboard_ui_${Date.now()}_${Math.random().toString(36).slice(2)}@example.com`; |
| 4 | + |
| 5 | +test.describe('Dashboard UI', () => { |
| 6 | + test('User can log in and view dashboard', async ({ page, request }) => { |
| 7 | + const email = randomEmail(); |
| 8 | + const password = 'PasswordUI123!'; |
| 9 | + |
| 10 | + // Seed user via API to avoid UI registration flakiness in testing |
| 11 | + const apiBaseUrl = process.env.E2E_API_BASE_URL ?? 'http://localhost:3001/api/v1'; |
| 12 | + const registerResp = await request.post(`${apiBaseUrl}/auth/register`, { |
| 13 | + data: { name: 'UI User', email, password }, |
| 14 | + }); |
| 15 | + expect(registerResp.ok()).toBeTruthy(); |
| 16 | + |
| 17 | + await test.step('Log into web app', async () => { |
| 18 | + await page.goto('/login'); |
| 19 | + await page.fill('input[type="email"]', email); |
| 20 | + await page.fill('input[type="password"]', password); |
| 21 | + await page.click('button[type="submit"]'); |
| 22 | + |
| 23 | + // Should redirect to dashboard |
| 24 | + await expect(page).toHaveURL(/\/dashboard/); |
| 25 | + }); |
| 26 | + |
| 27 | + await test.step('Verify Dashboard Elements', async () => { |
| 28 | + // Check for navigation or header |
| 29 | + await expect(page.locator('h1', { hasText: 'Dashboard' }).first()).toBeVisible(); |
| 30 | + |
| 31 | + // Removed flaky networkidle wait |
| 32 | + |
| 33 | + |
| 34 | + // The user doesn't have any groups yet, so check for empty state |
| 35 | + await expect(page.getByText('group', { exact: false }).first()).toBeVisible(); |
| 36 | + }); |
| 37 | + }); |
| 38 | +}); |
0 commit comments