import { act, render, screen } from "@testing-library/react"; import { afterEach, beforeEach, expect, test, vi } from "vitest"; import { DatabiApp } from "./DatabiApp.jsx"; import { fetchFilterOptions, fetchSelfGameStatisticsOverview, fetchStatisticsOverview } from "./api.js"; vi.mock("./api.js", () => ({ fetchFilterOptions: vi.fn(), fetchSelfGameStatisticsOverview: vi.fn(), fetchStatisticsOverview: vi.fn(), getCurrentAppCode: vi.fn(() => "lalu"), setCurrentAppCode: vi.fn((value) => String(value || "lalu").toLowerCase()) })); vi.mock("./charts/EChart.jsx", () => ({ EChart: () =>
})); beforeEach(() => { vi.useFakeTimers(); vi.setSystemTime(new Date("2026-06-06T08:00:00Z")); fetchFilterOptions.mockResolvedValue({ appOptions: [{ code: "lalu", label: "Lalu", value: "lalu" }], countryOptions: [{ countryCode: "", id: 0, label: "全部国家", regionIds: [], searchText: "全部国家 all", value: 0 }], regionOptions: [{ countryCodes: [], id: "all", label: "全部区域", value: "all" }] }); fetchSelfGameStatisticsOverview.mockResolvedValue({}); }); afterEach(() => { vi.useRealTimers(); vi.clearAllMocks(); }); test("keeps current data visible during scheduled refresh", async () => { const overview = { active_users: 10, paid_users: 2, recharge_usd_minor: 100, updated_at_ms: 1 }; fetchStatisticsOverview .mockResolvedValueOnce(overview) .mockResolvedValueOnce(overview) .mockImplementationOnce(() => new Promise(() => {})); render(