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

test.describe("报销：从支出详情记录", () => {
  test("01-支出详情可以记录部分报销并保留原支出", async ({ page }) => {
    await mockApi(page, { initialEntries: [makeEntry({ amount: 3200 })] });
    await 登录(page);
    await page.getByText("午餐").click();
    await page.getByRole("button", { name: "记录报销" }).click();
    await page.getByLabel("本次报销金额").fill("20");
    await page.getByRole("button", { name: "确认报销" }).click();
    await expect(page.getByText(/已报销/)).toBeVisible();
    await expect(page.getByText("净支出")).toBeVisible();
  });

  test("02-报销金额不能超过原支出的剩余金额", async ({ page }) => {
    await mockApi(page, { initialEntries: [makeEntry({ amount: 3200 })] });
    await 登录(page);
    await page.getByText("午餐").click();
    await page.getByRole("button", { name: "记录报销" }).click();
    await page.getByLabel("本次报销金额").fill("3201");
    await page.getByRole("button", { name: "确认报销" }).click();
    await expect(page.locator("form.reimbursement-sheet").getByText(/不超过剩余可报销金额/)).toBeVisible();
  });

  test("03-报销到账不出现在普通收入分类统计中", async ({ page }) => {
    await mockApi(page, { initialEntries: [makeEntry(), makeEntry({ id: "reimbursement", type: "income", amount: 1000, categoryId: "restaurant", reimbursementOfEntryId: "entry-lunch", note: "午餐报销" })] });
    await 登录(page);
    await page.goto("/stats");
    await expect(page.getByText("报销到账")).not.toBeVisible();
  });
});
