Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 176568f976 | |||
| 6a9a7939b2 | |||
| 894acbb6a1 | |||
| 899a1ba1a6 | |||
| f385966f87 | |||
| c4d46a5de3 | |||
| 39c64e3acd | |||
| df5786e418 | |||
| 9b8fbd6360 | |||
| 8ada2d1947 | |||
| 1a405a54fa | |||
| 5c23cf3873 | |||
| cc2b3039a3 | |||
| 0561c5d63c | |||
| e6c897a863 | |||
| 39318dd40d | |||
| be80f9339b | |||
| df41aac2b1 |
@@ -6,6 +6,8 @@ import { pageSchema, type Page } from '@/lib/schema/page'
|
||||
import { exportPage } from '@/lib/exporter/html'
|
||||
import { AssetManager } from '@/lib/assets/assetManager'
|
||||
import { buildZip } from '@/lib/exporter/zip'
|
||||
import { buildExtrasForPage } from '@/lib/exporter/extras'
|
||||
import { buildAssetsMetadata } from '@/lib/exporter/assets.meta'
|
||||
import type { Section } from '@/lib/state/store'
|
||||
import { createFormStore, type FormState } from '@/lib/state/formStore'
|
||||
import FormBuilderPanel from '@/components/FormBuilderPanel'
|
||||
@@ -47,6 +49,13 @@ export default function BuilderClientPage() {
|
||||
const [ogImage, setOgImage] = useState<string>('')
|
||||
const [ga4MeasurementId, setGa4MeasurementId] = useState<string>('')
|
||||
const [metaPixelId, setMetaPixelId] = useState<string>('')
|
||||
// Export Options (manifest/robots overrides)
|
||||
const [manifestName, setManifestName] = useState<string>('')
|
||||
const [manifestShortName, setManifestShortName] = useState<string>('')
|
||||
const [manifestStartUrl, setManifestStartUrl] = useState<string>('')
|
||||
const [manifestDisplay, setManifestDisplay] = useState<string>('')
|
||||
const [manifestThemeColor, setManifestThemeColor] = useState<string>('')
|
||||
const [robotsDisallow, setRobotsDisallow] = useState<string>('')
|
||||
const [viewport, setViewport] = useState<'desktop' | 'mobile'>(() => {
|
||||
if (typeof window !== 'undefined') {
|
||||
try {
|
||||
@@ -185,7 +194,20 @@ export default function BuilderClientPage() {
|
||||
}, [pageData, am])
|
||||
|
||||
const doExport = useCallback(async () => {
|
||||
const valid = pageSchema.parse(pageData)
|
||||
let valid = pageData as Page
|
||||
try {
|
||||
valid = pageSchema.parse(pageData)
|
||||
} catch {
|
||||
const fixed: Page = {
|
||||
...pageData,
|
||||
form: {
|
||||
actionUrl: pageData.form?.actionUrl ?? '',
|
||||
fields: pageData.form?.fields ?? [],
|
||||
spamProtection: pageData.form?.spamProtection ?? { honeypotFieldName: '_hp', minSubmitSeconds: 2 },
|
||||
},
|
||||
} as Page
|
||||
valid = pageSchema.parse(fixed)
|
||||
}
|
||||
const exported = exportPage(valid, { assetManager: am ?? undefined })
|
||||
try {
|
||||
if (typeof window !== 'undefined') {
|
||||
@@ -196,9 +218,34 @@ export default function BuilderClientPage() {
|
||||
}
|
||||
} catch {}
|
||||
const assets = am ? am.toZipStructure() : {}
|
||||
const zipBytes = await buildZip({ html: exported.html, css: exported.css, js: exported.js, assets })
|
||||
// Build overrides from UI options
|
||||
const manifestOverrideBase: Record<string, string> = {}
|
||||
if (manifestName && manifestName.trim().length > 0) manifestOverrideBase.name = manifestName.trim()
|
||||
if (manifestShortName && manifestShortName.trim().length > 0) manifestOverrideBase.short_name = manifestShortName.trim()
|
||||
if (manifestStartUrl && manifestStartUrl.trim().length > 0) manifestOverrideBase.start_url = manifestStartUrl.trim()
|
||||
if (manifestDisplay && manifestDisplay.trim().length > 0) manifestOverrideBase.display = manifestDisplay.trim()
|
||||
if (manifestThemeColor && manifestThemeColor.trim().length > 0) {
|
||||
const v = manifestThemeColor.trim()
|
||||
const hexOk = /^#([0-9a-fA-F]{3}){1,2}$/.test(v)
|
||||
if (hexOk) {
|
||||
manifestOverrideBase.theme_color = v
|
||||
}
|
||||
}
|
||||
const manifestOverride = Object.keys(manifestOverrideBase).length > 0 ? (manifestOverrideBase as { name?: string; short_name?: string; start_url?: string; display?: string; theme_color?: string }) : undefined
|
||||
const robotsTextOverride = (() => {
|
||||
const lines = (robotsDisallow || '').split(/\n+/).map((s) => s.trim()).filter((s) => s.length > 0)
|
||||
if (lines.length === 0) return undefined
|
||||
const disallowLines = lines.map((l) => (l.startsWith('Disallow:') ? l : `Disallow: ${l}`))
|
||||
return `User-agent: *\n${disallowLines.join('\n')}`
|
||||
})()
|
||||
const baseExtras = buildExtrasForPage(valid, { robotsText: robotsTextOverride, manifest: manifestOverride })
|
||||
const extras: Record<string, Uint8Array> = {
|
||||
...baseExtras,
|
||||
...(am ? { 'assets.json': buildAssetsMetadata(am) } : {}),
|
||||
}
|
||||
const zipBytes = await buildZip({ html: exported.html, css: exported.css, js: exported.js, assets, extras })
|
||||
download('landing.zip', zipBytes)
|
||||
}, [pageData, am])
|
||||
}, [pageData, am, manifestName, manifestShortName, manifestStartUrl, manifestDisplay, manifestThemeColor, robotsDisallow])
|
||||
|
||||
return (
|
||||
<div className="p-6 space-y-6">
|
||||
@@ -261,6 +308,80 @@ export default function BuilderClientPage() {
|
||||
onSelect={(i) => setSelectedIndex(i)}
|
||||
/>
|
||||
</div>
|
||||
<div className="border rounded p-3 space-y-2">
|
||||
<h2 className="text-sm font-semibold mb-1">Export Options</h2>
|
||||
<label className="block" htmlFor="ins-manifest-name">
|
||||
<span className="sr-only">Manifest Name</span>
|
||||
<input
|
||||
id="ins-manifest-name"
|
||||
aria-label="Manifest Name"
|
||||
className="border rounded px-3 py-2 w-full"
|
||||
value={manifestName}
|
||||
onChange={(e) => setManifestName(e.target.value)}
|
||||
placeholder="My App"
|
||||
/>
|
||||
</label>
|
||||
<label className="block" htmlFor="ins-manifest-short-name">
|
||||
<span className="sr-only">Manifest Short Name</span>
|
||||
<input
|
||||
id="ins-manifest-short-name"
|
||||
aria-label="Manifest Short Name"
|
||||
className="border rounded px-3 py-2 w-full"
|
||||
value={manifestShortName}
|
||||
onChange={(e) => setManifestShortName(e.target.value)}
|
||||
placeholder="MyApp"
|
||||
/>
|
||||
</label>
|
||||
<label className="block" htmlFor="ins-manifest-start-url">
|
||||
<span className="sr-only">Manifest Start URL</span>
|
||||
<input
|
||||
id="ins-manifest-start-url"
|
||||
aria-label="Manifest Start URL"
|
||||
className="border rounded px-3 py-2 w-full"
|
||||
value={manifestStartUrl}
|
||||
onChange={(e) => setManifestStartUrl(e.target.value)}
|
||||
placeholder="/"
|
||||
/>
|
||||
</label>
|
||||
<label className="block" htmlFor="ins-manifest-display">
|
||||
<span className="sr-only">Manifest Display</span>
|
||||
<select
|
||||
id="ins-manifest-display"
|
||||
aria-label="Manifest Display"
|
||||
className="border rounded px-3 py-2 w-full"
|
||||
value={manifestDisplay}
|
||||
onChange={(e) => setManifestDisplay(e.target.value)}
|
||||
>
|
||||
<option value="">(default)</option>
|
||||
<option value="standalone">standalone</option>
|
||||
<option value="minimal-ui">minimal-ui</option>
|
||||
<option value="browser">browser</option>
|
||||
</select>
|
||||
</label>
|
||||
<label className="block" htmlFor="ins-manifest-theme-color">
|
||||
<span className="sr-only">Manifest Theme Color</span>
|
||||
<input
|
||||
id="ins-manifest-theme-color"
|
||||
aria-label="Manifest Theme Color"
|
||||
className="border rounded px-3 py-2 w-full"
|
||||
value={manifestThemeColor}
|
||||
onChange={(e) => setManifestThemeColor(e.target.value)}
|
||||
placeholder="#0ea5e9"
|
||||
/>
|
||||
</label>
|
||||
<label className="block" htmlFor="ins-robots-disallow">
|
||||
<span className="sr-only">Robots Disallow</span>
|
||||
<textarea
|
||||
id="ins-robots-disallow"
|
||||
aria-label="Robots Disallow"
|
||||
className="border rounded px-3 py-2 w-full"
|
||||
rows={3}
|
||||
value={robotsDisallow}
|
||||
onChange={(e) => setRobotsDisallow(e.target.value)}
|
||||
placeholder="/private\n/tmp"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
right={
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import BuilderClientPage from '@/components/BuilderClientPage'
|
||||
|
||||
vi.mock('next-intl', () => {
|
||||
return {
|
||||
useTranslations: () => (key: string) => key,
|
||||
}
|
||||
})
|
||||
|
||||
const buildZipSpy = vi.fn(async (_arg: {
|
||||
html: string
|
||||
css: string
|
||||
js: string
|
||||
assets: Record<string, Uint8Array>
|
||||
extras?: Record<string, Uint8Array>
|
||||
}) => new Uint8Array([80, 75]))
|
||||
|
||||
vi.mock('@/lib/exporter/zip', () => {
|
||||
return {
|
||||
buildZip: (arg: {
|
||||
html: string
|
||||
css: string
|
||||
js: string
|
||||
assets: Record<string, Uint8Array>
|
||||
extras?: Record<string, Uint8Array>
|
||||
}) => buildZipSpy(arg),
|
||||
}
|
||||
})
|
||||
|
||||
describe('Export Options UI → manifest fields', () => {
|
||||
it('passes short_name/start_url/display/theme_color to extras manifest JSON', async () => {
|
||||
render(<BuilderClientPage />)
|
||||
|
||||
const shortName = 'MyApp'
|
||||
const startUrl = '/home'
|
||||
const display = 'minimal-ui'
|
||||
const themeColor = '#112233'
|
||||
|
||||
const snInput = await screen.findByLabelText('Manifest Short Name')
|
||||
fireEvent.change(snInput, { target: { value: shortName } })
|
||||
|
||||
const startInput = await screen.findByLabelText('Manifest Start URL')
|
||||
fireEvent.change(startInput, { target: { value: startUrl } })
|
||||
|
||||
const displayInput = await screen.findByLabelText('Manifest Display')
|
||||
fireEvent.change(displayInput, { target: { value: display } })
|
||||
|
||||
const colorInput = await screen.findByLabelText('Manifest Theme Color')
|
||||
fireEvent.change(colorInput, { target: { value: themeColor } })
|
||||
|
||||
const exportBtn = await screen.findByRole('button', { name: 'builder.action.export' })
|
||||
fireEvent.click(exportBtn)
|
||||
|
||||
expect(buildZipSpy).toHaveBeenCalled()
|
||||
const first = buildZipSpy.mock.calls[0]
|
||||
const extras: Record<string, Uint8Array> = (first![0] as { extras: Record<string, Uint8Array> }).extras
|
||||
const td = new TextDecoder()
|
||||
const manifestRaw = td.decode(extras['site.webmanifest'])
|
||||
const manifest = JSON.parse(manifestRaw)
|
||||
|
||||
expect(manifest.short_name).toBe(shortName)
|
||||
expect(manifest.start_url).toBe(startUrl)
|
||||
expect(manifest.display).toBe(display)
|
||||
expect(manifest.theme_color).toBe(themeColor)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,64 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import BuilderClientPage from '@/components/BuilderClientPage'
|
||||
|
||||
vi.mock('next-intl', () => {
|
||||
return {
|
||||
useTranslations: () => (key: string) => key,
|
||||
}
|
||||
})
|
||||
|
||||
const buildZipSpy = vi.fn(async (_arg: {
|
||||
html: string
|
||||
css: string
|
||||
js: string
|
||||
assets: Record<string, Uint8Array>
|
||||
extras?: Record<string, Uint8Array>
|
||||
}) => new Uint8Array([80, 75]))
|
||||
|
||||
vi.mock('@/lib/exporter/zip', () => {
|
||||
return {
|
||||
buildZip: (arg: {
|
||||
html: string
|
||||
css: string
|
||||
js: string
|
||||
assets: Record<string, Uint8Array>
|
||||
extras?: Record<string, Uint8Array>
|
||||
}) => buildZipSpy(arg),
|
||||
}
|
||||
})
|
||||
|
||||
describe('Export Options UI polish', () => {
|
||||
it('uses a dropdown for Manifest Display and passes selected value', async () => {
|
||||
render(<BuilderClientPage />)
|
||||
|
||||
// choose display = minimal-ui
|
||||
const displaySelect = await screen.findByLabelText('Manifest Display')
|
||||
fireEvent.change(displaySelect, { target: { value: 'minimal-ui' } })
|
||||
|
||||
const exportBtn = await screen.findByRole('button', { name: 'builder.action.export' })
|
||||
fireEvent.click(exportBtn)
|
||||
|
||||
const first = buildZipSpy.mock.calls[0]
|
||||
const extras: Record<string, Uint8Array> = (first![0] as { extras: Record<string, Uint8Array> }).extras
|
||||
const td = new TextDecoder()
|
||||
const manifest = JSON.parse(td.decode(extras['site.webmanifest']))
|
||||
expect(manifest.display).toBe('minimal-ui')
|
||||
})
|
||||
|
||||
it('ignores invalid theme_color override and keeps default theme when not a hex', async () => {
|
||||
render(<BuilderClientPage />)
|
||||
|
||||
const colorInput = await screen.findByLabelText('Manifest Theme Color')
|
||||
fireEvent.change(colorInput, { target: { value: 'blue' } }) // invalid hex
|
||||
|
||||
const exportBtn = await screen.findByRole('button', { name: 'builder.action.export' })
|
||||
fireEvent.click(exportBtn)
|
||||
|
||||
const first = buildZipSpy.mock.calls[0]
|
||||
const extras: Record<string, Uint8Array> = (first![0] as { extras: Record<string, Uint8Array> }).extras
|
||||
const td = new TextDecoder()
|
||||
const manifest = JSON.parse(td.decode(extras['site.webmanifest']))
|
||||
expect(manifest.theme_color).toBe('#0ea5e9') // default from page.theme.primaryColor
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,60 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import BuilderClientPage from '@/components/BuilderClientPage'
|
||||
|
||||
vi.mock('next-intl', () => {
|
||||
return {
|
||||
useTranslations: () => (key: string) => key,
|
||||
}
|
||||
})
|
||||
|
||||
const buildZipSpy = vi.fn(async (_arg: {
|
||||
html: string
|
||||
css: string
|
||||
js: string
|
||||
assets: Record<string, Uint8Array>
|
||||
extras?: Record<string, Uint8Array>
|
||||
}) => new Uint8Array([80, 75]))
|
||||
|
||||
vi.mock('@/lib/exporter/zip', () => {
|
||||
return {
|
||||
buildZip: (arg: {
|
||||
html: string
|
||||
css: string
|
||||
js: string
|
||||
assets: Record<string, Uint8Array>
|
||||
extras?: Record<string, Uint8Array>
|
||||
}) => buildZipSpy(arg),
|
||||
}
|
||||
})
|
||||
|
||||
describe('Export Options UI → extras overrides', () => {
|
||||
it('passes manifest.name and robots Disallow to buildExtrasForPage via buildZip extras', async () => {
|
||||
render(<BuilderClientPage />)
|
||||
|
||||
const manifestName = 'My App Custom'
|
||||
const robotsDisallow = '/private\n/tmp'
|
||||
|
||||
const nameInput = await screen.findByLabelText('Manifest Name')
|
||||
fireEvent.change(nameInput, { target: { value: manifestName } })
|
||||
|
||||
const robotsInput = await screen.findByLabelText('Robots Disallow')
|
||||
fireEvent.change(robotsInput, { target: { value: robotsDisallow } })
|
||||
|
||||
const exportBtn = await screen.findByRole('button', { name: 'builder.action.export' })
|
||||
fireEvent.click(exportBtn)
|
||||
|
||||
expect(buildZipSpy).toHaveBeenCalled()
|
||||
const first = buildZipSpy.mock.calls[0]
|
||||
expect(first && first[0]).toBeTruthy()
|
||||
const extras: Record<string, Uint8Array> = (first![0] as { extras: Record<string, Uint8Array> }).extras
|
||||
const td = new TextDecoder()
|
||||
const manifestRaw = td.decode(extras['site.webmanifest'])
|
||||
const robotsRaw = td.decode(extras['robots.txt'])
|
||||
const manifest = JSON.parse(manifestRaw)
|
||||
|
||||
expect(manifest.name).toBe(manifestName)
|
||||
expect(robotsRaw).toMatch(/Disallow: \/private/)
|
||||
expect(robotsRaw).toMatch(/Disallow: \/tmp/)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,30 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { AssetManager } from '@/lib/assets/assetManager'
|
||||
import { buildAssetsMetadata } from '@/lib/exporter/assets.meta'
|
||||
import type { AssetMetaItem } from '@/lib/exporter/assets.meta'
|
||||
|
||||
function u8(n: number): Uint8Array {
|
||||
const arr = new Uint8Array(n)
|
||||
for (let i = 0; i < n; i++) arr[i] = (i * 31) & 0xff
|
||||
return arr
|
||||
}
|
||||
|
||||
describe('Assets metadata builder', () => {
|
||||
it('emits assets.json with originalName/mime/size/hash/ext/zipPath', async () => {
|
||||
const am = new AssetManager({ maxBytes: 1024 * 1024, allowedExts: ['png'] })
|
||||
const bytes = u8(10)
|
||||
await am.add({ name: 'hero.png', type: 'image/png', bytes })
|
||||
const metaBytes = buildAssetsMetadata(am)
|
||||
const json = new TextDecoder().decode(metaBytes)
|
||||
const obj = JSON.parse(json) as { assets: AssetMetaItem[] }
|
||||
expect(Array.isArray(obj.assets)).toBe(true)
|
||||
expect(obj.assets.length).toBe(1)
|
||||
const a = obj.assets[0]
|
||||
expect(a.originalName).toBe('hero.png')
|
||||
expect(a.mimeType).toBe('image/png')
|
||||
expect(a.size).toBe(bytes.byteLength)
|
||||
expect(a.ext).toBe('png')
|
||||
expect(a.hash8).toMatch(/^[0-9a-f]{8}$/)
|
||||
expect(a.zipPath).toMatch(/^assets\/[0-9a-f]{8}\.png$/)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,30 @@
|
||||
import type { AssetManager } from '@/lib/assets/assetManager'
|
||||
|
||||
export type AssetMetaItem = {
|
||||
originalName: string
|
||||
mimeType: string
|
||||
size: number
|
||||
hash8: string
|
||||
ext: string
|
||||
zipPath: string
|
||||
integrity: string
|
||||
}
|
||||
|
||||
export function buildAssetsMetadata(am: AssetManager): Uint8Array {
|
||||
const list = am.list()
|
||||
const items: AssetMetaItem[] = list.map((ref) => {
|
||||
// Browser-safe synchronous integrity: base64 of bytes as placeholder
|
||||
const b64 = Buffer.from(ref.bytes).toString('base64')
|
||||
return {
|
||||
originalName: ref.originalName,
|
||||
mimeType: ref.mimeType,
|
||||
size: ref.bytes.byteLength,
|
||||
hash8: ref.hash8,
|
||||
ext: ref.ext,
|
||||
zipPath: ref.path,
|
||||
integrity: `sha256-${b64}`,
|
||||
}
|
||||
})
|
||||
const json = JSON.stringify({ assets: items }, null, 2)
|
||||
return new TextEncoder().encode(json)
|
||||
}
|
||||
@@ -124,7 +124,7 @@ function renderHero(section: { props: { heading: string; subheading?: string; im
|
||||
${subheading.length > 0 ? `<p>${escapeHtml(subheading)}</p>` : ''}
|
||||
</div>
|
||||
<div class="media">
|
||||
<img src="${escapeHtml(imageUrl)}" alt="${escapeHtml(heading)}" loading="lazy" decoding="async" />
|
||||
<img src="${escapeHtml(imageUrl)}" alt="${escapeHtml(heading)}" loading="lazy" decoding="async" width="1200" height="675" />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@@ -255,6 +255,8 @@ function buildHead(page: Page) {
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="canonical" href="/" />
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="manifest" href="/site.webmanifest" />
|
||||
<meta name="theme-color" content="${escapeHtml(page.theme.primaryColor)}" />
|
||||
<title>${escapeHtml(page.seo.title)}</title>
|
||||
<meta name="description" content="${escapeHtml(page.seo.description)}" />
|
||||
<meta property="og:title" content="${escapeHtml(page.seo.title)}" />
|
||||
@@ -337,6 +339,7 @@ export function exportPage(page: Page, opts?: ExportOptions): Exported {
|
||||
<html lang="${escapeHtml(page.locale)}">
|
||||
<head>
|
||||
${buildHead(page)}
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { exportPage } from '@/lib/exporter/html'
|
||||
import { pageSchema, type Page } from '@/lib/schema/page'
|
||||
|
||||
function makePage(): Page {
|
||||
return pageSchema.parse({
|
||||
title: 'Head Links',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
||||
sections: [],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
seo: { title: 't', description: 'd' },
|
||||
})
|
||||
}
|
||||
|
||||
describe('Exporter - head 링크 토큰', () => {
|
||||
it('site.webmanifest 링크를 포함한다', () => {
|
||||
const out = exportPage(makePage())
|
||||
expect(out.html).toMatch(/<link rel="manifest" href="\/site\.webmanifest"\s*\/>/)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,31 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { exportPage } from '@/lib/exporter/html'
|
||||
import { pageSchema, type Page } from '@/lib/schema/page'
|
||||
|
||||
function makePage(): Page {
|
||||
return pageSchema.parse({
|
||||
title: 'SEO/Perf 2',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#0ea5e9', fontFamily: 'Inter' },
|
||||
sections: [
|
||||
{ type: 'hero', props: { heading: 'Hello', subheading: 'World', imageUrl: 'https://img.example/hero.png' } },
|
||||
],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
seo: { title: 'SEO2', description: 'Desc2' },
|
||||
})
|
||||
}
|
||||
|
||||
describe('Exporter - theme-color meta and hero image intrinsic size', () => {
|
||||
it('includes theme-color meta using page.theme.primaryColor', () => {
|
||||
const out = exportPage(makePage())
|
||||
const html = out.html
|
||||
expect(html).toMatch(/<meta name="theme-color" content="#0ea5e9"\s*\/>/)
|
||||
})
|
||||
|
||||
it('renders hero image with width/height attributes for CLS reduction', () => {
|
||||
const out = exportPage(makePage())
|
||||
const html = out.html
|
||||
expect(html).toMatch(/<img[^>]*\swidth="[0-9]+"/)
|
||||
expect(html).toMatch(/<img[^>]*\sheight="[0-9]+"/)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,47 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { buildZip } from '@/lib/exporter/zip'
|
||||
import { exportPage } from '@/lib/exporter/html'
|
||||
import { pageSchema, type Page } from '@/lib/schema/page'
|
||||
import { buildExtrasForPage } from '@/lib/exporter/extras'
|
||||
|
||||
function makePageNoAction(): Page {
|
||||
return pageSchema.parse({
|
||||
title: 'Sheets Tpl',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
||||
sections: [ { type: 'hero', props: { heading: 'Hello', subheading: 'World', imageUrl: 'https://img/h.png' } } ],
|
||||
form: { actionUrl: '', fields: [ { type: 'text', name: 'email', label: 'Email', required: true } ], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
seo: { title: 't', description: 'd' },
|
||||
})
|
||||
}
|
||||
|
||||
function makePageWithAction(): Page {
|
||||
return pageSchema.parse({
|
||||
title: 'Sheets Off',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
||||
sections: [ { type: 'hero', props: { heading: 'Hello', subheading: 'World', imageUrl: 'https://img/h.png' } } ],
|
||||
form: { actionUrl: 'https://example.com/submit', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
seo: { title: 't', description: 'd' },
|
||||
})
|
||||
}
|
||||
|
||||
describe('Sheets 템플릿 Export', () => {
|
||||
it('actionUrl 미지정 시 extras에 Sheets 템플릿 파일을 포함한다', async () => {
|
||||
const page = makePageNoAction()
|
||||
const extras = buildExtrasForPage(page)
|
||||
expect(Object.keys(extras)).toContain('sheets/Code.gs')
|
||||
expect(Object.keys(extras)).toContain('sheets/README.txt')
|
||||
|
||||
const out = exportPage(page)
|
||||
const zipBytes = await buildZip({ html: out.html, css: out.css, js: out.js, assets: {}, extras })
|
||||
expect(zipBytes.byteLength).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('actionUrl 지정 시 extras에는 Sheets 템플릿이 포함되지 않는다', () => {
|
||||
const page = makePageWithAction()
|
||||
const extras = buildExtrasForPage(page)
|
||||
expect(Object.keys(extras)).not.toContain('sheets/Code.gs')
|
||||
expect(Object.keys(extras)).not.toContain('sheets/README.txt')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user