import "../../../tests/web/test-utils"; import { render, screen } from "@testing-library/react"; import { describe, expect, test, vi } from "bun:test"; import { RefreshCountdown } from "../../../src/web/components/RefreshCountdown"; describe("RefreshCountdown", () => { test("手动模式渲染刷新按钮", () => { const onRefresh = vi.fn(); render( , ); const button = screen.getByRole("button", { name: "刷新 Dashboard" }); expect(button).toBeTruthy(); }); test("等待首次刷新显示文本", () => { render( , ); expect(screen.getByText("等待首次刷新")).toBeTruthy(); }); test("刷新中显示文本", () => { render( , ); expect(screen.getByText("刷新中...")).toBeTruthy(); }); test("秒级间隔渲染 NumberFlow 倒计时", () => { const now = Date.now(); render( , ); const countdown = screen.getByLabelText(/秒$/); expect(countdown).toBeTruthy(); expect(countdown.className).toContain("refresh-countdown-flow"); }); test("分钟级间隔渲染带分秒的 NumberFlow 倒计时", () => { const now = Date.now(); render( , ); const countdown = screen.getByLabelText(/分\d{2}秒$/); expect(countdown).toBeTruthy(); expect(countdown.className).toContain("refresh-countdown-flow"); }); test("5 分钟间隔使用稳定分钟格式", () => { const now = Date.now(); const { container } = render( , ); const countdown = container.querySelector(".refresh-countdown-flow"); expect(countdown).toBeTruthy(); expect(countdown?.getAttribute("aria-label")).toMatch(/分\d{2}秒$/); }); });