import { expect, test } from "../fixtures/test";

test.describe("login error mapping", () => {
  test.use({ scenarioId: "auth-upstream-unavailable" });

  test("shows service unavailable copy for upstream 502", async ({ page }) => {
    await page.goto("/login");
    await page.getByLabel("账号或邮箱").fill("alice@example.com");
    await page.getByLabel("密码").fill("not-the-issue");
    await page.getByRole("button", { name: "登录" }).click();
    await expect(page.locator(".form-error")).toContainText("登录服务暂时不可用");
    await expect(page.locator(".form-error")).toContainText("upstream_unavailable");
    await expect(page.locator(".form-error")).not.toContainText("账号或密码不正确");
  });
});

test.describe("login invalid credentials", () => {
  test.use({ scenarioId: "auth-invalid-credentials" });

  test("keeps credential copy for 401", async ({ page }) => {
    await page.goto("/login");
    await page.getByLabel("账号或邮箱").fill("alice@example.com");
    await page.getByLabel("密码").fill("wrong-password");
    await page.getByRole("button", { name: "登录" }).click();
    await expect(page.locator(".form-error")).toContainText("账号或密码不正确");
  });
});
