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

47 lines
1.9 KiB
TypeScript

import { test, expect } from '@playwright/test';
test.describe('Authentication Flow', () => {
test('should handle login, registration, and logout', async ({ page }) => {
// Visit site → redirects to /home → see bottom nav
await page.goto('/');
await expect(page.locator('nav')).toBeVisible();
// Click Profile tab to find Login button
await page.click('text=Profile');
await expect(page).toHaveURL(/\/profile/);
// Click Login → see login form
await page.click('a[href="/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
await page.click('a[href="/register"]');
// Fill registration form → submit → redirect to home
const randomEmail = `newuser_${Date.now()}_${Math.floor(Math.random() * 1000)}@example.com`;
await page.fill('input[type="text"]', 'Test User');
await page.fill('input[type="email"]', randomEmail);
await page.fill('input[placeholder="Min. 8 characters"]', 'securepassword123');
await page.click('button[type="submit"]');
// Check redirect and authentication state
await expect(page).toHaveURL(/\/nur/);
// Go to Profile tab and check authenticated state
await page.click('text=Profile');
await expect(page.locator('nav')).toContainText('Profile');
await expect(page.locator('button:has-text("Logout")')).toBeVisible();
// Click logout → redirect to login → see login button
await page.click('button:has-text("Logout")');
await expect(page).toHaveURL(/\/login/);
await expect(page.locator('button:has-text("Sign In")')).toBeVisible();
});
});