Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 41e4238290 | |||
| e179035fbc | |||
| e1c91b1668 | |||
| 860eff514a | |||
| e16f8298ab |
@@ -0,0 +1,38 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import type { Block, ProjectConfig } from "@/features/editor/state/editorStore";
|
||||||
|
import { buildStaticHtml } from "@/app/api/export/route";
|
||||||
|
|
||||||
|
// /api/export/preview 라우트는 Export 결과 HTML 을 ZIP 없이 바로 반환하는
|
||||||
|
// 경량 프리뷰용 엔드포인트이다. 에디터에서 Export 미리보기 UX 를 제공하기 위해 사용한다.
|
||||||
|
|
||||||
|
type PreviewRequestBody = {
|
||||||
|
blocks: Block[];
|
||||||
|
projectConfig?: ProjectConfig;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
let body: PreviewRequestBody;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// JSON 본문을 파싱해서 blocks + projectConfig 를 추출한다.
|
||||||
|
body = (await request.json()) as PreviewRequestBody;
|
||||||
|
} catch {
|
||||||
|
// 잘못된 JSON 요청에 대해서는 400 에러를 반환한다.
|
||||||
|
return NextResponse.json({ message: "잘못된 JSON 요청입니다." }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const blocks = Array.isArray(body.blocks) ? body.blocks : [];
|
||||||
|
const projectConfig = body.projectConfig;
|
||||||
|
|
||||||
|
// Export 본문 HTML 은 기존 buildStaticHtml 을 재사용해서 생성한다.
|
||||||
|
// 이렇게 하면 /api/export ZIP 라우트와 동일한 정적 HTML 을 얻을 수 있다.
|
||||||
|
const html = buildStaticHtml(blocks, projectConfig);
|
||||||
|
|
||||||
|
// Export 미리보기는 ZIP 이 아니라 순수 HTML 문자열을 반환한다.
|
||||||
|
return new NextResponse(html, {
|
||||||
|
status: 200,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "text/html; charset=utf-8",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -52,7 +52,9 @@ const escapeHtml = (value: string): string =>
|
|||||||
const escapeAttr = (value: string): string => escapeHtml(value);
|
const escapeAttr = (value: string): string => escapeHtml(value);
|
||||||
|
|
||||||
export const buildStaticHtml = (blocks: Block[], projectConfig?: ProjectConfig): string => {
|
export const buildStaticHtml = (blocks: Block[], projectConfig?: ProjectConfig): string => {
|
||||||
const pageTitleRaw = (projectConfig?.title ?? "").trim() || "Page Builder Export";
|
const baseTitleRaw = (projectConfig?.title ?? "").trim() || "Page Builder Export";
|
||||||
|
const seoTitleRaw = (projectConfig?.seoTitle ?? "").trim();
|
||||||
|
const pageTitleRaw = seoTitleRaw || baseTitleRaw;
|
||||||
const pageTitle = escapeHtml(pageTitleRaw);
|
const pageTitle = escapeHtml(pageTitleRaw);
|
||||||
|
|
||||||
const headExtraRaw = (projectConfig?.headHtml ?? "").trim();
|
const headExtraRaw = (projectConfig?.headHtml ?? "").trim();
|
||||||
@@ -84,6 +86,77 @@ export const buildStaticHtml = (blocks: Block[], projectConfig?: ProjectConfig):
|
|||||||
const trackingRaw = (projectConfig?.trackingScript ?? "").trim();
|
const trackingRaw = (projectConfig?.trackingScript ?? "").trim();
|
||||||
const trackingHtml = trackingRaw ? `\n${trackingRaw}\n` : "";
|
const trackingHtml = trackingRaw ? `\n${trackingRaw}\n` : "";
|
||||||
|
|
||||||
|
const seoDescriptionRaw = (projectConfig?.seoDescription ?? "").trim();
|
||||||
|
const seoOgImageRaw = (projectConfig?.seoOgImageUrl ?? "").trim();
|
||||||
|
const seoCanonicalRaw = (projectConfig?.seoCanonicalUrl ?? "").trim();
|
||||||
|
const seoNoIndex = projectConfig?.seoNoIndex === true;
|
||||||
|
|
||||||
|
const seoHeadParts: string[] = [];
|
||||||
|
|
||||||
|
if (seoDescriptionRaw) {
|
||||||
|
seoHeadParts.push(
|
||||||
|
` <meta name="description" content="${escapeAttr(seoDescriptionRaw)}" />`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pageTitleRaw) {
|
||||||
|
seoHeadParts.push(
|
||||||
|
` <meta property="og:title" content="${escapeAttr(pageTitleRaw)}" />`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (seoDescriptionRaw) {
|
||||||
|
seoHeadParts.push(
|
||||||
|
` <meta property="og:description" content="${escapeAttr(seoDescriptionRaw)}" />`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
seoHeadParts.push(` <meta property="og:type" content="website" />`);
|
||||||
|
|
||||||
|
if (seoOgImageRaw) {
|
||||||
|
seoHeadParts.push(
|
||||||
|
` <meta property="og:image" content="${escapeAttr(seoOgImageRaw)}" />`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (seoCanonicalRaw) {
|
||||||
|
seoHeadParts.push(
|
||||||
|
` <meta property="og:url" content="${escapeAttr(seoCanonicalRaw)}" />`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Twitter 카드 메타 태그
|
||||||
|
seoHeadParts.push(
|
||||||
|
` <meta name="twitter:card" content="summary_large_image" />`,
|
||||||
|
);
|
||||||
|
if (pageTitleRaw) {
|
||||||
|
seoHeadParts.push(
|
||||||
|
` <meta name="twitter:title" content="${escapeAttr(pageTitleRaw)}" />`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (seoDescriptionRaw) {
|
||||||
|
seoHeadParts.push(
|
||||||
|
` <meta name="twitter:description" content="${escapeAttr(seoDescriptionRaw)}" />`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (seoOgImageRaw) {
|
||||||
|
seoHeadParts.push(
|
||||||
|
` <meta name="twitter:image" content="${escapeAttr(seoOgImageRaw)}" />`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (seoCanonicalRaw) {
|
||||||
|
seoHeadParts.push(
|
||||||
|
` <link rel="canonical" href="${escapeAttr(seoCanonicalRaw)}" />`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (seoNoIndex) {
|
||||||
|
seoHeadParts.push(
|
||||||
|
` <meta name="robots" content="noindex, nofollow" />`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const seoHeadHtml = seoHeadParts.length > 0 ? `\n${seoHeadParts.join("\n")}` : "";
|
||||||
|
|
||||||
const sectionBlocks = blocks.filter((b) => b.type === "section");
|
const sectionBlocks = blocks.filter((b) => b.type === "section");
|
||||||
const rootBlocks = blocks.filter((b) => !b.sectionId && b.type !== "section");
|
const rootBlocks = blocks.filter((b) => !b.sectionId && b.type !== "section");
|
||||||
|
|
||||||
@@ -515,7 +588,7 @@ export const buildStaticHtml = (blocks: Block[], projectConfig?: ProjectConfig):
|
|||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<title>${pageTitle}</title>
|
<title>${pageTitle}</title>
|
||||||
<link rel="stylesheet" href="./builder.css" />${headExtra}
|
<link rel="stylesheet" href="./builder.css" />${seoHeadHtml}${headExtra}
|
||||||
</head>
|
</head>
|
||||||
<body style="${bodyStyle}">
|
<body style="${bodyStyle}">
|
||||||
<main>
|
<main>
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import type { Block, ButtonBlockProps, FormBlockProps } from "@/features/editor/state/editorStore";
|
import type { Block, ButtonBlockProps, FormBlockProps } from "@/features/editor/state/editorStore";
|
||||||
import { NumericPropertyControl } from "@/features/editor/components/NumericPropertyControl";
|
|
||||||
import { ColorPickerField, TEXT_COLOR_PALETTE } from "@/features/editor/components/ColorPickerField";
|
|
||||||
|
|
||||||
interface FormControllerPanelProps {
|
interface FormControllerPanelProps {
|
||||||
block: Block; // type === "form"
|
block: Block; // type === "form"
|
||||||
@@ -131,89 +129,6 @@ export function FormControllerPanel({ block, blocks, selectedBlockId, updateBloc
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2 border-t border-slate-800 pt-3">
|
|
||||||
<h3 className="text-[11px] font-semibold text-slate-200">폼 레이아웃</h3>
|
|
||||||
<label className="flex flex-col gap-1 text-xs text-slate-400">
|
|
||||||
<span>폼 너비 모드</span>
|
|
||||||
<select
|
|
||||||
className="w-full rounded border border-slate-700 bg-slate-950 px-2 py-1 text-[11px] outline-none focus:border-sky-500"
|
|
||||||
value={formProps.formWidthMode ?? "auto"}
|
|
||||||
onChange={(e) =>
|
|
||||||
updateBlock(selectedBlockId, {
|
|
||||||
formWidthMode: e.target.value,
|
|
||||||
} as any)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<option value="auto">내용에 맞춤</option>
|
|
||||||
<option value="full">전체 폭</option>
|
|
||||||
<option value="fixed">고정 폭 (px)</option>
|
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
{(formProps.formWidthMode ?? "auto") === "fixed" && (
|
|
||||||
<NumericPropertyControl
|
|
||||||
label="폼 고정 너비 (px)"
|
|
||||||
unitLabel="(px)"
|
|
||||||
value={typeof formProps.formWidthPx === "number" ? formProps.formWidthPx : 360}
|
|
||||||
min={160}
|
|
||||||
max={960}
|
|
||||||
step={10}
|
|
||||||
presets={[
|
|
||||||
{ id: "sm", label: "좁게", value: 280 },
|
|
||||||
{ id: "md", label: "보통", value: 360 },
|
|
||||||
{ id: "lg", label: "넓게", value: 480 },
|
|
||||||
]}
|
|
||||||
onChangeValue={(v) =>
|
|
||||||
updateBlock(selectedBlockId, {
|
|
||||||
formWidthPx: v,
|
|
||||||
} as any)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<NumericPropertyControl
|
|
||||||
label="폼 위/아래 여백 (px)"
|
|
||||||
unitLabel="(px)"
|
|
||||||
value={typeof formProps.marginYPx === "number" ? formProps.marginYPx : 16}
|
|
||||||
min={0}
|
|
||||||
max={80}
|
|
||||||
step={2}
|
|
||||||
presets={[
|
|
||||||
{ id: "tight", label: "좁게", value: 8 },
|
|
||||||
{ id: "normal", label: "보통", value: 16 },
|
|
||||||
{ id: "relaxed", label: "넓게", value: 32 },
|
|
||||||
]}
|
|
||||||
onChangeValue={(v) =>
|
|
||||||
updateBlock(selectedBlockId, {
|
|
||||||
marginYPx: v,
|
|
||||||
} as any)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-2 border-t border-slate-800 pt-3 mt-4">
|
|
||||||
<h3 className="text-[11px] font-semibold text-slate-200">폼 스타일</h3>
|
|
||||||
<ColorPickerField
|
|
||||||
label="폼 배경색"
|
|
||||||
ariaLabelColorInput="폼 배경색 피커"
|
|
||||||
ariaLabelHexInput="폼 배경색 HEX"
|
|
||||||
value={
|
|
||||||
formProps.backgroundColorCustom && formProps.backgroundColorCustom.trim() !== ""
|
|
||||||
? formProps.backgroundColorCustom
|
|
||||||
: TEXT_COLOR_PALETTE[0]?.color ?? "#e5e7eb"
|
|
||||||
}
|
|
||||||
onChange={(hex) => {
|
|
||||||
updateBlock(selectedBlockId, {
|
|
||||||
backgroundColorCustom: hex,
|
|
||||||
} as any);
|
|
||||||
}}
|
|
||||||
palette={TEXT_COLOR_PALETTE}
|
|
||||||
onPaletteSelect={(item) => {
|
|
||||||
updateBlock(selectedBlockId, {
|
|
||||||
backgroundColorCustom: item.color,
|
|
||||||
} as any);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-2 border-t border-slate-800 pt-3 mt-4">
|
<div className="space-y-2 border-t border-slate-800 pt-3 mt-4">
|
||||||
<h3 className="text-[11px] font-semibold text-slate-200">폼 메시지</h3>
|
<h3 className="text-[11px] font-semibold text-slate-200">폼 메시지</h3>
|
||||||
<label className="flex flex-col gap-1 text-xs text-slate-400">
|
<label className="flex flex-col gap-1 text-xs text-slate-400">
|
||||||
|
|||||||
+93
-1
@@ -135,7 +135,9 @@ export default function EditorPage() {
|
|||||||
const [selectedBlockIds, setSelectedBlockIds] = useState<string[]>([]);
|
const [selectedBlockIds, setSelectedBlockIds] = useState<string[]>([]);
|
||||||
|
|
||||||
const [menuOpen, setMenuOpen] = useState(false);
|
const [menuOpen, setMenuOpen] = useState(false);
|
||||||
const [activeModal, setActiveModal] = useState<"project" | "json" | null>(null);
|
const [activeModal, setActiveModal] = useState<"project" | "json" | "exportPreview" | null>(null);
|
||||||
|
const [exportPreviewHtml, setExportPreviewHtml] = useState("");
|
||||||
|
const [exportPreviewStatus, setExportPreviewStatus] = useState<"idle" | "loading" | "error">("idle");
|
||||||
|
|
||||||
const sensors = useSensors(useSensor(PointerSensor));
|
const sensors = useSensors(useSensor(PointerSensor));
|
||||||
|
|
||||||
@@ -188,6 +190,37 @@ export default function EditorPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleRefreshExportPreview = async () => {
|
||||||
|
try {
|
||||||
|
setExportPreviewStatus("loading");
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
blocks,
|
||||||
|
projectConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await fetch("/api/export/preview", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
setExportPreviewStatus("error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const html = await response.text();
|
||||||
|
setExportPreviewHtml(html);
|
||||||
|
setExportPreviewStatus("idle");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Export 미리보기 요청 중 오류", error);
|
||||||
|
setExportPreviewStatus("error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const commitEditing = () => {
|
const commitEditing = () => {
|
||||||
if (!editingBlockId) return;
|
if (!editingBlockId) return;
|
||||||
updateBlock(editingBlockId, { text: editingText });
|
updateBlock(editingBlockId, { text: editingText });
|
||||||
@@ -685,6 +718,16 @@ export default function EditorPage() {
|
|||||||
>
|
>
|
||||||
JSON 내보내기/불러오기
|
JSON 내보내기/불러오기
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="w-full px-3 py-2 text-left hover:bg-slate-800 text-slate-100 border-t border-slate-800"
|
||||||
|
onClick={() => {
|
||||||
|
setMenuOpen(false);
|
||||||
|
setActiveModal("exportPreview");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Export 미리보기
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="w-full px-3 py-2 text-left hover:bg-slate-800 text-slate-100 border-t border-slate-800"
|
className="w-full px-3 py-2 text-left hover:bg-slate-800 text-slate-100 border-t border-slate-800"
|
||||||
@@ -807,6 +850,55 @@ export default function EditorPage() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{activeModal === "exportPreview" && (
|
||||||
|
<div className="fixed inset-0 z-30 flex items-center justify-center bg-black/60">
|
||||||
|
<div className="w-full max-w-4xl rounded-lg border border-slate-700 bg-slate-900 p-4 text-xs text-slate-100 shadow-xl">
|
||||||
|
<div className="flex items-center justify-between mb-3">
|
||||||
|
<h3 className="text-sm font-medium">Export 미리보기</h3>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="text-slate-400 hover:text-slate-100 text-sm"
|
||||||
|
onClick={() => setActiveModal(null)}
|
||||||
|
>
|
||||||
|
✕
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-3">
|
||||||
|
<div className="flex items-center justify-between gap-2">
|
||||||
|
<p className="text-[11px] text-slate-400">
|
||||||
|
현재 캔버스 상태를 기반으로 생성된 정적 Export HTML 을 미리 확인할 수 있습니다.
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="rounded border border-sky-700 bg-sky-950 px-3 py-1 text-[11px] text-sky-100 hover:bg-sky-900 disabled:opacity-60 disabled:cursor-not-allowed"
|
||||||
|
onClick={handleRefreshExportPreview}
|
||||||
|
disabled={exportPreviewStatus === "loading"}
|
||||||
|
>
|
||||||
|
{exportPreviewStatus === "loading" ? "로딩 중..." : "미리보기 새로고침"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{exportPreviewStatus === "error" && (
|
||||||
|
<p className="text-[11px] text-red-300">
|
||||||
|
Export 미리보기 HTML 을 불러오는 중 오류가 발생했습니다. 잠시 후 다시 시도해 주세요.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
{exportPreviewHtml ? (
|
||||||
|
<iframe
|
||||||
|
title="Export preview"
|
||||||
|
data-testid="export-preview-frame"
|
||||||
|
className="w-full h-[480px] rounded border border-slate-700 bg-slate-950"
|
||||||
|
srcDoc={exportPreviewHtml}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="w-full h-[200px] rounded border border-dashed border-slate-700 bg-slate-950 flex items-center justify-center text-[11px] text-slate-500">
|
||||||
|
아직 Export 미리보기 HTML 이 없습니다. "미리보기 새로고침" 버튼을 눌러 생성해 보세요.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{activeModal === "json" && (
|
{activeModal === "json" && (
|
||||||
<div className="fixed inset-0 z-30 flex items-center justify-center bg-black/60">
|
<div className="fixed inset-0 z-30 flex items-center justify-center bg-black/60">
|
||||||
<div className="w-full max-w-2xl rounded-lg border border-slate-700 bg-slate-900 p-4 text-xs text-slate-100 shadow-xl">
|
<div className="w-full max-w-2xl rounded-lg border border-slate-700 bg-slate-900 p-4 text-xs text-slate-100 shadow-xl">
|
||||||
|
|||||||
@@ -104,6 +104,65 @@ export function ProjectPropertiesPanel() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2 border-t border-slate-800 pt-3">
|
||||||
|
<h4 className="text-[11px] font-semibold text-slate-200">SEO / 메타</h4>
|
||||||
|
|
||||||
|
<label className="flex flex-col gap-1">
|
||||||
|
<span className="text-slate-400">SEO 타이틀</span>
|
||||||
|
<input
|
||||||
|
className="w-full rounded border border-slate-700 bg-slate-900 px-2 py-1 text-xs outline-none focus:border-sky-500"
|
||||||
|
aria-label="SEO 타이틀"
|
||||||
|
placeholder={projectConfig.title || "페이지 제목"}
|
||||||
|
value={projectConfig.seoTitle ?? ""}
|
||||||
|
onChange={(e) => updateProjectConfig({ seoTitle: e.target.value })}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label className="flex flex-col gap-1">
|
||||||
|
<span className="text-slate-400">메타 디스크립션</span>
|
||||||
|
<textarea
|
||||||
|
className="w-full rounded border border-slate-700 bg-slate-900 px-2 py-1 text-[11px] outline-none focus:border-sky-500 min-h-[56px]"
|
||||||
|
aria-label="메타 디스크립션"
|
||||||
|
placeholder="검색엔진 및 SNS 공유에 노출될 페이지 설명을 입력하세요."
|
||||||
|
value={projectConfig.seoDescription ?? ""}
|
||||||
|
onChange={(e) => updateProjectConfig({ seoDescription: e.target.value })}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label className="flex flex-col gap-1">
|
||||||
|
<span className="text-slate-400">OG/Twitter 이미지 URL</span>
|
||||||
|
<input
|
||||||
|
className="w-full rounded border border-slate-700 bg-slate-900 px-2 py-1 text-xs outline-none focus:border-sky-500"
|
||||||
|
aria-label="OG/Twitter 이미지 URL"
|
||||||
|
placeholder="예: https://example.com/og-image.png"
|
||||||
|
value={projectConfig.seoOgImageUrl ?? ""}
|
||||||
|
onChange={(e) => updateProjectConfig({ seoOgImageUrl: e.target.value })}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label className="flex flex-col gap-1">
|
||||||
|
<span className="text-slate-400">Canonical URL</span>
|
||||||
|
<input
|
||||||
|
className="w-full rounded border border-slate-700 bg-slate-900 px-2 py-1 text-xs outline-none focus:border-sky-500"
|
||||||
|
aria-label="Canonical URL"
|
||||||
|
placeholder="예: https://example.com/landing"
|
||||||
|
value={projectConfig.seoCanonicalUrl ?? ""}
|
||||||
|
onChange={(e) => updateProjectConfig({ seoCanonicalUrl: e.target.value })}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label className="flex items-center gap-2 text-[11px] text-slate-300">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
className="h-3 w-3 rounded border-slate-600 bg-slate-900"
|
||||||
|
aria-label="검색 엔진에 노출하지 않기 (noindex)"
|
||||||
|
checked={Boolean(projectConfig.seoNoIndex)}
|
||||||
|
onChange={(e) => updateProjectConfig({ seoNoIndex: e.target.checked })}
|
||||||
|
/>
|
||||||
|
<span>검색 엔진에 노출하지 않기 (noindex)</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<label className="flex flex-col gap-1">
|
<label className="flex flex-col gap-1">
|
||||||
<span className="text-slate-400">페이지 head HTML</span>
|
<span className="text-slate-400">페이지 head HTML</span>
|
||||||
|
|||||||
@@ -684,6 +684,12 @@ export interface ProjectConfig {
|
|||||||
bodyBgColorHex?: string;
|
bodyBgColorHex?: string;
|
||||||
headHtml?: string;
|
headHtml?: string;
|
||||||
trackingScript?: string;
|
trackingScript?: string;
|
||||||
|
// SEO / 메타 설정 (15.1)
|
||||||
|
seoTitle?: string;
|
||||||
|
seoDescription?: string;
|
||||||
|
seoOgImageUrl?: string;
|
||||||
|
seoCanonicalUrl?: string;
|
||||||
|
seoNoIndex?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 공통 블록 모델
|
// 공통 블록 모델
|
||||||
@@ -803,6 +809,12 @@ const createEditorState = (set: any, get: any): EditorState => ({
|
|||||||
bodyBgColorHex: "#020617",
|
bodyBgColorHex: "#020617",
|
||||||
headHtml: "",
|
headHtml: "",
|
||||||
trackingScript: "",
|
trackingScript: "",
|
||||||
|
// SEO 기본값: 필요할 때만 값을 채우고, 없으면 title 등을 사용한다.
|
||||||
|
seoTitle: "",
|
||||||
|
seoDescription: "",
|
||||||
|
seoOgImageUrl: "",
|
||||||
|
seoCanonicalUrl: "",
|
||||||
|
seoNoIndex: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
updateProjectConfig: (partial: Partial<ProjectConfig>) => {
|
updateProjectConfig: (partial: Partial<ProjectConfig>) => {
|
||||||
|
|||||||
@@ -861,26 +861,10 @@ export const computeFormControllerPublicTokens = (
|
|||||||
);
|
);
|
||||||
const mappedSubmitLabel = (mappedSubmitButton?.props as ButtonBlockProps | undefined)?.label ?? null;
|
const mappedSubmitLabel = (mappedSubmitButton?.props as ButtonBlockProps | undefined)?.label ?? null;
|
||||||
|
|
||||||
const widthMode = props.formWidthMode ?? "auto";
|
// FormBlock 은 레이아웃/스타일을 가지지 않는 순수 컨트롤러이므로
|
||||||
const formStyle: CSSProperties = {};
|
// formClassName 은 고정 기본값만 사용하고, formStyle 은 항상 빈 객체로 유지한다.
|
||||||
const formClassNames = ["space-y-3"];
|
const formClassNames = ["space-y-3"];
|
||||||
|
const formStyle: CSSProperties = {};
|
||||||
if (widthMode === "full") {
|
|
||||||
formClassNames.push("w-full");
|
|
||||||
}
|
|
||||||
if (widthMode === "fixed" && typeof props.formWidthPx === "number" && props.formWidthPx > 0) {
|
|
||||||
formStyle.width = pxToEm(props.formWidthPx);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof props.marginYPx === "number") {
|
|
||||||
const marginEm = pxToEm(props.marginYPx);
|
|
||||||
formStyle.marginTop = marginEm;
|
|
||||||
formStyle.marginBottom = marginEm;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (props.backgroundColorCustom && props.backgroundColorCustom.trim() !== "") {
|
|
||||||
formStyle.backgroundColor = props.backgroundColorCustom.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fields,
|
fields,
|
||||||
@@ -920,10 +904,8 @@ export const computeFormBlockExportTokens = (
|
|||||||
fallbackFields = props.fields;
|
fallbackFields = props.fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FormBlock 은 Export 레이어에서도 컨테이너 배경/레이아웃 스타일을 가지지 않는다.
|
||||||
const formStyleParts: string[] = [];
|
const formStyleParts: string[] = [];
|
||||||
if (typeof props.backgroundColorCustom === "string" && props.backgroundColorCustom.trim() !== "") {
|
|
||||||
formStyleParts.push(`background-color:${props.backgroundColorCustom.trim()}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
hasControllerFields: controllerFields.length > 0,
|
hasControllerFields: controllerFields.length > 0,
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
import "dotenv/config";
|
||||||
|
import { describe, it, expect } from "vitest";
|
||||||
|
import type { Block, ProjectConfig } from "@/features/editor/state/editorStore";
|
||||||
|
import { buildStaticHtml } from "@/app/api/export/route";
|
||||||
|
|
||||||
|
const BASE_URL = "http://localhost";
|
||||||
|
|
||||||
|
// /api/export/preview TDD:
|
||||||
|
// - blocks + projectConfig 를 받아 HTML 문자열을 바로 반환하는 경량 엔드포인트.
|
||||||
|
// - 기존 buildStaticHtml 과 동일한 HTML 을 반환해야 한다.
|
||||||
|
|
||||||
|
describe("/api/export/preview", () => {
|
||||||
|
it("POST /api/export/preview 는 blocks + projectConfig 로부터 HTML 문자열을 반환해야 한다", async () => {
|
||||||
|
const blocks: Block[] = [
|
||||||
|
{
|
||||||
|
id: "blk_preview_text",
|
||||||
|
type: "text",
|
||||||
|
props: {
|
||||||
|
text: "Export 미리보기 테스트",
|
||||||
|
align: "center",
|
||||||
|
size: "lg",
|
||||||
|
},
|
||||||
|
} as any,
|
||||||
|
];
|
||||||
|
|
||||||
|
const projectConfig: ProjectConfig = {
|
||||||
|
title: "Export 미리보기 페이지",
|
||||||
|
slug: "export-preview",
|
||||||
|
canvasPreset: "full",
|
||||||
|
};
|
||||||
|
|
||||||
|
const payload = { blocks, projectConfig };
|
||||||
|
|
||||||
|
const { POST: handlePreview } = await import("@/app/api/export/preview/route");
|
||||||
|
|
||||||
|
const res = await handlePreview(
|
||||||
|
new Request(`${BASE_URL}/api/export/preview`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(res.status).toBe(200);
|
||||||
|
expect(res.headers.get("Content-Type")).toBe("text/html; charset=utf-8");
|
||||||
|
|
||||||
|
const html = await res.text();
|
||||||
|
|
||||||
|
expect(html).toContain("<title>Export 미리보기 페이지</title>");
|
||||||
|
expect(html).toContain("Export 미리보기 테스트");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("/api/export/preview 의 HTML 은 동일 입력에 대해 buildStaticHtml 결과와 동일해야 한다", async () => {
|
||||||
|
const blocks: Block[] = [
|
||||||
|
{
|
||||||
|
id: "blk_preview_compare",
|
||||||
|
type: "text",
|
||||||
|
props: {
|
||||||
|
text: "Preview vs Export 동일성 테스트",
|
||||||
|
align: "left",
|
||||||
|
size: "base",
|
||||||
|
},
|
||||||
|
} as any,
|
||||||
|
];
|
||||||
|
|
||||||
|
const projectConfig: ProjectConfig = {
|
||||||
|
title: "동일성 테스트 페이지",
|
||||||
|
slug: "preview-equality-test",
|
||||||
|
canvasPreset: "full",
|
||||||
|
};
|
||||||
|
|
||||||
|
const payload = { blocks, projectConfig };
|
||||||
|
|
||||||
|
const { POST: handlePreview } = await import("@/app/api/export/preview/route");
|
||||||
|
|
||||||
|
const res = await handlePreview(
|
||||||
|
new Request(`${BASE_URL}/api/export/preview`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
const previewHtml = await res.text();
|
||||||
|
const staticHtml = buildStaticHtml(blocks, projectConfig);
|
||||||
|
|
||||||
|
expect(previewHtml).toBe(staticHtml);
|
||||||
|
});
|
||||||
|
});
|
||||||
+128
-2
@@ -7,6 +7,7 @@ import type { Block, ProjectConfig } from "@/features/editor/state/editorStore";
|
|||||||
import { createHeroTemplateBlocks } from "@/app/editor/templates/heroTemplate";
|
import { createHeroTemplateBlocks } from "@/app/editor/templates/heroTemplate";
|
||||||
import { createFeaturesTemplateBlocks } from "@/app/editor/templates/featuresTemplate";
|
import { createFeaturesTemplateBlocks } from "@/app/editor/templates/featuresTemplate";
|
||||||
import { createCtaTemplateBlocks } from "@/app/editor/templates/ctaTemplate";
|
import { createCtaTemplateBlocks } from "@/app/editor/templates/ctaTemplate";
|
||||||
|
import { createFooterTemplateBlocks } from "@/app/editor/templates/footerTemplate";
|
||||||
import { buildStaticHtml } from "@/app/api/export/route";
|
import { buildStaticHtml } from "@/app/api/export/route";
|
||||||
|
|
||||||
const BASE_URL = "http://localhost";
|
const BASE_URL = "http://localhost";
|
||||||
@@ -321,6 +322,88 @@ describe("/api/export", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("seoTitle/seoDescription/seoCanonicalUrl/seoOgImageUrl/seoNoIndex 가 설정된 경우 head 에 SEO 메타 태그들이 생성되어야 한다", () => {
|
||||||
|
const blocks: Block[] = [];
|
||||||
|
|
||||||
|
const projectConfig: ProjectConfig = {
|
||||||
|
title: "기본 타이틀",
|
||||||
|
slug: "seo-meta-test",
|
||||||
|
canvasPreset: "full",
|
||||||
|
seoTitle: "SEO 타이틀",
|
||||||
|
seoDescription: "SEO 설명",
|
||||||
|
seoOgImageUrl: "https://example.com/og.png",
|
||||||
|
seoCanonicalUrl: "https://example.com/landing",
|
||||||
|
seoNoIndex: true,
|
||||||
|
} as ProjectConfig;
|
||||||
|
|
||||||
|
const html = buildStaticHtml(blocks, projectConfig);
|
||||||
|
|
||||||
|
expect(html).toContain("<title>SEO 타이틀</title>");
|
||||||
|
expect(html).toContain('meta name="description" content="SEO 설명"');
|
||||||
|
expect(html).toContain('meta property="og:title" content="SEO 타이틀"');
|
||||||
|
expect(html).toContain('meta property="og:description" content="SEO 설명"');
|
||||||
|
expect(html).toContain('meta property="og:type" content="website"');
|
||||||
|
expect(html).toContain('meta property="og:image" content="https://example.com/og.png"');
|
||||||
|
expect(html).toContain('meta property="og:url" content="https://example.com/landing"');
|
||||||
|
|
||||||
|
expect(html).toContain('meta name="twitter:card" content="summary_large_image"');
|
||||||
|
expect(html).toContain('meta name="twitter:title" content="SEO 타이틀"');
|
||||||
|
expect(html).toContain('meta name="twitter:description" content="SEO 설명"');
|
||||||
|
expect(html).toContain('meta name="twitter:image" content="https://example.com/og.png"');
|
||||||
|
|
||||||
|
expect(html).toContain('<link rel="canonical" href="https://example.com/landing" />');
|
||||||
|
expect(html).toContain('<meta name="robots" content="noindex, nofollow" />');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("기본 SEO 메타 태그들 이후에 projectConfig.headHtml 이 head 에 추가되어야 한다", () => {
|
||||||
|
const blocks: Block[] = [];
|
||||||
|
|
||||||
|
const projectConfig: ProjectConfig = {
|
||||||
|
title: "헤드 SEO 순서 테스트",
|
||||||
|
slug: "head-seo-order-test",
|
||||||
|
canvasPreset: "full",
|
||||||
|
seoTitle: "SEO 타이틀",
|
||||||
|
seoDescription: "SEO 설명",
|
||||||
|
headHtml: '<meta name="custom" content="custom-meta" />',
|
||||||
|
} as ProjectConfig;
|
||||||
|
|
||||||
|
const html = buildStaticHtml(blocks, projectConfig);
|
||||||
|
const headStart = html.indexOf("<head>");
|
||||||
|
const headEnd = html.indexOf("</head>");
|
||||||
|
const head = html.slice(headStart, headEnd);
|
||||||
|
|
||||||
|
const descriptionIndex = head.indexOf('meta name="description"');
|
||||||
|
const customIndex = head.indexOf('meta name="custom" content="custom-meta"');
|
||||||
|
|
||||||
|
expect(descriptionIndex).toBeGreaterThan(-1);
|
||||||
|
expect(customIndex).toBeGreaterThan(-1);
|
||||||
|
expect(customIndex).toBeGreaterThan(descriptionIndex);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("SEO 필드 값에 특수 문자가 포함되어도 HTML 이 깨지지 않고 이스케이프되어야 한다", () => {
|
||||||
|
const blocks: Block[] = [];
|
||||||
|
|
||||||
|
const projectConfig: ProjectConfig = {
|
||||||
|
title: '기본 & "타이틀" <테스트>',
|
||||||
|
slug: "seo-escape-test",
|
||||||
|
canvasPreset: "full",
|
||||||
|
seoTitle: 'SEO & "타이틀" <테스트>',
|
||||||
|
seoDescription: '설명 & "디스크립션" <테스트>',
|
||||||
|
} as ProjectConfig;
|
||||||
|
|
||||||
|
const html = buildStaticHtml(blocks, projectConfig);
|
||||||
|
|
||||||
|
expect(html).toContain(
|
||||||
|
"<title>SEO & "타이틀" <테스트></title>",
|
||||||
|
);
|
||||||
|
expect(html).toContain(
|
||||||
|
'meta name="description" content="설명 & "디스크립션" <테스트>"',
|
||||||
|
);
|
||||||
|
expect(html).toContain(
|
||||||
|
'meta property="og:title" content="SEO & "타이틀" <테스트>"',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("폼 블록과 컨트롤러 필드 블록들은 정적 HTML에서도 폼 요소로 렌더되어야 한다", async () => {
|
it("폼 블록과 컨트롤러 필드 블록들은 정적 HTML에서도 폼 요소로 렌더되어야 한다", async () => {
|
||||||
const blocks: Block[] = [
|
const blocks: Block[] = [
|
||||||
{
|
{
|
||||||
@@ -1364,6 +1447,49 @@ describe("/api/export", () => {
|
|||||||
expect(html).toContain("지금 바로 행동을 유도하는 CTA 텍스트를 입력하세요.");
|
expect(html).toContain("지금 바로 행동을 유도하는 CTA 텍스트를 입력하세요.");
|
||||||
expect(html).toContain("CTA 버튼");
|
expect(html).toContain("CTA 버튼");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Footer 템플릿 섹션은 export HTML 의 마지막 섹션으로 렌더되고 푸터 텍스트를 포함해야 한다", async () => {
|
||||||
|
const sectionId = "footer_section_export";
|
||||||
|
const { blocks } = createFooterTemplateBlocks({ sectionId, createId: createIdFactory() });
|
||||||
|
|
||||||
|
const html = await exportTemplateHtml(blocks as Block[]);
|
||||||
|
|
||||||
|
expect(html).toContain("MyLanding");
|
||||||
|
expect(html).toContain("더 나은 웹사이트를 위한 최고의 선택.");
|
||||||
|
expect(html).toContain("서비스 소개");
|
||||||
|
expect(html).toContain("문의하기");
|
||||||
|
expect(html).toContain(" 2025 MyLanding.");
|
||||||
|
|
||||||
|
const lastSectionIndex = html.lastIndexOf("<section");
|
||||||
|
expect(lastSectionIndex).toBeGreaterThan(-1);
|
||||||
|
const lastSectionHtml = html.slice(lastSectionIndex);
|
||||||
|
expect(lastSectionHtml).toContain(" 2025 MyLanding.");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("루트 버튼 내비게이션 링크는 Export HTML 에서 동일한 라벨과 href 로 렌더되어야 한다", async () => {
|
||||||
|
const blocks: Block[] = [
|
||||||
|
{
|
||||||
|
id: "nav_btn_1",
|
||||||
|
type: "button",
|
||||||
|
props: {
|
||||||
|
label: "요금제",
|
||||||
|
href: "/pricing",
|
||||||
|
align: "left",
|
||||||
|
},
|
||||||
|
} as any,
|
||||||
|
];
|
||||||
|
|
||||||
|
const projectConfig: ProjectConfig = {
|
||||||
|
title: "내비게이션 링크 테스트",
|
||||||
|
slug: "nav-link-test",
|
||||||
|
canvasPreset: "full",
|
||||||
|
};
|
||||||
|
|
||||||
|
const html = buildStaticHtml(blocks, projectConfig);
|
||||||
|
|
||||||
|
expect(html).toContain('<a href="/pricing"');
|
||||||
|
expect(html).toContain(">요금제</a>");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("스타일 테스트", () => {
|
describe("스타일 테스트", () => {
|
||||||
@@ -1609,7 +1735,7 @@ describe("/api/export", () => {
|
|||||||
expect(html).toContain("background-color:#00ff88");
|
expect(html).toContain("background-color:#00ff88");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("backgroundColorCustom 이 지정된 폼 블록은 정적 HTML에서 form 요소 배경색을 반영해야 한다", async () => {
|
it("backgroundColorCustom 이 지정된 폼 블록은 정적 HTML에서 form 요소 배경색을 반영하지 않아야 한다", async () => {
|
||||||
const blocks: Block[] = [
|
const blocks: Block[] = [
|
||||||
{
|
{
|
||||||
id: "form_bg_custom",
|
id: "form_bg_custom",
|
||||||
@@ -1662,7 +1788,7 @@ describe("/api/export", () => {
|
|||||||
|
|
||||||
const html = await indexEntry!.async("string");
|
const html = await indexEntry!.async("string");
|
||||||
expect(html).toContain("<form");
|
expect(html).toContain("<form");
|
||||||
expect(html).toContain("background-color:#111111");
|
expect(html).not.toContain("background-color:#111111");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("backgroundColorCustom 이 지정된 섹션 블록은 정적 HTML에서 섹션 요소 배경색을 인라인 스타일로 반영해야 한다", async () => {
|
it("backgroundColorCustom 이 지정된 섹션 블록은 정적 HTML에서 섹션 요소 배경색을 인라인 스타일로 반영해야 한다", async () => {
|
||||||
|
|||||||
@@ -0,0 +1,148 @@
|
|||||||
|
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
||||||
|
import { render, screen, cleanup, fireEvent, waitFor } from "@testing-library/react";
|
||||||
|
import type { Block, ProjectConfig } from "@/features/editor/state/editorStore";
|
||||||
|
import EditorPage from "@/app/editor/page";
|
||||||
|
|
||||||
|
// EditorPage Export 미리보기 UX TDD
|
||||||
|
// - 상단 메뉴에 "Export 미리보기" 항목이 노출되는지 검증한다.
|
||||||
|
// - Export 미리보기 모달에서 "미리보기 새로고침" 클릭 시
|
||||||
|
// - /api/export/preview 엔드포인트를 호출하고,
|
||||||
|
// - 반환된 HTML 을 iframe srcdoc 으로 렌더하는지 확인한다.
|
||||||
|
|
||||||
|
let mockState: any;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
const baseProjectConfig: ProjectConfig = {
|
||||||
|
title: "Export 미리보기 테스트",
|
||||||
|
slug: "export-preview-test",
|
||||||
|
canvasPreset: "full",
|
||||||
|
} as ProjectConfig;
|
||||||
|
|
||||||
|
mockState = {
|
||||||
|
blocks: [
|
||||||
|
{
|
||||||
|
id: "blk_text_1",
|
||||||
|
type: "text",
|
||||||
|
props: {
|
||||||
|
text: "Export 미리보기 본문",
|
||||||
|
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(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
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>,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("EditorPage - Export 미리보기", () => {
|
||||||
|
it("메뉴에서 Export 미리보기 항목을 클릭하면 Export 미리보기 모달이 열려야 한다", () => {
|
||||||
|
render(<EditorPage />);
|
||||||
|
|
||||||
|
const menuButton = screen.getByText("메뉴");
|
||||||
|
fireEvent.click(menuButton);
|
||||||
|
|
||||||
|
const previewMenuItem = screen.getByText("Export 미리보기");
|
||||||
|
fireEvent.click(previewMenuItem);
|
||||||
|
|
||||||
|
const modalTitle = screen.getByText("Export 미리보기");
|
||||||
|
expect(modalTitle).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Export 미리보기 새로고침 시 /api/export/preview 를 호출하고 iframe 에 HTML 을 렌더해야 한다", async () => {
|
||||||
|
const fetchMock = vi.fn().mockResolvedValue(
|
||||||
|
new Response(
|
||||||
|
"<!DOCTYPE html><html><head><title>Export 미리보기 테스트</title></head><body>Export 미리보기 본문</body></html>",
|
||||||
|
{
|
||||||
|
status: 200,
|
||||||
|
headers: { "Content-Type": "text/html; charset=utf-8" },
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
vi.stubGlobal("fetch", fetchMock);
|
||||||
|
|
||||||
|
render(<EditorPage />);
|
||||||
|
|
||||||
|
const menuButton = screen.getByText("메뉴");
|
||||||
|
fireEvent.click(menuButton);
|
||||||
|
|
||||||
|
const previewMenuItem = screen.getByText("Export 미리보기");
|
||||||
|
fireEvent.click(previewMenuItem);
|
||||||
|
|
||||||
|
const refreshButton = screen.getByText("미리보기 새로고침");
|
||||||
|
fireEvent.click(refreshButton);
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
const [url, options] = fetchMock.mock.calls[0] as any;
|
||||||
|
expect(url).toBe("/api/export/preview");
|
||||||
|
expect(options.method).toBe("POST");
|
||||||
|
expect(options.headers["Content-Type"]).toBe("application/json");
|
||||||
|
|
||||||
|
const parsed = JSON.parse(options.body);
|
||||||
|
expect(Array.isArray(parsed.blocks)).toBe(true);
|
||||||
|
expect(parsed.blocks[0].id).toBe("blk_text_1");
|
||||||
|
expect(parsed.projectConfig.slug).toBe("export-preview-test");
|
||||||
|
|
||||||
|
const iframe = await screen.findByTestId("export-preview-frame");
|
||||||
|
const srcDoc = iframe.getAttribute("srcdoc") ?? "";
|
||||||
|
expect(srcDoc).toContain("Export 미리보기 테스트");
|
||||||
|
expect(srcDoc).toContain("Export 미리보기 본문");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||||
|
import { render, screen, fireEvent, cleanup } from "@testing-library/react";
|
||||||
|
import { ProjectPropertiesPanel } from "@/app/editor/panels/ProjectPropertiesPanel";
|
||||||
|
import type { ProjectConfig } from "@/features/editor/state/editorStore";
|
||||||
|
|
||||||
|
let mockState: { projectConfig: ProjectConfig; updateProjectConfig: ReturnType<typeof vi.fn> };
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
const baseConfig: ProjectConfig = {
|
||||||
|
title: "프로젝트",
|
||||||
|
slug: "project",
|
||||||
|
canvasPreset: "full",
|
||||||
|
canvasWidthPx: 1024,
|
||||||
|
canvasBgColorHex: "#0f172a",
|
||||||
|
bodyBgColorHex: "#020617",
|
||||||
|
headHtml: "",
|
||||||
|
trackingScript: "",
|
||||||
|
// SEO 필드는 아직 구현 전이지만, TDD 를 위해 기본값 형태만 지정해 둔다.
|
||||||
|
// 실제 타입 정의는 추후 15.1 구현에서 확장한다.
|
||||||
|
} as ProjectConfig;
|
||||||
|
|
||||||
|
mockState = {
|
||||||
|
projectConfig: baseConfig,
|
||||||
|
updateProjectConfig: vi.fn(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
cleanup();
|
||||||
|
});
|
||||||
|
|
||||||
|
vi.mock("@/features/editor/state/editorStore", () => {
|
||||||
|
const useEditorStore = (selector: (state: any) => any) => selector(mockState);
|
||||||
|
return {
|
||||||
|
__esModule: true,
|
||||||
|
useEditorStore,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("ProjectPropertiesPanel SEO 메타", () => {
|
||||||
|
it("SEO 타이틀 입력을 변경하면 seoTitle 이 updateProjectConfig 로 전달되어야 한다", () => {
|
||||||
|
render(<ProjectPropertiesPanel />);
|
||||||
|
|
||||||
|
const input = screen.getByLabelText("SEO 타이틀") as HTMLInputElement;
|
||||||
|
|
||||||
|
fireEvent.change(input, { target: { value: "새 SEO 타이틀" } });
|
||||||
|
|
||||||
|
expect(mockState.updateProjectConfig).toHaveBeenCalledWith({ seoTitle: "새 SEO 타이틀" });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("메타 디스크립션 입력을 변경하면 seoDescription 이 updateProjectConfig 로 전달되어야 한다", () => {
|
||||||
|
render(<ProjectPropertiesPanel />);
|
||||||
|
|
||||||
|
const textarea = screen.getByLabelText("메타 디스크립션") as HTMLTextAreaElement;
|
||||||
|
|
||||||
|
fireEvent.change(textarea, { target: { value: "SEO 설명" } });
|
||||||
|
|
||||||
|
expect(mockState.updateProjectConfig).toHaveBeenCalledWith({
|
||||||
|
seoDescription: "SEO 설명",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("OG/Twitter 이미지 URL 입력을 변경하면 seoOgImageUrl 이 updateProjectConfig 로 전달되어야 한다", () => {
|
||||||
|
render(<ProjectPropertiesPanel />);
|
||||||
|
|
||||||
|
const input = screen.getByLabelText("OG/Twitter 이미지 URL") as HTMLInputElement;
|
||||||
|
|
||||||
|
fireEvent.change(input, { target: { value: "https://example.com/og.png" } });
|
||||||
|
|
||||||
|
expect(mockState.updateProjectConfig).toHaveBeenCalledWith({
|
||||||
|
seoOgImageUrl: "https://example.com/og.png",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Canonical URL 입력을 변경하면 seoCanonicalUrl 이 updateProjectConfig 로 전달되어야 한다", () => {
|
||||||
|
render(<ProjectPropertiesPanel />);
|
||||||
|
|
||||||
|
const input = screen.getByLabelText("Canonical URL") as HTMLInputElement;
|
||||||
|
|
||||||
|
fireEvent.change(input, { target: { value: "https://example.com/landing" } });
|
||||||
|
|
||||||
|
expect(mockState.updateProjectConfig).toHaveBeenCalledWith({
|
||||||
|
seoCanonicalUrl: "https://example.com/landing",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("검색 노출 제어 체크박스를 토글하면 seoNoIndex 가 true 로 업데이트되어야 한다", () => {
|
||||||
|
render(<ProjectPropertiesPanel />);
|
||||||
|
|
||||||
|
const checkbox = screen.getByLabelText(
|
||||||
|
"검색 엔진에 노출하지 않기 (noindex)",
|
||||||
|
) as HTMLInputElement;
|
||||||
|
|
||||||
|
expect(checkbox.checked).toBe(false);
|
||||||
|
|
||||||
|
fireEvent.click(checkbox);
|
||||||
|
|
||||||
|
expect(mockState.updateProjectConfig).toHaveBeenCalledWith({
|
||||||
|
seoNoIndex: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import { describe, it, expect, afterEach } from "vitest";
|
||||||
|
import { render, screen, cleanup } from "@testing-library/react";
|
||||||
|
import { PublicPageRenderer } from "@/features/editor/components/PublicPageRenderer";
|
||||||
|
import { createFooterTemplateBlocks } from "@/app/editor/templates/footerTemplate";
|
||||||
|
import type { Block } from "@/features/editor/state/editorStore";
|
||||||
|
|
||||||
|
// PublicPageRenderer 푸터 템플릿 TDD
|
||||||
|
// - footerTemplate 로 생성한 섹션이 프리뷰에서 섹션/텍스트 구조로 올바르게 렌더되는지 검증한다.
|
||||||
|
|
||||||
|
describe("PublicPageRenderer - 푸터 템플릿", () => {
|
||||||
|
afterEach(() => {
|
||||||
|
cleanup();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("푸터 템플릿 섹션은 프리뷰에서 섹션과 푸터 텍스트들을 렌더해야 한다", () => {
|
||||||
|
const sectionId = "footer_preview_section";
|
||||||
|
let i = 0;
|
||||||
|
const createId = () => `footer_${++i}`;
|
||||||
|
|
||||||
|
const { blocks } = createFooterTemplateBlocks({ sectionId, createId });
|
||||||
|
|
||||||
|
render(<PublicPageRenderer blocks={blocks as Block[]} />);
|
||||||
|
|
||||||
|
const section = screen.getByTestId("preview-section");
|
||||||
|
expect(section.getAttribute("data-section-id")).toBe(sectionId);
|
||||||
|
|
||||||
|
expect(screen.getByText("MyLanding")).toBeTruthy();
|
||||||
|
expect(screen.getByText("더 나은 웹사이트를 위한 최고의 선택.")).toBeTruthy();
|
||||||
|
expect(screen.getByText(/서비스 소개/)).toBeTruthy();
|
||||||
|
expect(screen.getByText(/문의하기/)).toBeTruthy();
|
||||||
|
expect(screen.getByText(/© 2025 MyLanding\./)).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -2,7 +2,6 @@ import { describe, it, expect, vi } from "vitest";
|
|||||||
import { render, screen, fireEvent } from "@testing-library/react";
|
import { render, screen, fireEvent } from "@testing-library/react";
|
||||||
import { TextPropertiesPanel } from "@/app/editor/panels/TextPropertiesPanel";
|
import { TextPropertiesPanel } from "@/app/editor/panels/TextPropertiesPanel";
|
||||||
import { ListPropertiesPanel } from "@/app/editor/panels/ListPropertiesPanel";
|
import { ListPropertiesPanel } from "@/app/editor/panels/ListPropertiesPanel";
|
||||||
import { FormControllerPanel } from "@/app/editor/forms/FormControllerPanel";
|
|
||||||
import type { Block } from "@/features/editor/state/editorStore";
|
import type { Block } from "@/features/editor/state/editorStore";
|
||||||
|
|
||||||
// Text/List/Form 패널에 추가되는 블록 배경색(backgroundColorCustom) 컨트롤에 대한 최소 TDD
|
// Text/List/Form 패널에 추가되는 블록 배경색(backgroundColorCustom) 컨트롤에 대한 최소 TDD
|
||||||
@@ -58,34 +57,4 @@ describe("Text/List/Form 패널 - 블록 배경색 컨트롤", () => {
|
|||||||
expect.objectContaining({ backgroundColorCustom: "#445566" }),
|
expect.objectContaining({ backgroundColorCustom: "#445566" }),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("FormControllerPanel 에서 배경색 HEX 인풋 변경 시 updateBlock 이 backgroundColorCustom 으로 호출되어야 한다", () => {
|
|
||||||
const updateBlock = vi.fn();
|
|
||||||
|
|
||||||
const formBlock: Block = {
|
|
||||||
id: "form-1",
|
|
||||||
type: "form",
|
|
||||||
props: {
|
|
||||||
kind: "contact",
|
|
||||||
submitTarget: "internal",
|
|
||||||
} as any,
|
|
||||||
};
|
|
||||||
|
|
||||||
render(
|
|
||||||
<FormControllerPanel
|
|
||||||
block={formBlock}
|
|
||||||
blocks={[]}
|
|
||||||
selectedBlockId="form-1"
|
|
||||||
updateBlock={updateBlock}
|
|
||||||
/>,
|
|
||||||
);
|
|
||||||
|
|
||||||
const hexInput = screen.getByLabelText("폼 배경색 HEX");
|
|
||||||
fireEvent.change(hexInput, { target: { value: "#778899" } });
|
|
||||||
|
|
||||||
expect(updateBlock).toHaveBeenCalledWith(
|
|
||||||
"form-1",
|
|
||||||
expect.objectContaining({ backgroundColorCustom: "#778899" }),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -411,10 +411,9 @@ describe("formHelpers.computeFormControllerPublicTokens", () => {
|
|||||||
expect(checkboxField.groupLabelImageUrl).toBe("https://example.com/group.png");
|
expect(checkboxField.groupLabelImageUrl).toBe("https://example.com/group.png");
|
||||||
|
|
||||||
expect(tokens.formClassName).toBe("space-y-3");
|
expect(tokens.formClassName).toBe("space-y-3");
|
||||||
expect(tokens.formStyle.width).toBe("20em");
|
// FormBlock 은 이제 레이아웃/배경 스타일을 가지지 않는 순수 컨트롤러이므로,
|
||||||
expect(tokens.formStyle.marginTop).toBe("2em");
|
// formStyle 은 항상 빈 객체여야 한다.
|
||||||
expect(tokens.formStyle.marginBottom).toBe("2em");
|
expect(tokens.formStyle).toEqual({});
|
||||||
expect(tokens.formStyle.backgroundColor).toBe("#123456");
|
|
||||||
|
|
||||||
expect(tokens.submitLabel).toBe("컨트롤러 버튼");
|
expect(tokens.submitLabel).toBe("컨트롤러 버튼");
|
||||||
});
|
});
|
||||||
@@ -509,7 +508,8 @@ describe("formHelpers.computeFormBlockExportTokens", () => {
|
|||||||
expect(tokens.controllerFields[0].id).toBe("input-1");
|
expect(tokens.controllerFields[0].id).toBe("input-1");
|
||||||
expect(tokens.controllerFields[1].id).toBe("select-1");
|
expect(tokens.controllerFields[1].id).toBe("select-1");
|
||||||
expect(tokens.fallbackFields).toHaveLength(0);
|
expect(tokens.fallbackFields).toHaveLength(0);
|
||||||
expect(tokens.formStyleParts).toEqual(["background-color:#123456"]);
|
// FormBlock 은 Export 레이어에서도 컨테이너 배경/레이아웃 스타일을 가지지 않는다.
|
||||||
|
expect(tokens.formStyleParts).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fieldIds 가 없고 fields 가 있을 때 fallbackFields 를 사용해야 한다", () => {
|
it("fieldIds 가 없고 fields 가 있을 때 fallbackFields 를 사용해야 한다", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user