폼전송 기능 수정
This commit is contained in:
@@ -2114,7 +2114,7 @@ describe("/api/export", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("스타일 테스트", () => {
|
||||
describe("buildStaticHtml", () => {
|
||||
it("text 블록은 pb 텍스트 스타일 클래스를 포함해야 한다", async () => {
|
||||
const blocks: Block[] = [
|
||||
{
|
||||
@@ -2545,6 +2545,50 @@ describe("/api/export", () => {
|
||||
expect(html).toContain("섹션 레이아웃 텍스트");
|
||||
});
|
||||
|
||||
it("FormBlock.submitButtonId 로 매핑된 버튼은 해당 form 을 submit 하는 button 요소로 Export 되어야 한다", async () => {
|
||||
const blocks: Block[] = [
|
||||
{
|
||||
id: "form_1",
|
||||
type: "form",
|
||||
props: {
|
||||
fieldIds: ["field_email"],
|
||||
requiredFieldIds: [],
|
||||
submitButtonId: "submit_btn",
|
||||
},
|
||||
} as any,
|
||||
{
|
||||
id: "field_email",
|
||||
type: "formInput",
|
||||
props: {
|
||||
label: "이메일",
|
||||
formFieldName: "email",
|
||||
},
|
||||
} as any,
|
||||
{
|
||||
id: "submit_btn",
|
||||
type: "button",
|
||||
props: {
|
||||
label: "폼 제출",
|
||||
href: "#",
|
||||
},
|
||||
} as any,
|
||||
];
|
||||
|
||||
const projectConfig: ProjectConfig = {
|
||||
title: "폼 제출 버튼 매핑 테스트",
|
||||
slug: "form-submit-button-mapping-test",
|
||||
canvasPreset: "full",
|
||||
} as ProjectConfig;
|
||||
|
||||
const { buildStaticHtml } = await import("@/app/api/export/route");
|
||||
|
||||
const html = buildStaticHtml(blocks, projectConfig);
|
||||
|
||||
expect(html).toContain('<form id="form_form_1" class="pb-form-controller" method="post" action="/api/forms/submit"');
|
||||
expect(html).toContain('type="submit" form="form_form_1"');
|
||||
expect(html).toContain("폼 제출");
|
||||
});
|
||||
|
||||
it("formInput 블록의 textColorCustom 은 정적 HTML에서 input 텍스트 색상 스타일로 반영되어야 한다", async () => {
|
||||
const blocks: Block[] = [
|
||||
{
|
||||
@@ -3178,6 +3222,7 @@ describe("/api/export", () => {
|
||||
expect(css).toContain(".pb-root-inner");
|
||||
expect(css).toContain("max-width: 72rem");
|
||||
expect(css).toContain(".pb-section-inner");
|
||||
expect(css).toContain("margin-inline: auto");
|
||||
expect(css).toContain(".pb-section-columns");
|
||||
expect(css).toContain("gap: 2rem");
|
||||
expect(css).toContain(".pb-section-column");
|
||||
|
||||
@@ -155,3 +155,106 @@ test("프리뷰 폼 제출 후 제출 내역 페이지에서 데이터가 보여
|
||||
await expect(page.getByText(messageValue)).toBeVisible();
|
||||
}
|
||||
});
|
||||
|
||||
test("퍼블릭 페이지 폼 제출 후 제출 내역 페이지에서 데이터가 보여야 한다", async ({ page, request }) => {
|
||||
const now = Date.now();
|
||||
const email = `public-form-e2e-${now}@example.com`;
|
||||
const password = "public-form-e2e-password";
|
||||
const projectSlug = `public-form-e2e-project-${now}`;
|
||||
|
||||
const signupRes = await request.post("/api/auth/signup", {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
data: { email, password },
|
||||
});
|
||||
|
||||
expect(signupRes.status()).toBe(201);
|
||||
|
||||
const setCookieHeader = signupRes.headers()["set-cookie"];
|
||||
expect(setCookieHeader).toBeTruthy();
|
||||
|
||||
const cookieHeaderString = Array.isArray(setCookieHeader)
|
||||
? setCookieHeader.join("; ")
|
||||
: (setCookieHeader as string);
|
||||
|
||||
const match = cookieHeaderString.match(/pb_access=([^;]+)/);
|
||||
expect(match).not.toBeNull();
|
||||
|
||||
const accessToken = match![1];
|
||||
|
||||
await page.context().addCookies([
|
||||
{
|
||||
name: "pb_access",
|
||||
value: accessToken,
|
||||
domain: "localhost",
|
||||
path: "/",
|
||||
httpOnly: true,
|
||||
secure: false,
|
||||
sameSite: "Lax",
|
||||
},
|
||||
]);
|
||||
|
||||
await page.goto("/editor");
|
||||
|
||||
const propertiesSidebar = page.getByTestId("properties-sidebar");
|
||||
await propertiesSidebar.getByLabel("프로젝트 제목").fill("E2E 퍼블릭 폼 프로젝트");
|
||||
await propertiesSidebar.getByLabel("프로젝트 주소 (slug)").fill(projectSlug);
|
||||
|
||||
await page.getByRole("button", { name: "입력(Input)" }).click();
|
||||
await page.getByRole("button", { name: "입력(Input)" }).click();
|
||||
await page.getByRole("button", { name: "입력(Input)" }).click();
|
||||
await page.getByRole("button", { name: "버튼" }).click();
|
||||
await page.getByRole("button", { name: "폼 컨트롤러" }).click();
|
||||
|
||||
const fieldMappingGroup = page.getByRole("group", { name: "폼 필드 매핑" });
|
||||
const fieldCheckboxes = fieldMappingGroup.locator("> label > input[type='checkbox']");
|
||||
const fieldCount = await fieldCheckboxes.count();
|
||||
for (let i = 0; i < fieldCount; i += 1) {
|
||||
await fieldCheckboxes.nth(i).check({ force: true });
|
||||
}
|
||||
|
||||
const submitSelect = page.getByRole("combobox", { name: "Submit 버튼" });
|
||||
await submitSelect.selectOption({ index: 1 });
|
||||
|
||||
await page.getByRole("button", { name: "메뉴 ▼" }).click();
|
||||
await page.getByRole("button", { name: "프로젝트 저장/불러오기" }).click();
|
||||
await page.getByRole("button", { name: "저장 (로컬 + 서버)" }).click();
|
||||
|
||||
await expect(page).toHaveURL(/\/_?projects/);
|
||||
await expect(page.getByText(projectSlug)).toBeVisible();
|
||||
|
||||
await page.goto(`/p/${projectSlug}`);
|
||||
|
||||
const nameValue = "홍길동";
|
||||
const emailValue = `public-submitted-${now}@example.com`;
|
||||
const messageValue = "퍼블릭 E2E 테스트 메시지";
|
||||
|
||||
const inputs = page.locator("input.pb-input");
|
||||
const inputCount = await inputs.count();
|
||||
expect(inputCount).toBeGreaterThanOrEqual(2);
|
||||
|
||||
await inputs.nth(0).fill(nameValue);
|
||||
await inputs.nth(1).fill(emailValue);
|
||||
if (inputCount >= 3) {
|
||||
await inputs.nth(2).fill(messageValue);
|
||||
}
|
||||
|
||||
await page.getByRole("button", { name: "버튼" }).click();
|
||||
|
||||
await expect(page.getByText("성공적으로 전송되었습니다.")).toBeVisible();
|
||||
|
||||
await page.goto("/projects");
|
||||
await expect(page).toHaveURL(/\/_?projects/);
|
||||
|
||||
const submissionsRow = page.locator("tr", { hasText: projectSlug }).first();
|
||||
await submissionsRow.getByRole("link", { name: "폼 제출 내역" }).click();
|
||||
|
||||
await expect(page).toHaveURL(new RegExp(`/projects/${projectSlug}/submissions`));
|
||||
await expect(page.getByRole("heading", { name: "폼 제출 내역" })).toBeVisible();
|
||||
await expect(page.getByText(projectSlug)).toBeVisible();
|
||||
|
||||
await expect(page.getByText(nameValue)).toBeVisible();
|
||||
await expect(page.getByText(emailValue)).toBeVisible();
|
||||
if (inputCount >= 3) {
|
||||
await expect(page.getByText(messageValue)).toBeVisible();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
||||
import { render, cleanup, waitFor } from "@testing-library/react";
|
||||
import EditorPage from "@/app/editor/page";
|
||||
import type { Block, ProjectConfig } from "@/features/editor/state/editorStore";
|
||||
|
||||
let mockState: any;
|
||||
let searchParamsSlug: string | null = null;
|
||||
let searchParamsNew: string | null = null;
|
||||
|
||||
beforeEach(() => {
|
||||
const baseProjectConfig: ProjectConfig = {
|
||||
title: "기존 프로젝트",
|
||||
slug: "existing-slug",
|
||||
canvasPreset: "full",
|
||||
} as ProjectConfig;
|
||||
|
||||
mockState = {
|
||||
blocks: [
|
||||
{
|
||||
id: "blk_existing",
|
||||
type: "text",
|
||||
props: {
|
||||
text: "기존 프로젝트 블록",
|
||||
align: "left",
|
||||
size: "base",
|
||||
},
|
||||
},
|
||||
] as Block[],
|
||||
projectConfig: baseProjectConfig,
|
||||
selectedBlockId: null as string | null,
|
||||
selectedListItemId: null as string | null,
|
||||
undo: vi.fn(),
|
||||
redo: vi.fn(),
|
||||
removeBlock: vi.fn(),
|
||||
duplicateBlock: vi.fn(),
|
||||
selectBlock: vi.fn(),
|
||||
selectListItem: vi.fn(),
|
||||
replaceBlocks: vi.fn((nextBlocks: Block[]) => {
|
||||
mockState.blocks = nextBlocks;
|
||||
}),
|
||||
reorderBlocks: vi.fn(),
|
||||
moveBlock: vi.fn(),
|
||||
addTextBlock: vi.fn(),
|
||||
addButtonBlock: vi.fn(),
|
||||
addImageBlock: vi.fn(),
|
||||
addDividerBlock: vi.fn(),
|
||||
addListBlock: vi.fn(),
|
||||
addSectionBlock: vi.fn(),
|
||||
addFormBlock: vi.fn(),
|
||||
addFormInputBlock: vi.fn(),
|
||||
addFormSelectBlock: vi.fn(),
|
||||
addFormCheckboxBlock: vi.fn(),
|
||||
addFormRadioBlock: vi.fn(),
|
||||
addHeroTemplateSection: vi.fn(),
|
||||
addFeaturesTemplateSection: vi.fn(),
|
||||
addCtaTemplateSection: vi.fn(),
|
||||
addFaqTemplateSection: vi.fn(),
|
||||
addPricingTemplateSection: vi.fn(),
|
||||
addTestimonialsTemplateSection: vi.fn(),
|
||||
addBlogTemplateSection: vi.fn(),
|
||||
addTeamTemplateSection: vi.fn(),
|
||||
addFooterTemplateSection: vi.fn(),
|
||||
updateBlock: vi.fn(),
|
||||
updateProjectConfig: vi.fn((partial: Partial<ProjectConfig>) => {
|
||||
mockState.projectConfig = {
|
||||
...(mockState.projectConfig as ProjectConfig),
|
||||
...partial,
|
||||
} as ProjectConfig;
|
||||
}),
|
||||
resetHistory: vi.fn(),
|
||||
};
|
||||
|
||||
window.localStorage.clear();
|
||||
searchParamsSlug = null;
|
||||
searchParamsNew = null;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
vi.mock("@/features/editor/state/editorStore", () => {
|
||||
const useEditorStore = (selector: (state: any) => any) => selector(mockState);
|
||||
(useEditorStore as any).getState = () => mockState;
|
||||
|
||||
return {
|
||||
__esModule: true,
|
||||
useEditorStore,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("next/link", () => {
|
||||
return {
|
||||
__esModule: true,
|
||||
default: ({ href, children }: any) => <a href={href}>{children}</a>,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("next/navigation", () => {
|
||||
return {
|
||||
__esModule: true,
|
||||
useRouter: () => ({
|
||||
push: vi.fn(),
|
||||
}),
|
||||
useSearchParams: () => ({
|
||||
get: (key: string) => {
|
||||
if (key === "slug") return searchParamsSlug;
|
||||
if (key === "new") return searchParamsNew;
|
||||
return null;
|
||||
},
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe("EditorPage - 프로젝트 목록에서 새 프로젝트 만들기", () => {
|
||||
it("/editor?new=1 로 진입하면 기존 프로젝트 상태를 초기화하고 새 캔버스를 열어야 한다", async () => {
|
||||
searchParamsNew = "1";
|
||||
|
||||
const fetchMock = vi.fn().mockImplementation((input: any, init?: any) => {
|
||||
const url = typeof input === "string" ? input : input.url;
|
||||
const method = init?.method ?? "GET";
|
||||
|
||||
if (url === "/api/auth/me" && method === "GET") {
|
||||
return Promise.resolve(
|
||||
new Response(
|
||||
JSON.stringify({ id: "user-1", email: "user@example.com", tokenVersion: 1 }),
|
||||
{
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.resolve(new Response(null, { status: 200 }));
|
||||
});
|
||||
|
||||
vi.stubGlobal("fetch", fetchMock as any);
|
||||
|
||||
render(<EditorPage />);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetchMock).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(Array.isArray(mockState.blocks)).toBe(true);
|
||||
expect(mockState.blocks.length).toBe(0);
|
||||
|
||||
const slug = (mockState.projectConfig as ProjectConfig).slug;
|
||||
expect(slug).not.toBe("existing-slug");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,289 @@
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
||||
import { render, cleanup, waitFor } from "@testing-library/react";
|
||||
import EditorPage from "@/app/editor/page";
|
||||
import type { Block, ProjectConfig } from "@/features/editor/state/editorStore";
|
||||
|
||||
let mockState: any;
|
||||
let searchParamsSlug: string | null = null;
|
||||
|
||||
beforeEach(() => {
|
||||
const baseProjectConfig: ProjectConfig = {
|
||||
title: "서버 자동저장 테스트",
|
||||
slug: "my-landing",
|
||||
canvasPreset: "full",
|
||||
} as ProjectConfig;
|
||||
|
||||
mockState = {
|
||||
blocks: [
|
||||
{
|
||||
id: "blk_1",
|
||||
type: "text",
|
||||
props: {
|
||||
text: "서버 자동저장 블록",
|
||||
align: "left",
|
||||
size: "base",
|
||||
},
|
||||
},
|
||||
] as Block[],
|
||||
projectConfig: baseProjectConfig,
|
||||
selectedBlockId: null as string | null,
|
||||
selectedListItemId: null as string | null,
|
||||
undo: vi.fn(),
|
||||
redo: vi.fn(),
|
||||
removeBlock: vi.fn(),
|
||||
duplicateBlock: vi.fn(),
|
||||
selectBlock: vi.fn(),
|
||||
selectListItem: vi.fn(),
|
||||
replaceBlocks: vi.fn(),
|
||||
reorderBlocks: vi.fn(),
|
||||
moveBlock: vi.fn(),
|
||||
addTextBlock: vi.fn(),
|
||||
addButtonBlock: vi.fn(),
|
||||
addImageBlock: vi.fn(),
|
||||
addDividerBlock: vi.fn(),
|
||||
addListBlock: vi.fn(),
|
||||
addSectionBlock: vi.fn(),
|
||||
addFormBlock: vi.fn(),
|
||||
addFormInputBlock: vi.fn(),
|
||||
addFormSelectBlock: vi.fn(),
|
||||
addFormCheckboxBlock: vi.fn(),
|
||||
addFormRadioBlock: vi.fn(),
|
||||
addHeroTemplateSection: vi.fn(),
|
||||
addFeaturesTemplateSection: vi.fn(),
|
||||
addCtaTemplateSection: vi.fn(),
|
||||
addFaqTemplateSection: vi.fn(),
|
||||
addPricingTemplateSection: vi.fn(),
|
||||
addTestimonialsTemplateSection: vi.fn(),
|
||||
addBlogTemplateSection: vi.fn(),
|
||||
addTeamTemplateSection: vi.fn(),
|
||||
addFooterTemplateSection: vi.fn(),
|
||||
updateBlock: vi.fn(),
|
||||
updateProjectConfig: vi.fn((partial: Partial<ProjectConfig>) => {
|
||||
mockState.projectConfig = {
|
||||
...(mockState.projectConfig as ProjectConfig),
|
||||
...partial,
|
||||
} as ProjectConfig;
|
||||
}),
|
||||
resetHistory: vi.fn(),
|
||||
};
|
||||
|
||||
window.localStorage.clear();
|
||||
searchParamsSlug = null;
|
||||
|
||||
vi.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
vi.useRealTimers();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
vi.mock("@/features/editor/state/editorStore", () => {
|
||||
const useEditorStore = (selector: (state: any) => any) => selector(mockState);
|
||||
(useEditorStore as any).getState = () => mockState;
|
||||
|
||||
return {
|
||||
__esModule: true,
|
||||
useEditorStore,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("next/link", () => {
|
||||
return {
|
||||
__esModule: true,
|
||||
default: ({ href, children }: any) => <a href={href}>{children}</a>,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("next/navigation", () => {
|
||||
return {
|
||||
__esModule: true,
|
||||
useRouter: () => ({
|
||||
push: vi.fn(),
|
||||
}),
|
||||
useSearchParams: () => ({
|
||||
get: (key: string) => (key === "slug" ? searchParamsSlug : null),
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe("EditorPage - 서버 자동 저장", () => {
|
||||
it("로그인된 사용자가 새 페이지를 편집하면 자동 생성된 slug 로 /api/projects 에 주기적으로 저장해야 한다", async () => {
|
||||
const fetchMock = vi.fn().mockImplementation((input: any, init?: any) => {
|
||||
const url = typeof input === "string" ? input : input.url;
|
||||
const method = init?.method ?? "GET";
|
||||
|
||||
if (url === "/api/auth/me" && method === "GET") {
|
||||
return Promise.resolve(
|
||||
new Response(
|
||||
JSON.stringify({ id: "user-1", email: "user@example.com", tokenVersion: 1 }),
|
||||
{
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (url === "/api/projects" && method === "POST") {
|
||||
return Promise.resolve(
|
||||
new Response(
|
||||
JSON.stringify({ slug: JSON.parse((init?.body as string) ?? "{}").slug }),
|
||||
{
|
||||
status: 201,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.resolve(new Response(null, { status: 200 }));
|
||||
});
|
||||
|
||||
vi.stubGlobal("fetch", fetchMock as any);
|
||||
|
||||
render(<EditorPage />);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
fetchMock.mock.calls.some(
|
||||
([url, options]: any[]) => url === "/api/auth/me" && (options?.method ?? "GET") === "GET",
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
await vi.advanceTimersByTimeAsync(20000);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
fetchMock.mock.calls.some(
|
||||
([url, options]: any[]) => url === "/api/projects" && (options?.method ?? "GET") === "POST",
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
const projectCall = fetchMock.mock.calls.find(
|
||||
([url, options]: any[]) => url === "/api/projects" && (options?.method ?? "GET") === "POST",
|
||||
) as any;
|
||||
|
||||
const [, options] = projectCall;
|
||||
const body = JSON.parse((options.body as string) ?? "{}");
|
||||
|
||||
expect(typeof body.slug).toBe("string");
|
||||
expect(body.slug).not.toBe("my-landing");
|
||||
expect(mockState.projectConfig.slug).toBe(body.slug);
|
||||
});
|
||||
|
||||
it("authUserId 가 없으면 /api/projects 자동 저장을 호출하지 않아야 한다", async () => {
|
||||
const fetchMock = vi.fn().mockImplementation((input: any, init?: any) => {
|
||||
const url = typeof input === "string" ? input : input.url;
|
||||
const method = init?.method ?? "GET";
|
||||
|
||||
if (url === "/api/auth/me" && method === "GET") {
|
||||
return Promise.resolve(new Response(null, { status: 200 }));
|
||||
}
|
||||
|
||||
return Promise.resolve(new Response(null, { status: 200 }));
|
||||
});
|
||||
|
||||
vi.stubGlobal("fetch", fetchMock as any);
|
||||
|
||||
render(<EditorPage />);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
fetchMock.mock.calls.some(
|
||||
([url]: any[]) => url === "/api/auth/me",
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
await vi.advanceTimersByTimeAsync(20000);
|
||||
|
||||
const projectCalls = fetchMock.mock.calls.filter(
|
||||
([url, options]: any[]) => url === "/api/projects" && (options?.method ?? "GET") === "POST",
|
||||
);
|
||||
|
||||
expect(projectCalls.length).toBe(0);
|
||||
});
|
||||
|
||||
it("slug 쿼리 파라미터로 기존 프로젝트를 열었을 때는 해당 slug 로 서버 자동 저장을 해야 한다", async () => {
|
||||
searchParamsSlug = "existing-slug";
|
||||
mockState.projectConfig.slug = "my-landing" as any;
|
||||
|
||||
const fetchMock = vi.fn().mockImplementation((input: any, init?: any) => {
|
||||
const url = typeof input === "string" ? input : input.url;
|
||||
const method = init?.method ?? "GET";
|
||||
|
||||
if (url === "/api/auth/me" && method === "GET") {
|
||||
return Promise.resolve(
|
||||
new Response(
|
||||
JSON.stringify({ id: "user-1", email: "user@example.com", tokenVersion: 1 }),
|
||||
{
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (url === "/api/projects/existing-slug" && method === "GET") {
|
||||
return Promise.resolve(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
slug: "existing-slug",
|
||||
title: "기존 프로젝트",
|
||||
contentJson: mockState.blocks,
|
||||
}),
|
||||
{
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (url === "/api/projects" && method === "POST") {
|
||||
return Promise.resolve(
|
||||
new Response(
|
||||
JSON.stringify({ slug: JSON.parse((init?.body as string) ?? "{}").slug }),
|
||||
{
|
||||
status: 201,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.resolve(new Response(null, { status: 200 }));
|
||||
});
|
||||
|
||||
vi.stubGlobal("fetch", fetchMock as any);
|
||||
|
||||
render(<EditorPage />);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
fetchMock.mock.calls.some(
|
||||
([url, options]: any[]) =>
|
||||
url === "/api/projects/existing-slug" && (options?.method ?? "GET") === "GET",
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
await vi.advanceTimersByTimeAsync(20000);
|
||||
|
||||
const projectCall = fetchMock.mock.calls.find(
|
||||
([url, options]: any[]) => url === "/api/projects" && (options?.method ?? "GET") === "POST",
|
||||
) as any;
|
||||
|
||||
expect(projectCall).toBeTruthy();
|
||||
|
||||
const [, options] = projectCall;
|
||||
const body = JSON.parse((options.body as string) ?? "{}");
|
||||
|
||||
expect(body.slug).toBe("existing-slug");
|
||||
expect(mockState.projectConfig.slug).toBe("existing-slug");
|
||||
});
|
||||
});
|
||||
@@ -151,4 +151,75 @@ describe("FormControllerPanel", () => {
|
||||
// 기본 선택 값은 FormBlock.submitButtonId 이어야 한다.
|
||||
expect(select.value).toBe("btn-1");
|
||||
});
|
||||
|
||||
it("submitTarget 이 webhook 인 경우 Google Sheets 연동 가이드 텍스트를 보여줘야 한다", () => {
|
||||
const formBlock = makeFormBlock("form-webhook", {
|
||||
submitTarget: "webhook",
|
||||
} as any);
|
||||
|
||||
const updateBlock = vi.fn();
|
||||
|
||||
render(
|
||||
<FormControllerPanel
|
||||
block={formBlock}
|
||||
blocks={[formBlock]}
|
||||
selectedBlockId="form-webhook"
|
||||
updateBlock={updateBlock}
|
||||
/>,
|
||||
);
|
||||
|
||||
const guideButton = screen.getByRole("button", { name: "Google Sheets 연동 가이드" });
|
||||
guideButton.click();
|
||||
|
||||
// Google Sheets 연동 가이드 헤딩과 Apps Script 안내 문구가 노출되어야 한다.
|
||||
expect(screen.getByText("Google Sheets 연동 가이드")).toBeTruthy();
|
||||
expect(
|
||||
screen.getByText(/Apps Script 웹 앱 URL/i),
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
it("Google Sheets 가이드 모달의 Apps Script 코드가 컨트롤러에 매핑된 전송 키와 작성일시를 포함해야 한다", () => {
|
||||
const formBlock = makeFormBlock("form-webhook", {
|
||||
submitTarget: "webhook",
|
||||
fieldIds: ["input-name", "input-email"],
|
||||
} as any);
|
||||
|
||||
const inputNameBlock: Block = {
|
||||
id: "input-name",
|
||||
type: "formInput",
|
||||
props: {
|
||||
label: "이름",
|
||||
formFieldName: "name",
|
||||
} as any,
|
||||
} as any;
|
||||
|
||||
const inputEmailBlock: Block = {
|
||||
id: "input-email",
|
||||
type: "formInput",
|
||||
props: {
|
||||
label: "이메일",
|
||||
formFieldName: "email",
|
||||
} as any,
|
||||
} as any;
|
||||
|
||||
const updateBlock = vi.fn();
|
||||
|
||||
render(
|
||||
<FormControllerPanel
|
||||
block={formBlock}
|
||||
blocks={[formBlock, inputNameBlock, inputEmailBlock]}
|
||||
selectedBlockId="form-webhook"
|
||||
updateBlock={updateBlock}
|
||||
/>,
|
||||
);
|
||||
|
||||
const guideButton = screen.getByRole("button", { name: "Google Sheets 연동 가이드" });
|
||||
guideButton.click();
|
||||
|
||||
const scriptTextarea = screen.getByDisplayValue(/function doPost/) as HTMLTextAreaElement;
|
||||
|
||||
expect(scriptTextarea.value).toContain("params.name || \"\"");
|
||||
expect(scriptTextarea.value).toContain("params.email || \"\"");
|
||||
expect(scriptTextarea.value).toContain("new Date()");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user