import { test, expect } from "@playwright/test";
import { makeEntry, mockApi, 登录 } from "../测试夹具";

test.describe("统计与查询：未分类和分类轮盘", () => {
  test("01-统计未分类跳转查询后能显示对应流水", async ({ page }) => {
    await mockApi(page, { initialEntries: [makeEntry({ categoryId: "expense", note: "待归类午餐" })] });
    await 登录(page);
    await page.goto("/stats?tab=category&range=month&month=2026-08");

    await page.locator(".category-stat-row", { hasText: "支出" }).click();
    const uncategorized = page.locator(".category-stat-row", { hasText: "未分类" });
    await expect(uncategorized).toBeVisible();
    await uncategorized.getByRole("button", { name: "查看该分类流水" }).click();

    await expect(page).toHaveURL(/\/query\?.*cat=expense(?::|%3A)uncategorized/);
    await expect(page.getByText("待归类午餐")).toBeVisible();
    await expect(page.getByRole("button", { name: /分类.*支出未分类/ })).toBeVisible();
    await page.getByRole("button", { name: "打开查询条件" }).click();
    await expect(page.getByRole("button", { name: "取消支出未分类" })).toBeVisible();
  });

  test("02-分类轮盘默认显示支出大类，返回后显示收支类型", async ({ page }) => {
    await mockApi(page);
    await 登录(page);
    await page.getByRole("button", { name: "记一笔" }).click();
    await page.getByRole("button", { name: /选择分类，当前为支出/ }).click();

    await expect(page.getByRole("button", { name: "餐饮" })).toBeVisible();
    await expect(page.getByRole("button", { name: "收入", exact: true })).not.toBeVisible();
    await page.getByRole("button", { name: "返回上一级" }).click();
    await expect(page.getByRole("button", { name: "支出", exact: true })).toBeVisible();
    await expect(page.getByRole("button", { name: "收入", exact: true })).toBeVisible();
  });
});
