import { test, expect } from '@playwright/test';

/**
 * EN: E2E tests for authentication flows
 * VI: E2E tests cho các luồng xác thực
 */
test.describe('Authentication', () => {
  test.beforeEach(async ({ page }) => {
    // EN: Navigate to login page / VI: Điều hướng đến trang login
    await page.goto('/login');
  });

  test('should display login page', async ({ page }) => {
    await expect(page.getByText('Sign In / Đăng nhập')).toBeVisible();
    await expect(page.getByPlaceholderText(/email/i)).toBeVisible();
    await expect(page.getByPlaceholderText(/password/i)).toBeVisible();
  });

  test('should show validation errors for empty form', async ({ page }) => {
    await page.getByRole('button', { name: /sign in/i }).click();
    // EN: Check for validation errors / VI: Kiểm tra lỗi validation
    await expect(page.getByText(/email is required/i)).toBeVisible();
  });

  test('should navigate to register page', async ({ page }) => {
    await page.getByRole('link', { name: /sign up/i }).click();
    await expect(page).toHaveURL(/.*\/register/);
  });

  test('should navigate to forgot password page', async ({ page }) => {
    await page.getByRole('link', { name: /forgot password/i }).click();
    await expect(page).toHaveURL(/.*\/forgot-password/);
  });
});
