/** * @file EditorModal.test.tsx * @description Unit tests for the tool-agnostic `EditorModal`: it must load * existing content through the injected `fetchContent` callback rather than * a hardcoded API, and must refuse to save a create with no name. * @author Nguyễn Ngọc Trí Vĩ */ import { describe, it, expect, vi } from "vitest"; import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { EditorModal } from "../EditorModal"; describe("EditorModal", () => { it("loads the existing body through the injected fetcher, not a hardcoded API", async () => { const fetchContent = vi.fn().mockResolvedValue("old body"); render( {}} onSave={async () => {}} /> ); expect(fetchContent).toHaveBeenCalledWith("/r/default.rules"); expect(await screen.findByDisplayValue("old body")).toBeInTheDocument(); }); it("refuses to save a create with no name", async () => { const onSave = vi.fn(); render( ""} onClose={() => {}} onSave={onSave} /> ); await userEvent.click(screen.getByRole("button", { name: /save/i })); expect(onSave).not.toHaveBeenCalled(); }); });