// TrendWindowSelect: offers exactly the engine's trend-window presets (so
// the UI can never offer a window the API rejects), fires onChange with
// the picked key, and labels the select for accessibility.

import { describe, expect, it, vi } from "vitest";
import { fireEvent, render, screen } from "@testing-library/react";
import { TrendWindowSelect } from "@/components/regions/TrendWindowSelect";
import { TREND_WINDOWS } from "@/engine/trend-window";

describe("TrendWindowSelect", () => {
  it("offers exactly the engine's trend-window presets, keyed by window", () => {
    render(<TrendWindowSelect value="24h" onChange={() => {}} />);
    const select = screen.getByRole("combobox", { name: "trend time range" });
    const keys = [...select.querySelectorAll("option")].map((o) => o.getAttribute("value"));
    expect(keys).toEqual(TREND_WINDOWS.map((w) => w.key));
    expect((select as HTMLSelectElement).value).toBe("24h");
  });

  it("fires onChange with the picked window key", () => {
    const onChange = vi.fn();
    render(<TrendWindowSelect value="24h" onChange={onChange} />);
    fireEvent.change(screen.getByRole("combobox", { name: "trend time range" }), {
      target: { value: "7d" },
    });
    expect(onChange).toHaveBeenCalledWith("7d");
  });
});
