import React from "react";
import { describe, it, expect, vi } from "vitest";
import { fireEvent, render, screen } from "@testing-library/react";
import { Select } from "./index";
describe("Select", () => {
    it("renders correctly", () => {
        const onChange = vi.fn();
        const name = "testSelect";
        const items = [
            { value: "item-1", label: "Item 1" },
            { value: "item-2", label: "Item 2" },
        ];
        render(React.createElement(Select, { name: name, items: items, onChange: onChange }));
        const select = screen.getByTestId("select-testSelect");
        expect(select).toBeInTheDocument();
        expect(select.getAttribute("data-state")).toBe("closed");
    });
    it("displays the placeholder when no item is selected", () => {
        var _a;
        const onChange = vi.fn();
        const name = "testSelect";
        const items = [
            { value: "item-1", label: "Item 1" },
            { value: "item-2", label: "Item 2" },
        ];
        render(React.createElement(Select, { placeholder: "Select an option", items: items, onChange: onChange, name: name }));
        expect(screen.getByText("Select an option")).toBeInTheDocument();
        const select = screen.getByTestId("select-testSelect");
        const selectValue = (_a = select.querySelector("span")) === null || _a === void 0 ? void 0 : _a.textContent;
        expect(selectValue).toBe("Select an option");
    });
    it("disables the select when disabled prop is true", () => {
        const onChange = vi.fn();
        const name = "testSelect";
        const items = [
            { value: "item-1", label: "Item 1" },
            { value: "item-2", label: "Item 2" },
        ];
        render(React.createElement(Select, { placeholder: "Select an option", items: items, onChange: onChange, name: name, disabled: true }));
        const select = screen.getByTestId("select-testSelect");
        expect(select).toBeDisabled();
    });
    it("handles click on select correctly", () => {
        const onChange = vi.fn();
        const name = "testSelect";
        const items = [
            { value: "item-1", label: "Item 1" },
            { value: "item-2", label: "Item 2" },
        ];
        render(React.createElement(Select, { name: name, items: items, onChange: onChange }));
        const select = screen.getByTestId("select-testSelect");
        fireEvent.click(select);
        expect(select.getAttribute("data-state")).toBe("open");
        expect(screen.getByText("Item 1")).toBeInTheDocument();
    });
    it("handles click on item correctly", () => {
        var _a;
        const onChange = vi.fn();
        const name = "testSelect";
        const items = [
            { value: "item-1", label: "Item 1" },
            { value: "item-2", label: "Item 2" },
        ];
        render(React.createElement(Select, { name: name, items: items, onChange: onChange }));
        const select = screen.getByTestId("select-testSelect");
        fireEvent.click(select);
        const item = screen.getByText("Item 1");
        fireEvent.click(item);
        expect(onChange).toHaveBeenCalledWith("item-1");
        expect(select.getAttribute("data-state")).toBe("closed");
        const selectValue = (_a = select.querySelector("span")) === null || _a === void 0 ? void 0 : _a.textContent;
        expect(selectValue).toBe("Item 1");
    });
});
//# sourceMappingURL=index.test.js.map