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 }) => {
|
2026-07-08 18:07:07 +08:00
|
|
|
// Visit site → redirects to /home → see bottom nav
|
2026-07-02 20:01:48 +08:00
|
|
|
await page.goto('/');
|
|
|
|
|
await expect(page.locator('nav')).toBeVisible();
|
|
|
|
|
|
2026-07-08 18:07:07 +08:00
|
|
|
// Click Profile tab to find Login button
|
|
|
|
|
await page.click('text=Profile');
|
|
|
|
|
await expect(page).toHaveURL(/\/profile/);
|
|
|
|
|
|
2026-07-02 20:01:48 +08:00
|
|
|
// Click Login → see login form
|
2026-07-08 18:07:07 +08:00
|
|
|
await page.click('a[href="/login"]');
|
2026-07-02 20:01:48 +08:00
|
|
|
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();
|
|
|
|
|
|
2026-07-08 18:07:07 +08:00
|
|
|
// Navigate to registration
|
|
|
|
|
await page.click('a[href="/register"]');
|
2026-07-02 20:01:48 +08:00
|
|
|
|
|
|
|
|
// Fill registration form → submit → redirect to home
|
2026-07-08 18:07:07 +08:00
|
|
|
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');
|
2026-07-02 20:01:48 +08:00
|
|
|
await page.click('button[type="submit"]');
|
|
|
|
|
|
|
|
|
|
// Check redirect and authentication state
|
2026-07-08 18:07:07 +08:00
|
|
|
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();
|
2026-07-02 20:01:48 +08:00
|
|
|
|
2026-07-08 18:07:07 +08:00
|
|
|
// 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();
|
2026-07-02 20:01:48 +08:00
|
|
|
});
|
|
|
|
|
});
|