유닛테스트 수정
This commit is contained in:
@@ -12,10 +12,10 @@ describe("PublicPageRenderer - 폼 제출 메시지", () => {
|
||||
cleanup();
|
||||
// fetch 목 초기화
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(global as any).fetch = undefined;
|
||||
(globalThis as any).fetch = undefined;
|
||||
});
|
||||
|
||||
it("FormBlock 이 있어도 프리뷰에서는 폼 컨트롤러를 렌더하지 않아야 한다 (성공 메시지 설정)", () => {
|
||||
it("성공 응답 시 FormBlock 의 successMessage 를 성공 메시지로 렌더해야 한다", async () => {
|
||||
const blocks: Block[] = [
|
||||
{
|
||||
id: "form_success",
|
||||
@@ -25,6 +25,9 @@ describe("PublicPageRenderer - 폼 제출 메시지", () => {
|
||||
submitTarget: "internal",
|
||||
successMessage: "폼 성공 메시지 (config)",
|
||||
errorMessage: "폼 에러 메시지 (config)",
|
||||
fields: [
|
||||
{ id: "f1", name: "name", label: "이름", type: "text", required: true },
|
||||
],
|
||||
fieldIds: [],
|
||||
submitButtonId: null,
|
||||
} as any,
|
||||
@@ -38,16 +41,32 @@ describe("PublicPageRenderer - 폼 제출 메시지", () => {
|
||||
}),
|
||||
);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(global as any).fetch = fetchMock;
|
||||
(globalThis as any).fetch = fetchMock;
|
||||
|
||||
render(<PublicPageRenderer blocks={blocks} />);
|
||||
|
||||
const form = screen.queryByTestId("preview-form-controller");
|
||||
expect(form).toBeNull();
|
||||
expect(fetchMock).not.toHaveBeenCalled();
|
||||
const form = screen.getByTestId("preview-form-controller") as HTMLFormElement;
|
||||
expect(form).toBeTruthy();
|
||||
|
||||
const input = form.querySelector('input[name="name"]') as HTMLInputElement | null;
|
||||
expect(input).not.toBeNull();
|
||||
|
||||
const submitButton = screen.getByRole("button", { name: "폼 전송" });
|
||||
expect(submitButton).toBeTruthy();
|
||||
|
||||
fireEvent.submit(form);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
const msg = screen.getByText("폼 성공 메시지 (config)");
|
||||
expect(msg).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
it("FormBlock 이 있어도 프리뷰에서는 폼 컨트롤러나 에러 메시지를 렌더하지 않아야 한다", () => {
|
||||
it("실패 응답 시 FormBlock 의 errorMessage 를 에러 메시지로 렌더해야 한다", async () => {
|
||||
const blocks: Block[] = [
|
||||
{
|
||||
id: "form_error",
|
||||
@@ -57,6 +76,9 @@ describe("PublicPageRenderer - 폼 제출 메시지", () => {
|
||||
submitTarget: "internal",
|
||||
successMessage: "폼 성공 메시지 (config)",
|
||||
errorMessage: "폼 에러 메시지 (config)",
|
||||
fields: [
|
||||
{ id: "f1", name: "name", label: "이름", type: "text", required: true },
|
||||
],
|
||||
fieldIds: [],
|
||||
submitButtonId: null,
|
||||
} as any,
|
||||
@@ -70,13 +92,25 @@ describe("PublicPageRenderer - 폼 제출 메시지", () => {
|
||||
}),
|
||||
);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(global as any).fetch = fetchMock;
|
||||
(globalThis 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();
|
||||
const form = screen.getByTestId("preview-form-controller") as HTMLFormElement;
|
||||
expect(form).toBeTruthy();
|
||||
|
||||
const submitButton = screen.getByRole("button", { name: "폼 전송" });
|
||||
expect(submitButton).toBeTruthy();
|
||||
|
||||
fireEvent.submit(form);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
const errorMsg = screen.getByText("폼 에러 메시지 (config)");
|
||||
expect(errorMsg).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user