import { describe, it, expect, vi } from "vitest";
import { renderToStaticMarkup } from "react-dom/server";
// SSE hook + the server action are deliberately stubbed. The action's
// optimistic result is provided by feeding `useActionState` a manual
// initial state via the mock's exported helper.
const sendTestActionMock = vi.fn();
vi.mock("@/actions/groups", () => ({
sendTestAction: (...args: unknown[]) => sendTestActionMock(...args),
}));
// Capture the handlers the form passes to useEvents so we can fire
// `send_test.done` ourselves and observe the state transition.
const eventHandlers: {
"send_test.done"?: (e: { groupId: string; ok: boolean; error: string | null }) => void;
} = {};
vi.mock("@/hooks/use-events", () => ({
useEvents: (handlers: typeof eventHandlers) => {
Object.assign(eventHandlers, handlers);
},
}));
import { SendTestForm } from "./send-test-form";
describe("SendTestForm — initial render", () => {
it("renders the textarea and submit button, no status pill yet", () => {
const html = renderToStaticMarkup();
expect(html).toMatch(/