Files
falah-mobile/e2e/auth-flow.spec.ts
T

39 lines
1.5 KiB
TypeScript
Raw Normal View History

2026-07-02 20:01:48 +08:00
import { test, expect } from '@playwright/test';
test.describe('Authentication Flow', () => {
test('should handle login, registration, and logout', async ({ page }) => {
// Visit site → home page loads → see navbar
await page.goto('/');
await expect(page.locator('nav')).toBeVisible();
// Click Login → see login form
await page.click('text=Login');
await expect(page.locator('form')).toBeVisible();
// Try invalid login → see error message
await page.fill('input[type="email"]', 'invalid@example.com');
await page.fill('input[type="password"]', 'wrongpassword');
await page.click('button[type="submit"]');
await expect(page.locator('text=Invalid credentials')).toBeVisible();
// Navigate to registration (assuming a link exists on login page)
await page.click('text=Register');
// Fill registration form → submit → redirect to home
await page.fill('input[name="name"]', 'Test User');
await page.fill('input[name="email"]', 'newuser@example.com');
await page.fill('input[name="password"]', 'securepassword123');
await page.click('button[type="submit"]');
// Check redirect and authentication state
await expect(page).toHaveURL('/');
// See user menu or similar in navbar when authenticated
await expect(page.locator('nav')).toContainText('Logout');
// Click logout → redirect to home → see login button
await page.click('text=Logout');
await expect(page).toHaveURL('/');
await expect(page.locator('text=Login')).toBeVisible();
});
});