// @vitest-environment jsdom
import { describe, it, expect, vi } from "vitest";
import { render, screen, fireEvent } from "@testing-library/react";
import { DaySelect } from "./DaySelect.js";

describe("DaySelect", () => {
  it("renders a select with data-testid", () => {
    render(<DaySelect selectedDate="20260416" availableDates={["20260416"]} locale="en" onNavigate={() => {}} />);
    expect(screen.getByTestId("day-select")).toBeTruthy();
  });

  it("renders one option per available date", () => {
    render(
      <DaySelect
        selectedDate="20260416"
        availableDates={["20260415", "20260416", "20260417"]}
        locale="en"
        onNavigate={() => {}}
      />,
    );
    const select = screen.getByTestId("day-select") as HTMLSelectElement;
    expect(select.options).toHaveLength(3);
  });

  it("has selectedDate as select value", () => {
    render(
      <DaySelect
        selectedDate="20260416"
        availableDates={["20260415", "20260416", "20260417"]}
        locale="en"
        onNavigate={() => {}}
      />,
    );
    const select = screen.getByTestId("day-select") as HTMLSelectElement;
    expect(select.value).toBe("20260416");
  });

  it("fires onNavigate with new date on change", () => {
    const onNavigate = vi.fn();
    render(
      <DaySelect
        selectedDate="20260416"
        availableDates={["20260415", "20260416", "20260417"]}
        locale="en"
        onNavigate={onNavigate}
      />,
    );
    fireEvent.change(screen.getByTestId("day-select"), { target: { value: "20260417" } });
    expect(onNavigate).toHaveBeenCalledWith("20260417");
  });
});
