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

const TEST_USER = {
  email: "admin@example.com",
  password: "admin@123",
};

test.describe("登录跳转测试（系统Chrome）", () => {
  test.skip(({ browserName }) => browserName !== "chromium", "Chrome only");

  test("登录成功后应跳转到dashboard并保持在dashboard", async ({ page }) => {
    await page.goto("/login");
    await page.waitForLoadState("domcontentloaded");

    await page.locator("#email").fill(TEST_USER.email);
    await page.locator("#password").fill(TEST_USER.password);
    await page.getByRole("button", { name: /登录/ }).click();

    try {
      await expect(page).toHaveURL(/\/dashboard/, { timeout: 30000 });
    } catch {
      await page.locator("#email").fill(TEST_USER.email);
      await page.locator("#password").fill(TEST_USER.password);
      await page.getByRole("button", { name: /登录/ }).click();
      await expect(page).toHaveURL(/\/dashboard/, { timeout: 30000 });
    }

    await page.waitForLoadState("networkidle");
    await expect(page).toHaveURL(/\/dashboard/);
    await expect(page.getByText("品牌健康中心", { exact: false })).toBeVisible({ timeout: 10000 });
  });
});
