import { describe, it, expect } from "vitest";
import { renderHook } from "@testing-library/react";
import { type ReactNode } from "react";
import { useToast, ToastContext, type ToastContextValue } from "./useToast";

describe("useToast", () => {
  it("throws error when used outside provider", () => {
    expect(() => {
      renderHook(() => useToast());
    }).toThrow("useToast must be used within ToastProvider");
  });

  it("returns context value when inside provider", () => {
    const mockShow = () => {};
    const ctxValue: ToastContextValue = { show: mockShow };

    const wrapper = ({ children }: { children: ReactNode }) => (
      <ToastContext.Provider value={ctxValue}>
        {children}
      </ToastContext.Provider>
    );

    const { result } = renderHook(() => useToast(), { wrapper });
    expect(result.current.show).toBe(mockShow);
  });
});
