import type React from "react";
import { act } from "react";
import { createRoot } from "react-dom/client";
import { afterEach, describe, expect, it } from "vitest";
import { Separator } from "./separator";

let container: HTMLDivElement | null = null;

const render = async (element: React.ReactElement) => {
  container = document.createElement("div");
  document.body.appendChild(container);
  const root = createRoot(container);
  await act(async () => {
    root.render(element);
  });
  return root;
};

afterEach(() => {
  if (container) {
    container.remove();
    container = null;
  }
});

describe("Separator", () => {
  it("renders a horizontal separator with custom classes", async () => {
    const root = await render(
      <Separator className="custom-separator" data-testid="separator" />,
    );

    const separator = container?.querySelector("[data-testid='separator']");

    expect(separator?.className).toContain("h-px");
    expect(separator?.className).toContain("custom-separator");

    await act(async () => {
      root.unmount();
    });
  });
});
