83 lines
2.7 KiB
TypeScript
83 lines
2.7 KiB
TypeScript
import { describe, it, expect, afterEach, vi } from "vitest";
|
|
import { render, screen, fireEvent, cleanup, waitFor } from "@testing-library/react";
|
|
import { PublicPageRenderer } from "@/features/editor/components/PublicPageRenderer";
|
|
import type { Block } from "@/features/editor/state/editorStore";
|
|
|
|
// PublicPageRenderer 폼 제출 UX TDD
|
|
// - 성공 응답 시 FormBlockProps 의 successMessage 를 success 스타일로 표시해야 한다.
|
|
// - 실패 응답 시 FormBlockProps 의 errorMessage 를 error 스타일로 표시해야 한다.
|
|
|
|
describe("PublicPageRenderer - 폼 제출 메시지", () => {
|
|
afterEach(() => {
|
|
cleanup();
|
|
// fetch 목 초기화
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
(global as any).fetch = undefined;
|
|
});
|
|
|
|
it("FormBlock 이 있어도 프리뷰에서는 폼 컨트롤러를 렌더하지 않아야 한다 (성공 메시지 설정)", () => {
|
|
const blocks: Block[] = [
|
|
{
|
|
id: "form_success",
|
|
type: "form",
|
|
props: {
|
|
kind: "contact",
|
|
submitTarget: "internal",
|
|
successMessage: "폼 성공 메시지 (config)",
|
|
errorMessage: "폼 에러 메시지 (config)",
|
|
fieldIds: [],
|
|
submitButtonId: null,
|
|
} as any,
|
|
},
|
|
];
|
|
|
|
const fetchMock = vi.fn(async () =>
|
|
new Response("ok", {
|
|
status: 200,
|
|
headers: { "Content-Type": "text/plain" },
|
|
}),
|
|
);
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
(global as any).fetch = fetchMock;
|
|
|
|
render(<PublicPageRenderer blocks={blocks} />);
|
|
|
|
const form = screen.queryByTestId("preview-form-controller");
|
|
expect(form).toBeNull();
|
|
expect(fetchMock).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("FormBlock 이 있어도 프리뷰에서는 폼 컨트롤러나 에러 메시지를 렌더하지 않아야 한다", () => {
|
|
const blocks: Block[] = [
|
|
{
|
|
id: "form_error",
|
|
type: "form",
|
|
props: {
|
|
kind: "contact",
|
|
submitTarget: "internal",
|
|
successMessage: "폼 성공 메시지 (config)",
|
|
errorMessage: "폼 에러 메시지 (config)",
|
|
fieldIds: [],
|
|
submitButtonId: null,
|
|
} as any,
|
|
},
|
|
];
|
|
|
|
const fetchMock = vi.fn(async () =>
|
|
new Response("error", {
|
|
status: 500,
|
|
headers: { "Content-Type": "text/plain" },
|
|
}),
|
|
);
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
(global as any).fetch = fetchMock;
|
|
|
|
render(<PublicPageRenderer blocks={blocks} />);
|
|
|
|
const form = screen.queryByTestId("preview-form-controller");
|
|
expect(form).toBeNull();
|
|
expect(fetchMock).not.toHaveBeenCalled();
|
|
expect(screen.queryByText("폼 에러 메시지 (config)")).toBeNull();
|
|
});
|
|
});
|