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

const FRONT_URL = process.env.PLAYWRIGHT_FRONT_URL ?? 'http://localhost:3800';
const USER = process.env.E2E_PLAYER_USERNAME ?? 'demo_player';
const PASS = process.env.E2E_PLAYER_PASSWORD ?? '12345678';

test('玩家端登录 → 进入大厅', async ({ page }) => {
  test.setTimeout(90_000);
  await page.goto(`${FRONT_URL}/login`);

  const userInput = page.locator('#login-user');
  await userInput.waitFor({ state: 'visible', timeout: 60_000 });
  await userInput.fill(USER);
  await page.locator('#login-pass').fill(PASS);

  const captchaImg = page.locator('img[src^="data:image"]');
  await captchaImg.waitFor({ state: 'visible', timeout: 30_000 });

  await page.locator('#login-captcha').fill('LOTTERY_E2E_BYPASS');
  await page.getByRole('button', { name: /^登录$|Sign in|submit/i }).click();

  await page.waitForURL(/\/hall/, { timeout: 45_000 });
  expect(page.url()).toContain('/hall');
});
