import { render, screen } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import { EmptyState, FreshnessBanner, LoadingState } from "./Feedback";

describe("compact feedback states", () => {
  it("keeps loading and empty states to their functional labels", () => {
    const { rerender } = render(<LoadingState label="正在读取队列" />);
    expect(screen.getByText("正在读取队列")).toBeVisible();
    expect(screen.queryByText("请稍候，页面会保留已成功读取的内容。")).not.toBeInTheDocument();

    rerender(<EmptyState title="暂无号码" />);
    expect(screen.getByText("暂无号码")).toBeVisible();
  });

  it("hides healthy freshness notes and keeps a short offline recovery state", () => {
    const { container, rerender } = render(
      <FreshnessBanner offline={false} stale={false} timestamp="2026-07-11T05:00:00Z" />,
    );
    expect(container).toBeEmptyDOMElement();

    rerender(<FreshnessBanner offline={false} stale={false} refreshing timestamp="2026-07-11T05:00:00Z" />);
    expect(container).toBeEmptyDOMElement();

    rerender(<FreshnessBanner offline stale={false} timestamp="2026-07-11T05:00:00Z" />);
    expect(screen.getByText("连接中断")).toBeVisible();
    expect(screen.queryByText(/纸质号码|人工广播/)).not.toBeInTheDocument();
  });
});
