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

test("中文界面可以生成优化文章和导出链接", async ({ page }) => {
  await page.goto("/");

  await page.getByLabel("访问密钥").fill("local-dev-key");
  await page.getByLabel("标题").fill("Example Technology Co., Ltd. GEO 指南");
  await page
    .getByLabel("正文")
    .fill(
      "Example Technology Co., Ltd. has 8 years of GEO optimization experience. Example GEO 帮助市场团队优化内容结构。",
    );
  await page.getByLabel("图片描述或图片链接").fill("产品仪表盘截图");
  await page.getByLabel("用户要求").fill("保持事实准确，语气自然。");

  await page.getByRole("button", { name: "分析文章" }).click();
  await expect(page.getByText("候选事实卡已生成。")).toBeVisible();

  await page
    .locator("label")
    .filter({ hasText: "待确认事项" })
    .locator("textarea")
    .fill("");
  await page.getByRole("button", { name: "确认事实卡" }).click();
  await expect(page.getByText("事实卡已确认。")).toBeVisible();

  await page.getByRole("button", { name: "开始优化" }).click();
  await expect(page.getByText("优化完成。")).toBeVisible();
  await expect(page.getByText("质量报告")).toBeVisible();

  await expect(page.getByRole("link", { name: "optimized.md" })).toBeVisible();
  await expect(page.getByRole("link", { name: "optimized.docx" })).toBeVisible();
  await expect(page.getByRole("link", { name: "qa_report.json" })).toBeVisible();
});
