import { fireEvent, render, screen } from "@testing-library/react";
import { expect, test, vi } from "vitest";
import { DateTimePicker } from "@/shared/ui/DateTimePicker.jsx";

test("selects one business date and time without submitting an outer form", () => {
    const onChange = vi.fn();
    const initial = new Date(2026, 6, 13, 14, 30, 0, 0).getTime();
    render(<DateTimePicker label="订单时间" value={initial} onChange={onChange} />);

    fireEvent.click(screen.getByRole("button", { name: /订单时间/ }));
    fireEvent.click(screen.getByRole("button", { name: "2026-07-11" }));
    fireEvent.click(screen.getByRole("button", { name: "确定" }));

    expect(onChange).toHaveBeenCalledWith(new Date(2026, 6, 11, 14, 30, 0, 0).getTime());
});
