import "../../../tests/web/test-utils";
import { render } from "@testing-library/react";
import { describe, expect, test, vi } from "bun:test";

import { RefreshCountdown } from "../../../src/web/components/RefreshCountdown";

describe("RefreshCountdown", () => {
  test("手动模式不崩溃", () => {
    const { container } = render(
      <RefreshCountdown
        dashboardUpdatedAt={0}
        isFetching={false}
        isManualRefresh={true}
        onRefresh={vi.fn()}
        refreshInterval={30000}
      />,
    );

    expect(container.firstChild).not.toBeNull();
  });

  test("自动模式不崩溃", () => {
    const now = Date.now();
    const { container } = render(
      <RefreshCountdown
        dashboardUpdatedAt={now - 10000}
        isFetching={false}
        isManualRefresh={false}
        onRefresh={vi.fn()}
        refreshInterval={30000}
      />,
    );

    expect(container.firstChild).not.toBeNull();
  });

  test("fetching 状态不崩溃", () => {
    const { container } = render(
      <RefreshCountdown
        dashboardUpdatedAt={1000}
        isFetching={true}
        isManualRefresh={false}
        onRefresh={vi.fn()}
        refreshInterval={30000}
      />,
    );

    expect(container.firstChild).not.toBeNull();
  });

  test("未刷新状态不崩溃", () => {
    const { container } = render(
      <RefreshCountdown
        dashboardUpdatedAt={0}
        isFetching={false}
        isManualRefresh={false}
        onRefresh={vi.fn()}
        refreshInterval={30000}
      />,
    );

    expect(container.firstChild).not.toBeNull();
  });
});
