Compare commits
58 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a9a7939b2 | |||
| 894acbb6a1 | |||
| 899a1ba1a6 | |||
| f385966f87 | |||
| c4d46a5de3 | |||
| 2caffe9950 | |||
| 8757809928 | |||
| 39c64e3acd | |||
| df5786e418 | |||
| 76889080e8 | |||
| 68c8c8ff15 | |||
| 9b8fbd6360 | |||
| 8ada2d1947 | |||
| 1a405a54fa | |||
| 5c23cf3873 | |||
| cc2b3039a3 | |||
| 0561c5d63c | |||
| e6c897a863 | |||
| 39318dd40d | |||
| be80f9339b | |||
| df41aac2b1 | |||
| a620ff970a | |||
| 524abda49c | |||
| fe62656d37 | |||
| 8ad3a9e677 | |||
| e9a87773ea | |||
| 678b081364 | |||
| 46a9c5c83d | |||
| 6c86e1cf85 | |||
| a16541e90d | |||
| aaea43f2cc | |||
| 3f7bf3f1c8 | |||
| bc29faf60c | |||
| 4b9627d4ee | |||
| 26a3b43d28 | |||
| a476756a6c | |||
| 6ff27295e6 | |||
| 8d5501d927 | |||
| cd8ae32203 | |||
| 7110db8a4a | |||
| 7b36e14b65 | |||
| 32a760dd9a | |||
| 3d2f1dc8d4 | |||
| a957401a59 | |||
| 9cc5db5d28 | |||
| 16da17e533 | |||
| 8205215c17 | |||
| 36514286aa | |||
| cc271abedb | |||
| 8297002dc5 | |||
| 25ed57da53 | |||
| 90e410f49e | |||
| 14a3d32480 | |||
| f6c54d1074 | |||
| 1ffebc774f | |||
| 19b8becc30 | |||
| 602f1eabde | |||
| d6510e2b05 |
@@ -0,0 +1,37 @@
|
||||
name: Auto Label PR
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
jobs:
|
||||
add-automerge-label:
|
||||
runs-on: [macos, host]
|
||||
steps:
|
||||
- name: Add 'automerge' label to PR
|
||||
env:
|
||||
CI_TOKEN: ${{ secrets.CI_TOKEN }}
|
||||
GITEA_BASE_URL: https://gitea.jaybe.dev
|
||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||
REPO: ${{ github.repository }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ -z "${CI_TOKEN:-}" ]; then
|
||||
echo "CI_TOKEN not set; skipping labeling"; exit 0; fi
|
||||
OWNER=$(echo "$REPO" | cut -d'/' -f1)
|
||||
NAME=$(echo "$REPO" | cut -d'/' -f2)
|
||||
echo "Resolving existing label id for 'automerge' in $OWNER/$NAME (no creation)"
|
||||
curl -sS -o /tmp/labels.json -H "Authorization: token ${CI_TOKEN}" \
|
||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/labels?limit=1000" || true
|
||||
# Extract all ids whose name == automerge, prefer the smallest id (oldest)
|
||||
LID=$(tr '\n' ' ' < /tmp/labels.json | \
|
||||
grep -o '"id":[0-9][0-9]*[^\}]*"name":"automerge"' | \
|
||||
sed -E 's/.*"id":([0-9]+).*/\1/' | sort -n | head -n1 || true)
|
||||
if [ -z "${LID:-}" ]; then
|
||||
echo "No existing 'automerge' label found; skipping labeling"; exit 0; fi
|
||||
echo "Labeling PR #$PR_NUMBER with id $LID"
|
||||
curl -sS -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: token ${CI_TOKEN}" \
|
||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/issues/${PR_NUMBER}/labels" \
|
||||
-d '{"labels":['"${LID}"']}' || true
|
||||
@@ -0,0 +1,76 @@
|
||||
name: Auto PR
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'feat/**'
|
||||
|
||||
jobs:
|
||||
open-pr:
|
||||
runs-on: [macos, host]
|
||||
steps:
|
||||
- name: Create Pull Request via Gitea API
|
||||
env:
|
||||
CI_TOKEN: ${{ secrets.CI_TOKEN }}
|
||||
GITEA_BASE_URL: https://gitea.jaybe.dev
|
||||
REPO: ${{ github.repository }}
|
||||
HEAD_BRANCH: ${{ github.ref_name }}
|
||||
BASE_BRANCH: main
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ -z "${CI_TOKEN:-}" ]; then
|
||||
echo "GITEA_TOKEN not set; skipping auto-pr"; exit 0; fi
|
||||
OWNER=$(echo "$REPO" | cut -d'/' -f1)
|
||||
NAME=$(echo "$REPO" | cut -d'/' -f2)
|
||||
TITLE="auto: PR for $HEAD_BRANCH"
|
||||
BODY="Automated PR created on push to $HEAD_BRANCH"
|
||||
echo "Creating PR $HEAD_BRANCH -> $BASE_BRANCH for $OWNER/$NAME"
|
||||
HTTP_CODE=$(curl -sS -o /tmp/pr_resp.json -w "%{http_code}" -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: token ${CI_TOKEN}" \
|
||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/pulls" \
|
||||
-d "{\"head\":\"${HEAD_BRANCH}\",\"base\":\"${BASE_BRANCH}\",\"title\":\"${TITLE}\",\"body\":\"${BODY}\"}") || true
|
||||
echo "API status: $HTTP_CODE"
|
||||
if [ "$HTTP_CODE" = "201" ]; then
|
||||
echo "PR created"; cat /tmp/pr_resp.json
|
||||
PR_NUMBER=$(cat /tmp/pr_resp.json | sed -n 's/.*"number":\([0-9]*\).*/\1/p' | head -n1)
|
||||
else
|
||||
echo "PR not created (possibly exists). Response:"; cat /tmp/pr_resp.json || true
|
||||
fi
|
||||
|
||||
# Retry to resolve PR number by listing open PRs and matching head/base
|
||||
i=0
|
||||
while [ -z "${PR_NUMBER:-}" ] && [ $i -lt 10 ]; do
|
||||
i=$((i+1))
|
||||
echo "[retry $i] Resolving PR number for $HEAD_BRANCH -> $BASE_BRANCH"
|
||||
curl -sS -o /tmp/pr_list.json -H "Authorization: token ${CI_TOKEN}" \
|
||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/pulls?state=open" || true
|
||||
# Extract PR number matching head.ref==HEAD_BRANCH and base.ref==BASE_BRANCH
|
||||
PR_NUMBER=$(awk -v hb="$HEAD_BRANCH" -v bb="$BASE_BRANCH" 'BEGIN{RS="},"; pr=""} {
|
||||
if($0 ~ /\"head\":\{[^}]*\"ref\":\"" hb "\"/ && $0 ~ /\"base\":\{[^}]*\"ref\":\"" bb "\"/){
|
||||
if (match($0, /\"number\":([0-9]+)/, m)) { print m[1]; exit }
|
||||
}
|
||||
}' /tmp/pr_list.json)
|
||||
if [ -z "${PR_NUMBER:-}" ]; then sleep 2; fi
|
||||
done
|
||||
|
||||
if [ -n "${PR_NUMBER:-}" ]; then
|
||||
echo "Resolving existing label id for 'automerge' in $OWNER/$NAME (no creation)"
|
||||
curl -sS -o /tmp/labels.json -H "Authorization: token ${CI_TOKEN}" \
|
||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/labels?limit=1000" || true
|
||||
LID=$(tr '\n' ' ' < /tmp/labels.json | \
|
||||
grep -o '"id":[0-9][0-9]*[^\}]*"name":"automerge"' | \
|
||||
sed -E 's/.*"id":([0-9]+).*/\1/' | sort -n | head -n1 || true)
|
||||
if [ -n "${LID:-}" ]; then
|
||||
echo "Adding 'automerge' (id=$LID) label to PR #$PR_NUMBER"
|
||||
curl -sS -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: token ${CI_TOKEN}" \
|
||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/issues/${PR_NUMBER}/labels" \
|
||||
-d '{"labels":['"${LID}"']}' || true
|
||||
else
|
||||
echo "No existing 'automerge' label found; skipping label add"
|
||||
fi
|
||||
else
|
||||
echo "PR number could not be determined; skipping label add"
|
||||
fi
|
||||
@@ -0,0 +1,82 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, master ]
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: [macos, host]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install deps
|
||||
run: npm ci
|
||||
|
||||
- name: Unit/Component tests (Vitest)
|
||||
run: npm test
|
||||
env:
|
||||
CI: true
|
||||
|
||||
- name: Install Playwright browsers
|
||||
run: npx playwright install --with-deps
|
||||
|
||||
- name: E2E tests (Playwright)
|
||||
run: npm run test:e2e -- --reporter=line
|
||||
env:
|
||||
CI: true
|
||||
|
||||
- name: Upload Playwright report
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: playwright-report
|
||||
path: playwright-report
|
||||
if-no-files-found: ignore
|
||||
retention-days: 3
|
||||
|
||||
- name: Auto-merge PR on green
|
||||
if: ${{ github.event_name == 'pull_request' }}
|
||||
env:
|
||||
CI_TOKEN: ${{ secrets.CI_TOKEN }}
|
||||
GITEA_BASE_URL: https://gitea.jaybe.dev
|
||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||
REPO: ${{ github.repository }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ -z "${CI_TOKEN:-}" ]; then
|
||||
echo "CI_TOKEN not set; skipping auto-merge"; exit 0; fi
|
||||
OWNER=$(echo "$REPO" | cut -d'/' -f1)
|
||||
NAME=$(echo "$REPO" | cut -d'/' -f2)
|
||||
echo "Checking labels for PR #$PR_NUMBER on $OWNER/$NAME"
|
||||
LABELS_JSON=$(curl -sS -X GET \
|
||||
-H "Authorization: token ${CI_TOKEN}" \
|
||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/issues/${PR_NUMBER}")
|
||||
echo "labels payload (first 200 chars):"; echo "$LABELS_JSON" | cut -c1-200 || true
|
||||
if ! echo "$LABELS_JSON" | grep -qi '"name":"automerge"'; then
|
||||
echo "Label 'automerge' not present; skipping merge"; exit 0; fi
|
||||
echo "Label 'automerge' present; proceeding to merge"
|
||||
# ensure PR is open
|
||||
PR_JSON=$(curl -sS -X GET \
|
||||
-H "Authorization: token ${CI_TOKEN}" \
|
||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/pulls/${PR_NUMBER}")
|
||||
STATE=$(echo "$PR_JSON" | sed -n 's/.*"state":"\([^"]*\)".*/\1/p')
|
||||
echo "PR state: ${STATE:-unknown}"
|
||||
if [ "${STATE:-}" != "open" ]; then
|
||||
echo "PR state is not open; skipping merge"; exit 0; fi
|
||||
echo "Merging PR #$PR_NUMBER for $OWNER/$NAME"
|
||||
HTTP_CODE=$(curl -sS -o /tmp/merge_resp.json -w "%{http_code}" -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: token ${CI_TOKEN}" \
|
||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/pulls/${PR_NUMBER}/merge" \
|
||||
-d '{"Do":"merge","MergeMessage":"auto-merge: CI green"}' || true)
|
||||
echo "merge http: $HTTP_CODE"
|
||||
echo "merge resp:"; cat /tmp/merge_resp.json || true
|
||||
@@ -7,7 +7,7 @@ on:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: [macos, host]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
@@ -39,3 +39,4 @@ yarn-error.log*
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
MAIN_PLAN.md
|
||||
|
||||
@@ -6,6 +6,7 @@ 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 type { Section } from '@/lib/state/store'
|
||||
import { createFormStore, type FormState } from '@/lib/state/formStore'
|
||||
import FormBuilderPanel from '@/components/FormBuilderPanel'
|
||||
@@ -47,6 +48,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 +193,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 +217,30 @@ 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 extras = buildExtrasForPage(valid, { robotsText: robotsTextOverride, manifest: manifestOverride })
|
||||
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 +303,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/)
|
||||
})
|
||||
})
|
||||
@@ -13,7 +13,8 @@ export default function I18nProvider({
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
return (
|
||||
<NextIntlClientProvider locale={locale} messages={messages}>
|
||||
// next-intl: Provide a default timeZone to avoid ENVIRONMENT_FALLBACK mismatches
|
||||
<NextIntlClientProvider locale={locale} messages={messages} timeZone="Asia/Seoul">
|
||||
{children}
|
||||
</NextIntlClientProvider>
|
||||
)
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import '@testing-library/jest-dom'
|
||||
import React from 'react'
|
||||
import BuilderClientPage from '@/components/BuilderClientPage'
|
||||
import I18nProvider from '@/components/I18nProvider'
|
||||
import en from '@/messages/en.json'
|
||||
import { assertDescribedBy } from '@/components/testUtils/inspectorA11y'
|
||||
|
||||
describe('Inspector a11y sections template - Hero/CTA/FAQ describedby wiring', () => {
|
||||
it('Hero, CTA, FAQ inspector inputs are wired to helptexts', () => {
|
||||
render(
|
||||
<I18nProvider locale="en" messages={en as unknown as Record<string, string>}>
|
||||
<BuilderClientPage />
|
||||
</I18nProvider>
|
||||
)
|
||||
|
||||
// Add hero to enable inspector
|
||||
const addHero = screen.getByRole('button', { name: 'Add Hero' })
|
||||
fireEvent.click(addHero)
|
||||
|
||||
// Select first section (Hero)
|
||||
const selectButtons = screen.getAllByRole('button', { name: /Select \d+/ })
|
||||
fireEvent.click(selectButtons[0])
|
||||
|
||||
const heroHeading = screen.getByLabelText('Hero Heading')
|
||||
assertDescribedBy(heroHeading, 'ins-hero-heading-help')
|
||||
|
||||
// Replace with CTA and test describedby
|
||||
const addCta = screen.getByRole('button', { name: 'Add CTA' })
|
||||
fireEvent.click(addCta)
|
||||
const selectSecond = screen.getAllByRole('button', { name: /Select \d+/ })[1]
|
||||
fireEvent.click(selectSecond)
|
||||
|
||||
const ctaText = screen.getByLabelText('CTA Text')
|
||||
assertDescribedBy(ctaText, 'ins-cta-text-help')
|
||||
const ctaHref = screen.getByLabelText('CTA Href')
|
||||
assertDescribedBy(ctaHref, 'ins-cta-href-help')
|
||||
|
||||
// Add FAQ and test using shared help id
|
||||
const addFaq = screen.getByRole('button', { name: 'Add FAQ' })
|
||||
fireEvent.click(addFaq)
|
||||
const selectThird = screen.getAllByRole('button', { name: /Select \d+/ })[2]
|
||||
fireEvent.click(selectThird)
|
||||
// Add one FAQ item to render inputs
|
||||
const addFaqItem = screen.getByRole('button', { name: 'Add FAQ Item' })
|
||||
fireEvent.click(addFaqItem)
|
||||
|
||||
const faqQ = screen.getByLabelText('FAQ Q 0')
|
||||
const faqA = screen.getByLabelText('FAQ A 0')
|
||||
assertDescribedBy(faqQ, 'ins-faq-help')
|
||||
assertDescribedBy(faqA, 'ins-faq-help')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,29 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import '@testing-library/jest-dom'
|
||||
import React from 'react'
|
||||
import BuilderClientPage from '@/components/BuilderClientPage'
|
||||
import I18nProvider from '@/components/I18nProvider'
|
||||
import en from '@/messages/en.json'
|
||||
import { assertDescribedBy } from '@/components/testUtils/inspectorA11y'
|
||||
|
||||
describe('Inspector a11y template - describedby wiring', () => {
|
||||
it('SEO/Analytics inputs are wired to their helptexts via aria-describedby', () => {
|
||||
render(
|
||||
<I18nProvider locale="en" messages={en as unknown as Record<string, string>}>
|
||||
<BuilderClientPage />
|
||||
</I18nProvider>
|
||||
)
|
||||
|
||||
const seoTitle = screen.getByLabelText('SEO Title')
|
||||
const seoDesc = screen.getByLabelText('SEO Description')
|
||||
const ogImage = screen.getByLabelText('OG Image URL')
|
||||
const ga4 = screen.getByLabelText('GA4 Measurement ID')
|
||||
const meta = screen.getByLabelText('Meta Pixel ID')
|
||||
|
||||
assertDescribedBy(seoTitle, 'ins-seo-title-help')
|
||||
assertDescribedBy(seoDesc, 'ins-seo-desc-help')
|
||||
assertDescribedBy(ogImage, 'ins-og-image-help')
|
||||
assertDescribedBy(ga4, 'ins-ga4-help')
|
||||
assertDescribedBy(meta, 'ins-meta-pixel-help')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,28 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import '@testing-library/jest-dom'
|
||||
import React from 'react'
|
||||
import BuilderClientPage from '@/components/BuilderClientPage'
|
||||
import I18nProvider from '@/components/I18nProvider'
|
||||
import en from '@/messages/en.json'
|
||||
|
||||
describe('Buttons naming/aria-label consistency (smoke)', () => {
|
||||
it('renders primary action buttons with stable accessible names', () => {
|
||||
render(
|
||||
<I18nProvider locale="en" messages={en as unknown as Record<string, string>}>
|
||||
<BuilderClientPage />
|
||||
</I18nProvider>
|
||||
)
|
||||
|
||||
// Sidebar/toolbar actions
|
||||
expect(screen.getByRole('button', { name: 'Add Hero' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Add FAQ' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Add CTA' })).toBeInTheDocument()
|
||||
|
||||
// Export button
|
||||
expect(screen.getByRole('button', { name: 'Export ZIP' })).toBeInTheDocument()
|
||||
|
||||
// Preview viewport toggle buttons have explicit aria-labels as names
|
||||
expect(screen.getByRole('button', { name: 'Desktop' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Mobile' })).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,42 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import '@testing-library/jest-dom'
|
||||
import React from 'react'
|
||||
import BuilderClientPage from '@/components/BuilderClientPage'
|
||||
import I18nProvider from '@/components/I18nProvider'
|
||||
import en from '@/messages/en.json'
|
||||
import ko from '@/messages/ko.json'
|
||||
|
||||
describe('i18n regression - form add actions (en/ko)', () => {
|
||||
function renderWith(locale: 'en' | 'ko') {
|
||||
const messages = locale === 'en' ? en : ko
|
||||
return render(
|
||||
<I18nProvider locale={locale} messages={messages as unknown as Record<string, string>}>
|
||||
<BuilderClientPage />
|
||||
</I18nProvider>
|
||||
)
|
||||
}
|
||||
|
||||
it('en labels exist for form field add buttons', () => {
|
||||
renderWith('en')
|
||||
expect(screen.getByRole('button', { name: 'Add Text' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Add Email' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Add Tel' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Add Date' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Add Textarea' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Add Checkbox' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Add Select' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Add Radio' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('ko labels exist for form field add buttons', () => {
|
||||
renderWith('ko')
|
||||
expect(screen.getByRole('button', { name: '텍스트 필드 추가' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: '이메일 필드 추가' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: '전화번호 필드 추가' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: '날짜 필드 추가' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: '텍스트영역 추가' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: '체크박스 추가' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: '셀렉트 추가' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: '라디오 추가' })).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,32 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import '@testing-library/jest-dom'
|
||||
import React from 'react'
|
||||
import BuilderClientPage from '@/components/BuilderClientPage'
|
||||
import I18nProvider from '@/components/I18nProvider'
|
||||
import en from '@/messages/en.json'
|
||||
import ko from '@/messages/ko.json'
|
||||
|
||||
describe('i18n regression - misc labels (title/preview/sections)', () => {
|
||||
function renderWith(locale: 'en' | 'ko') {
|
||||
const messages = locale === 'en' ? en : ko
|
||||
return render(
|
||||
<I18nProvider locale={locale} messages={messages as unknown as Record<string, string>}>
|
||||
<BuilderClientPage />
|
||||
</I18nProvider>
|
||||
)
|
||||
}
|
||||
|
||||
it('en: builder title, preview text, sections heading present', () => {
|
||||
renderWith('en')
|
||||
expect(screen.getByRole('heading', { name: 'Landing Page Builder' })).toBeInTheDocument()
|
||||
expect(screen.getByText('Preview (static)')).toBeInTheDocument()
|
||||
expect(screen.getByText('Sections')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('ko: builder title, preview text, sections heading present', () => {
|
||||
renderWith('ko')
|
||||
expect(screen.getByRole('heading', { name: '랜딩 페이지 빌더' })).toBeInTheDocument()
|
||||
expect(screen.getByText('미리보기(정적)')).toBeInTheDocument()
|
||||
expect(screen.getByText('섹션')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,62 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import '@testing-library/jest-dom'
|
||||
import React from 'react'
|
||||
import BuilderClientPage from '@/components/BuilderClientPage'
|
||||
import I18nProvider from '@/components/I18nProvider'
|
||||
import en from '@/messages/en.json'
|
||||
import ko from '@/messages/ko.json'
|
||||
|
||||
function renderWith(locale: 'en' | 'ko') {
|
||||
const messages = locale === 'en' ? en : ko
|
||||
return render(
|
||||
<I18nProvider locale={locale} messages={messages as unknown as Record<string, string>}>
|
||||
<BuilderClientPage />
|
||||
</I18nProvider>
|
||||
)
|
||||
}
|
||||
|
||||
describe('i18n regression - key presence on main UI', () => {
|
||||
it('en: shows expected labels and buttons', () => {
|
||||
renderWith('en')
|
||||
expect(screen.getByRole('heading', { name: 'Landing Page Builder' })).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Title')).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Locale')).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Primary Color')).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Font Family')).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Export ZIP' })).toBeInTheDocument()
|
||||
// form actions
|
||||
expect(screen.getByRole('button', { name: 'Add Text' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Add Email' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Add Tel' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Add Date' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Add Textarea' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Add Checkbox' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Add Select' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Add Radio' })).toBeInTheDocument()
|
||||
// preview
|
||||
expect(screen.getByRole('button', { name: 'Desktop' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Mobile' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('ko: shows expected labels and buttons', () => {
|
||||
renderWith('ko')
|
||||
expect(screen.getByRole('heading', { name: '랜딩 페이지 빌더' })).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('제목')).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('로케일')).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('대표 색상')).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('폰트')).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'ZIP 내보내기' })).toBeInTheDocument()
|
||||
// form actions
|
||||
expect(screen.getByRole('button', { name: '텍스트 필드 추가' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: '이메일 필드 추가' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: '전화번호 필드 추가' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: '날짜 필드 추가' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: '텍스트영역 추가' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: '체크박스 추가' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: '셀렉트 추가' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: '라디오 추가' })).toBeInTheDocument()
|
||||
// preview
|
||||
expect(screen.getByRole('button', { name: 'Desktop' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Mobile' })).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,32 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import '@testing-library/jest-dom'
|
||||
import React from 'react'
|
||||
import BuilderClientPage from '@/components/BuilderClientPage'
|
||||
import I18nProvider from '@/components/I18nProvider'
|
||||
import en from '@/messages/en.json'
|
||||
import ko from '@/messages/ko.json'
|
||||
|
||||
describe('i18n regression - sidebar add actions (en/ko)', () => {
|
||||
function renderWith(locale: 'en' | 'ko') {
|
||||
const messages = locale === 'en' ? en : ko
|
||||
return render(
|
||||
<I18nProvider locale={locale} messages={messages as unknown as Record<string, string>}>
|
||||
<BuilderClientPage />
|
||||
</I18nProvider>
|
||||
)
|
||||
}
|
||||
|
||||
it('en labels exist', () => {
|
||||
renderWith('en')
|
||||
expect(screen.getByRole('button', { name: 'Add Hero' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Add FAQ' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Add CTA' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('ko labels exist', () => {
|
||||
renderWith('ko')
|
||||
expect(screen.getByRole('button', { name: '히어로 추가' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'FAQ 추가' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'CTA 추가' })).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,31 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import '@testing-library/jest-dom'
|
||||
import React from 'react'
|
||||
import BuilderClientPage from '@/components/BuilderClientPage'
|
||||
import I18nProvider from '@/components/I18nProvider'
|
||||
import en from '@/messages/en.json'
|
||||
|
||||
describe('Preview viewport toggle ARIA regression', () => {
|
||||
it('Desktop/Mobile buttons expose stable ARIA attributes', () => {
|
||||
render(
|
||||
<I18nProvider locale="en" messages={en as unknown as Record<string, string>}>
|
||||
<BuilderClientPage />
|
||||
</I18nProvider>
|
||||
)
|
||||
|
||||
const desktop = screen.getByRole('button', { name: 'Desktop' })
|
||||
const mobile = screen.getByRole('button', { name: 'Mobile' })
|
||||
|
||||
// describedby shared help
|
||||
expect(desktop).toHaveAttribute('aria-describedby', 'preview-toggle-help')
|
||||
expect(mobile).toHaveAttribute('aria-describedby', 'preview-toggle-help')
|
||||
|
||||
// controls preview container
|
||||
expect(desktop).toHaveAttribute('aria-controls', 'preview-container')
|
||||
expect(mobile).toHaveAttribute('aria-controls', 'preview-container')
|
||||
|
||||
// default pressed state: Desktop true, Mobile false
|
||||
expect(desktop).toHaveAttribute('aria-pressed', 'true')
|
||||
expect(mobile).toHaveAttribute('aria-pressed', 'false')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,8 @@
|
||||
// Inspector a11y helper: verify input ↔ helptext wiring via aria-describedby
|
||||
import { expect } from 'vitest'
|
||||
|
||||
export function assertDescribedBy(input: HTMLElement, helpId: string) {
|
||||
expect(input).toHaveAttribute('aria-describedby', helpId)
|
||||
const help = (input.ownerDocument || document).getElementById(helpId)
|
||||
expect(help).not.toBeNull()
|
||||
}
|
||||
@@ -41,7 +41,7 @@ describe('Exporter a11y/responsive enhancements', () => {
|
||||
test('hero image alt derives from heading', () => {
|
||||
const out = exportPage(makePage())
|
||||
expect(out.html).toContain('<h1 id="hero-heading">Welcome</h1>')
|
||||
expect(out.html).toContain('<img src="https://example.com/img.png" alt="Welcome" />')
|
||||
expect(out.html).toMatch(/<img[^>]*src="https:\/\/example\.com\/img\.png"[^>]*alt="Welcome"[^>]*\/>/)
|
||||
})
|
||||
|
||||
test('responsive and a11y CSS tokens exist', () => {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
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: 'CSS Tokens Expand',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#0ea5e9', fontFamily: 'Inter' },
|
||||
sections: [],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
seo: { title: 'SEO', description: 'Desc' },
|
||||
})
|
||||
}
|
||||
|
||||
describe('Exporter CSS tokens - expanded regression', () => {
|
||||
it('includes root var, skip-link base/focus, focus outline, reduced-motion, body font', () => {
|
||||
const out = exportPage(makePage())
|
||||
const css = out.css
|
||||
|
||||
// :root primary color var
|
||||
expect(css).toMatch(/:root\{\s*--primary:\s*#0ea5e9\s*;\s*\}/)
|
||||
|
||||
// body font family includes configured font first
|
||||
expect(css).toMatch(/body\{[^}]*font-family:\s*Inter,\s*system-ui[\s\S]*\}/)
|
||||
|
||||
// skip-link base and focus tokens
|
||||
expect(css).toMatch(/a\.skip-link\{[\s\S]*left:-9999px[\s\S]*\}/)
|
||||
expect(css).toMatch(/a\.skip-link:focus\{[\s\S]*left:1rem[\s\S]*background:[^;]+;[\s\S]*\}/)
|
||||
|
||||
// focus-visible/outline tokens (any focusable)
|
||||
expect(css).toMatch(/button:focus, a:focus, input:focus, select:focus, textarea:focus\{[\s\S]*outline:\s*3px solid\s*#2563eb[\s\S]*outline-offset:\s*2px[\s\S]*\}/)
|
||||
|
||||
// reduced-motion detailed rule
|
||||
expect(css).toMatch(/@media \(prefers-reduced-motion: reduce\)\{\s*\*\{\s*transition:\s*none !important;\s*animation:\s*none !important\s*\}\s*\}/)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,32 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { exportPage } from '@/lib/exporter/html'
|
||||
import { pageSchema, type Page } from '@/lib/schema/page'
|
||||
|
||||
function makePage(overrides: Partial<Page> = {}): Page {
|
||||
const base: Page = {
|
||||
title: 'CTA Edge',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
||||
sections: [
|
||||
{ type: 'cta', props: { text: ' ', href: '#' } },
|
||||
{ type: 'features', props: { items: ['One'] } },
|
||||
] as Page['sections'],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
analytics: { ga4MeasurementId: '', metaPixelId: '', customHeadHtml: '' },
|
||||
seo: { title: 't', description: 'd' },
|
||||
}
|
||||
return pageSchema.parse({ ...base, ...overrides })
|
||||
}
|
||||
|
||||
describe('Exporter - CTA edge cases', () => {
|
||||
it('drops CTA section when text is whitespace-only', () => {
|
||||
const out = exportPage(makePage())
|
||||
expect(out.html).not.toContain('<section class="cta"')
|
||||
expect(out.html).not.toContain('<a class="btn-cta"')
|
||||
})
|
||||
|
||||
it('renders CTA when text is valid after trimming', () => {
|
||||
const out = exportPage(makePage({ sections: [ { type: 'cta', props: { text: ' Buy Now ', href: '#' } } ] as Page['sections'] }))
|
||||
expect(out.html).toContain('<a class="btn-cta" href="#">Buy Now</a>')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,30 @@
|
||||
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: 'Dark Contrast Hover',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
||||
sections: [
|
||||
{ type: 'hero', props: { heading: 'Welcome', subheading: 'Sub', imageUrl: 'https://img.example/h.png' } },
|
||||
{ type: 'cta', props: { text: 'Call', href: '#' } },
|
||||
],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
seo: { title: 't', description: 'd' },
|
||||
})
|
||||
}
|
||||
|
||||
describe('Exporter - dark mode hover/cta tokens', () => {
|
||||
it('adds link hover underline and ensures btn-cta readable in dark', () => {
|
||||
const out = exportPage(makePage())
|
||||
const css = out.css
|
||||
|
||||
// underline on hover for links in dark for clearer affordance
|
||||
expect(css).toMatch(/@media \(prefers-color-scheme: dark\)[\s\S]*a:hover\{[^}]*text-decoration:underline/i)
|
||||
|
||||
// btn-cta has readable foreground/background in dark
|
||||
expect(css).toMatch(/@media \(prefers-color-scheme: dark\)[\s\S]*\.btn-cta\{[^}]*background:[^;]+;[^}]*color:#fff/i)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,37 @@
|
||||
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: 'Dark Contrast',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
||||
sections: [
|
||||
{ type: 'hero', props: { heading: 'Welcome', subheading: 'Sub', imageUrl: 'https://img.example/h.png' } },
|
||||
{ type: 'faq', props: { items: [{ q: 'Q', a: 'A' }] } },
|
||||
{ type: 'cta', props: { text: 'Go', href: '#' } },
|
||||
],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
seo: { title: 't', description: 'd' },
|
||||
})
|
||||
}
|
||||
|
||||
describe('Exporter - dark mode contrast tokens', () => {
|
||||
it('includes dark mode tokens that improve contrast for links/buttons/faq text', () => {
|
||||
const out = exportPage(makePage())
|
||||
const css = out.css
|
||||
|
||||
// dark mode block exists
|
||||
expect(css).toMatch(/@media \(prefers-color-scheme: dark\)/)
|
||||
|
||||
// link color token in dark
|
||||
expect(css).toMatch(/@media \(prefers-color-scheme: dark\)[\s\S]*a\{[^}]*color:#93c5fd/i)
|
||||
|
||||
// button keeps readable foreground/background in dark
|
||||
expect(css).toMatch(/@media \(prefers-color-scheme: dark\)[\s\S]*button\{[^}]*background:[^;]+;[^}]*color:#fff/i)
|
||||
|
||||
// faq answer text brighter in dark
|
||||
expect(css).toMatch(/@media \(prefers-color-scheme: dark\)[\s\S]*\.faq-a\{[^}]*color:#cbd5e1/i)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,45 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { pageSchema, type Page } from '@/lib/schema/page'
|
||||
import { buildExtrasForPage } from '@/lib/exporter/extras'
|
||||
|
||||
function makePage(): Page {
|
||||
return pageSchema.parse({
|
||||
title: 'Overrides',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
||||
sections: [ { type: 'hero', props: { heading: 'Hello', subheading: 'World', imageUrl: 'https://img/h.png' } } ],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
seo: { title: 't', description: 'd' },
|
||||
})
|
||||
}
|
||||
|
||||
describe('extras 오버라이드', () => {
|
||||
it('robots.txt Disallow 오버라이드가 반영된다', () => {
|
||||
const page = makePage()
|
||||
const extras = buildExtrasForPage(page, { robotsText: 'User-agent: *\nDisallow: /admin\nDisallow: /private' })
|
||||
const robots = Buffer.from(extras['robots.txt']).toString('utf8')
|
||||
expect(robots).toContain('User-agent: *')
|
||||
expect(robots).toContain('Disallow: /admin')
|
||||
expect(robots).toContain('Disallow: /private')
|
||||
})
|
||||
|
||||
it('manifest 필드 오버라이드(name/short_name/start_url/display/theme_color)가 반영된다', () => {
|
||||
const page = makePage()
|
||||
const extras = buildExtrasForPage(page, {
|
||||
manifest: {
|
||||
name: 'My App',
|
||||
short_name: 'MyApp',
|
||||
start_url: '/start',
|
||||
display: 'minimal-ui',
|
||||
theme_color: '#123abc',
|
||||
},
|
||||
})
|
||||
const manifestStr = Buffer.from(extras['site.webmanifest']).toString('utf8')
|
||||
const manifest = JSON.parse(manifestStr)
|
||||
expect(manifest.name).toBe('My App')
|
||||
expect(manifest.short_name).toBe('MyApp')
|
||||
expect(manifest.start_url).toBe('/start')
|
||||
expect(manifest.display).toBe('minimal-ui')
|
||||
expect(manifest.theme_color).toBe('#123abc')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,64 @@
|
||||
import type { Page } from '@/lib/schema/page'
|
||||
|
||||
export type ExtrasOverrides = {
|
||||
robotsText?: string
|
||||
manifest?: Partial<{
|
||||
name: string
|
||||
short_name: string
|
||||
start_url: string
|
||||
display: string
|
||||
theme_color: string
|
||||
}>
|
||||
}
|
||||
|
||||
function toBytes(s: string): Uint8Array {
|
||||
return new TextEncoder().encode(s)
|
||||
}
|
||||
|
||||
function buildRobots(base?: string): string {
|
||||
if (base && base.trim().length > 0) return base
|
||||
return 'User-agent: *\n'
|
||||
}
|
||||
|
||||
function deriveManifest(page: Page) {
|
||||
const name = page.title || 'Landing'
|
||||
const short_name = name.length > 12 ? name.slice(0, 12) : name
|
||||
const start_url = '/'
|
||||
const display = 'standalone'
|
||||
const theme_color = page.theme?.primaryColor || '#0ea5e9'
|
||||
return { name, short_name, start_url, display, theme_color }
|
||||
}
|
||||
|
||||
export function buildExtrasForPage(page: Page, overrides?: ExtrasOverrides): Record<string, Uint8Array> {
|
||||
const out: Record<string, Uint8Array> = {}
|
||||
|
||||
// robots.txt
|
||||
const robotsText = buildRobots(overrides?.robotsText)
|
||||
out['robots.txt'] = toBytes(robotsText)
|
||||
|
||||
// site.webmanifest
|
||||
const manifestBase = deriveManifest(page)
|
||||
const manifestMerged = { ...manifestBase, ...(overrides?.manifest || {}) }
|
||||
const manifestJson = JSON.stringify(manifestMerged, null, 2)
|
||||
out['site.webmanifest'] = toBytes(manifestJson)
|
||||
|
||||
// Google Sheets 템플릿: actionUrl 미지정 시 포함
|
||||
const action = page.form?.actionUrl?.trim()
|
||||
const hasAction = !!(action && action.length > 0)
|
||||
if (!hasAction) {
|
||||
const code = `/**
|
||||
* Google Apps Script Web App for form submissions
|
||||
* - Deploy as Web App and set URL as form action if needed.
|
||||
*/
|
||||
function doPost(e){
|
||||
// TODO: handle submission to Google Sheets
|
||||
return ContentService.createTextOutput('OK')
|
||||
}
|
||||
`
|
||||
const readme = `Google Sheets Apps Script Template\n\n1) Apps Script에서 새 프로젝트를 만들고 아래 Code.gs를 붙여넣으세요.\n2) 배포 > 웹 앱으로 배포 후 URL을 복사해 사용하세요.`
|
||||
out['sheets/Code.gs'] = toBytes(code)
|
||||
out['sheets/README.txt'] = toBytes(readme)
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
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: 'Font Opt',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
||||
sections: [ { type: 'hero', props: { heading: 'Hello', subheading: 'World', imageUrl: 'https://img/h.png' } } ],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
seo: { title: 't', description: 'd' },
|
||||
})
|
||||
}
|
||||
|
||||
describe('폰트 최적화', () => {
|
||||
it('head에 Google Fonts preconnect 링크가 포함된다', () => {
|
||||
const page = makePage()
|
||||
const out = exportPage(page)
|
||||
expect(out.html).toContain('<link rel="preconnect" href="https://fonts.googleapis.com"')
|
||||
expect(out.html).toContain('<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin')
|
||||
})
|
||||
|
||||
it('CSS에 system-ui 폴백이 포함된다', () => {
|
||||
const page = makePage()
|
||||
const out = exportPage(page)
|
||||
expect(out.css).toMatch(/font-family:[^;]*system-ui/i)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,75 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { pageSchema, type Page } from '@/lib/schema/page'
|
||||
import { exportPage } from '@/lib/exporter/html'
|
||||
|
||||
const makePage = (): Page =>
|
||||
pageSchema.parse({
|
||||
title: 'Form Help A11y',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#0ea5e9', fontFamily: 'Inter' },
|
||||
sections: [],
|
||||
form: {
|
||||
actionUrl: '',
|
||||
fields: [
|
||||
{ type: 'text', name: 'name', label: 'Name', required: true, help: 'Your full name' },
|
||||
{ type: 'email', name: 'email', label: 'Email', required: true },
|
||||
{ type: 'select', name: 'plan', label: 'Plan', required: false, options: ['A','B'], help: 'Choose your plan' },
|
||||
{ type: 'radio', name: 'size', label: 'Size', required: false, options: ['S','M','L'], help: 'Pick one size' },
|
||||
{ type: 'checkbox', name: 'agree', label: 'Agree', required: true, help: 'You must agree to proceed' },
|
||||
{ type: 'textarea', name: 'msg', label: 'Message', required: false },
|
||||
],
|
||||
spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 },
|
||||
},
|
||||
seo: { title: 'Form Help A11y', description: 'desc' },
|
||||
})
|
||||
|
||||
/**
|
||||
* Requirements (a11y):
|
||||
* - Each control has an id `field-<name>` and its label has htmlFor pointing to it.
|
||||
* - If field.help exists:
|
||||
* - Render help element with id `field-<name>-help` containing help text.
|
||||
* - Control has `aria-describedby` referencing the help id.
|
||||
* - For radio group, set aria-describedby on the fieldset instead of individual radios.
|
||||
*/
|
||||
|
||||
describe('Exporter - form helptext and aria-describedby', () => {
|
||||
it('renders id/htmlFor and help + aria-describedby wiring', () => {
|
||||
const page = makePage()
|
||||
const out = exportPage(page)
|
||||
const html = out.html
|
||||
|
||||
// text with help
|
||||
expect(html).toContain('id="field-name"')
|
||||
expect(html).toContain('<label for="field-name">Name')
|
||||
expect(html).toContain('id="field-name-help"')
|
||||
expect(html).toContain('Your full name')
|
||||
expect(html).toContain('aria-describedby="field-name-help"')
|
||||
|
||||
// email without help → no aria-describedby
|
||||
expect(html).toContain('id="field-email"')
|
||||
expect(html).toContain('<label for="field-email">Email')
|
||||
expect(html).not.toContain('field-email-help')
|
||||
|
||||
// select with help
|
||||
expect(html).toContain('id="field-plan"')
|
||||
expect(html).toContain('<label for="field-plan">Plan')
|
||||
expect(html).toContain('id="field-plan-help"')
|
||||
expect(html).toContain('Choose your plan')
|
||||
|
||||
// radio group help → fieldset has aria-describedby
|
||||
expect(html).toContain('<fieldset')
|
||||
expect(html).toContain('aria-describedby="field-size-help"')
|
||||
expect(html).toContain('id="field-size-help"')
|
||||
expect(html).toContain('Pick one size')
|
||||
|
||||
// checkbox with help
|
||||
expect(html).toContain('id="field-agree"')
|
||||
expect(html).toContain('<label for="field-agree">')
|
||||
expect(html).toContain('id="field-agree-help"')
|
||||
expect(html).toContain('You must agree to proceed')
|
||||
|
||||
// textarea without help
|
||||
expect(html).toContain('id="field-msg"')
|
||||
expect(html).toContain('<label for="field-msg">Message')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,66 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { pageSchema, type Page } from '@/lib/schema/page'
|
||||
import { exportPage } from '@/lib/exporter/html'
|
||||
|
||||
function makePage(fields: Page['form']['fields']): Page {
|
||||
return pageSchema.parse({
|
||||
title: 'Matrix',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#0ea5e9', fontFamily: 'Inter' },
|
||||
sections: [],
|
||||
form: {
|
||||
actionUrl: '',
|
||||
fields,
|
||||
spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 },
|
||||
},
|
||||
seo: { title: 'SEO', description: 'Desc' },
|
||||
})
|
||||
}
|
||||
|
||||
describe('Exporter - form helptext matrix (required/maxLength/pattern/help)', () => {
|
||||
it('text: required + maxLength + help → has required, maxlength, help id and aria-describedby', () => {
|
||||
const page = makePage([
|
||||
{ type: 'text', name: 'nick', label: 'Nickname', required: true, maxLength: 10, help: 'Public name' },
|
||||
])
|
||||
const html = exportPage(page).html
|
||||
expect(html).toContain('id="field-nick"')
|
||||
expect(html).toMatch(/name="nick"[^"]*[^>]*required/)
|
||||
expect(html).toMatch(/name="nick"[^"]*[^>]*maxlength="10"/)
|
||||
expect(html).toContain('id="field-nick-help"')
|
||||
expect(html).toContain('aria-describedby="field-nick-help"')
|
||||
})
|
||||
|
||||
it('tel: pattern only, no help → has pattern, no aria-describedby', () => {
|
||||
const page = makePage([
|
||||
{ type: 'tel', name: 'phone', label: 'Phone', required: false, pattern: '^\\+?[0-9\\- ]{7,}$' },
|
||||
])
|
||||
const html = exportPage(page).html
|
||||
expect(html).toMatch(/name="phone"[^"]*[^>]*pattern="\^\\\+\?\[0-9\\\- \]\{7,\}\$"/)
|
||||
expect(html).not.toContain('field-phone-help')
|
||||
// ensure no false aria-describedby
|
||||
expect(html).not.toMatch(/name="phone"[^"]*[^>]*aria-describedby=/)
|
||||
})
|
||||
|
||||
it('select: help present → select has aria-describedby and help element exists', () => {
|
||||
const page = makePage([
|
||||
{ type: 'select', name: 'plan', label: 'Plan', required: false, options: ['Free','Pro'], help: 'Choose one' },
|
||||
])
|
||||
const html = exportPage(page).html
|
||||
expect(html).toContain('id="field-plan"')
|
||||
expect(html).toContain('aria-describedby="field-plan-help"')
|
||||
expect(html).toContain('id="field-plan-help"')
|
||||
})
|
||||
|
||||
it('radio: help present → fieldset has aria-describedby; radios do not individually', () => {
|
||||
const page = makePage([
|
||||
{ type: 'radio', name: 'size', label: 'Size', required: false, options: ['S','M'], help: 'Pick one' },
|
||||
])
|
||||
const html = exportPage(page).html
|
||||
// fieldset wiring
|
||||
expect(html).toContain('<fieldset')
|
||||
expect(html).toContain('aria-describedby="field-size-help"')
|
||||
expect(html).toContain('id="field-size-help"')
|
||||
// radios present
|
||||
expect(html).toContain('type="radio"')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,67 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { pageSchema, type Page } from '@/lib/schema/page'
|
||||
import { exportPage } from '@/lib/exporter/html'
|
||||
|
||||
const makePage = (): Page =>
|
||||
pageSchema.parse({
|
||||
title: 'Form Help Snapshot',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#0ea5e9', fontFamily: 'Inter' },
|
||||
sections: [],
|
||||
form: {
|
||||
actionUrl: '',
|
||||
fields: [
|
||||
{ type: 'text', name: 'name', label: 'Name', required: true, help: 'Your full name' },
|
||||
{ type: 'email', name: 'email', label: 'Email', required: true },
|
||||
{ type: 'radio', name: 'size', label: 'Size', options: ['S','M'], help: 'Pick one size' },
|
||||
{ type: 'select', name: 'plan', label: 'Plan', options: ['Free','Pro'], help: 'Choose plan' },
|
||||
{ type: 'checkbox', name: 'agree', label: 'Agree', required: true, help: 'Must agree' },
|
||||
],
|
||||
spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 },
|
||||
},
|
||||
seo: { title: 'SEO', description: 'Desc' },
|
||||
})
|
||||
|
||||
function extractForm(html: string): string {
|
||||
const m = html.match(/<form[\s\S]*?<\/form>/)
|
||||
return m ? m[0]
|
||||
// normalize whitespace for snapshot stability
|
||||
.replace(/\s+\n/g, '\n')
|
||||
.replace(/\n\s+/g, '\n')
|
||||
.trim()
|
||||
: ''
|
||||
}
|
||||
|
||||
describe('Exporter - form helptext snapshot', () => {
|
||||
it('contains stable wiring for ids/labels/help/aria', () => {
|
||||
const out = exportPage(makePage())
|
||||
const form = extractForm(out.html)
|
||||
|
||||
// name with help
|
||||
expect(form).toContain('id="field-name"')
|
||||
expect(form).toContain('<label for="field-name">Name')
|
||||
expect(form).toContain('id="field-name-help"')
|
||||
expect(form).toContain('aria-describedby="field-name-help"')
|
||||
|
||||
// email present (no help)
|
||||
expect(form).toContain('id="field-email"')
|
||||
expect(form).toContain('<label for="field-email">Email')
|
||||
expect(form).not.toContain('field-email-help')
|
||||
|
||||
// radio group help on fieldset
|
||||
expect(form).toContain('<fieldset')
|
||||
expect(form).toContain('aria-describedby="field-size-help"')
|
||||
expect(form).toContain('id="field-size-help"')
|
||||
expect(form).toContain('type="radio"')
|
||||
|
||||
// select with help
|
||||
expect(form).toContain('id="field-plan"')
|
||||
expect(form).toContain('aria-describedby="field-plan-help"')
|
||||
expect(form).toContain('id="field-plan-help"')
|
||||
|
||||
// checkbox with help
|
||||
expect(form).toContain('id="field-agree"')
|
||||
expect(form).toContain('aria-describedby="field-agree-help"')
|
||||
expect(form).toContain('id="field-agree-help"')
|
||||
})
|
||||
})
|
||||
@@ -37,7 +37,8 @@ describe('Exporter - form rendering', () => {
|
||||
// select/radio 옵션 존재
|
||||
expect(out.html).toContain('<select')
|
||||
expect(out.html).toContain('<option value="A">A</option>')
|
||||
expect(out.html).toContain('<input type="radio"')
|
||||
// 라디오 인풋은 id 속성이 먼저 오므로 type만으로 확인
|
||||
expect(out.html).toContain('type="radio"')
|
||||
|
||||
// checkbox/textarea
|
||||
expect(out.html).toContain('type="checkbox"')
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { describe, test, expect } from 'vitest'
|
||||
import { pageSchema, type Page } from '@/lib/schema/page'
|
||||
import { exportPage } from '@/lib/exporter/html'
|
||||
|
||||
const makePage = (): Page =>
|
||||
pageSchema.parse({
|
||||
title: 'Form Tokens Regression',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#0ea5e9', fontFamily: 'Inter' },
|
||||
sections: [],
|
||||
form: {
|
||||
actionUrl: '',
|
||||
fields: [
|
||||
{ type: 'text', name: 'fullName', label: 'Full Name', required: true, maxLength: 50 },
|
||||
{ type: 'email', name: 'email', label: 'Email', required: true },
|
||||
{ type: 'tel', name: 'phone', label: 'Phone', pattern: '^\\+?[0-9\\- ]{7,}$' },
|
||||
{ type: 'radio', name: 'size', label: 'Size', options: ['S','M','L'] },
|
||||
{ type: 'select', name: 'plan', label: 'Plan', options: ['Free','Pro'] },
|
||||
{ type: 'checkbox', name: 'agree', label: 'Agree to terms', required: true },
|
||||
{ type: 'textarea', name: 'message', label: 'Message' },
|
||||
],
|
||||
spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 },
|
||||
},
|
||||
seo: { title: 'SEO', description: 'Desc' },
|
||||
analytics: { ga4MeasurementId: '', metaPixelId: '', customHeadHtml: '' },
|
||||
})
|
||||
|
||||
describe('Exporter - form tokens regression', () => {
|
||||
test('renders inputs with required/pattern/maxLength and spam-protection markers', () => {
|
||||
const { html, js } = exportPage(makePage())
|
||||
|
||||
// required + maxlength on text
|
||||
expect(html).toMatch(/name="fullName"[^"]*[^>]*required/)
|
||||
expect(html).toMatch(/name="fullName"[^"]*[^>]*maxlength="50"/)
|
||||
|
||||
// email required
|
||||
expect(html).toMatch(/name="email"[^"]*[^>]*required/)
|
||||
|
||||
// tel pattern
|
||||
expect(html).toMatch(/name="phone"[^"]*[^>]*pattern="\^\\\+\?\[0-9\\\- \]\{7,\}\$"/)
|
||||
|
||||
// radio/select options present
|
||||
// 라디오 인풋은 id 속성이 먼저 오므로 type만으로 확인
|
||||
expect(html).toContain('type="radio"')
|
||||
expect(html).toContain('<select')
|
||||
expect(html).toContain('<option value="Free">Free</option>')
|
||||
|
||||
// checkbox/textarea
|
||||
expect(html).toContain('type="checkbox"')
|
||||
expect(html).toContain('<textarea')
|
||||
|
||||
// spam-protection hidden inputs
|
||||
expect(html).toContain('type="hidden"')
|
||||
expect(html).toContain('name="_hp"')
|
||||
expect(html).toContain('name="_ts"')
|
||||
|
||||
// js fills timestamp
|
||||
expect(js).toMatch(/querySelector\('input\[name="_ts"\]'\)/)
|
||||
})
|
||||
})
|
||||
@@ -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(overrides: Partial<Page> = {}): Page {
|
||||
const base: Page = {
|
||||
title: 'Hero Edge',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
||||
sections: [
|
||||
{ type: 'hero', props: { heading: 'Welcome', subheading: ' ', imageUrl: 'https://img.example/h.png' } },
|
||||
] as Page['sections'],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
analytics: { ga4MeasurementId: '', metaPixelId: '', customHeadHtml: '' },
|
||||
seo: { title: 't', description: 'd' },
|
||||
}
|
||||
return pageSchema.parse({ ...base, ...overrides })
|
||||
}
|
||||
|
||||
describe('Exporter - hero edge cases', () => {
|
||||
it('omits subheading when whitespace-only', () => {
|
||||
const out = exportPage(makePage())
|
||||
expect(out.html).toContain('<h1 id="hero-heading">Welcome</h1>')
|
||||
expect(out.html).not.toMatch(/<div class="text">[\s\S]*<p>\s*<\/p>/)
|
||||
})
|
||||
|
||||
it('trims subheading content', () => {
|
||||
const out = exportPage(makePage({ sections: [ { type: 'hero', props: { heading: 'Welcome', subheading: ' Hello world ', imageUrl: 'https://img.example/h.png' } } ] as Page['sections'] }))
|
||||
expect(out.html).toContain('<p>Hello world</p>')
|
||||
})
|
||||
})
|
||||
+104
-25
@@ -5,7 +5,12 @@ export type Exported = { html: string; css: string; js: string }
|
||||
export type ExportOptions = { assetManager?: AssetManager }
|
||||
|
||||
function renderFaq(section: { props: { items: Array<{ q: string; a: string }> } }) {
|
||||
const items: Array<{ q: string; a: string }> = Array.isArray(section.props.items) ? section.props.items : []
|
||||
const itemsRaw: Array<{ q: string; a: string }> = Array.isArray(section.props.items) ? section.props.items : []
|
||||
const isBlank = (s: string | undefined | null) => !s || s.trim().length === 0
|
||||
const items = itemsRaw
|
||||
.map((it) => ({ q: (it.q || '').trim(), a: (it.a || '').trim() }))
|
||||
// drop when both question and answer are blank
|
||||
.filter((it) => !(isBlank(it.q) && isBlank(it.a)))
|
||||
return `
|
||||
<section class="faq" aria-labelledby="faq-heading">
|
||||
<div class="container">
|
||||
@@ -27,7 +32,9 @@ function renderFaq(section: { props: { items: Array<{ q: string; a: string }> }
|
||||
}
|
||||
|
||||
function renderFeatures(section: { props: { items: string[] } }) {
|
||||
const items: string[] = Array.isArray(section.props?.items) ? section.props.items : []
|
||||
const items: string[] = (Array.isArray(section.props?.items) ? section.props.items : [])
|
||||
.map((s) => String(s ?? '').trim())
|
||||
.filter((s) => s.length > 0)
|
||||
return `
|
||||
<section class="features" aria-labelledby="features-heading">
|
||||
<div class="container">
|
||||
@@ -40,10 +47,29 @@ function renderFeatures(section: { props: { items: string[] } }) {
|
||||
`
|
||||
}
|
||||
|
||||
function renderBenefits(section: { props: { items: string[] } }) {
|
||||
const items: string[] = (Array.isArray(section.props?.items) ? section.props.items : [])
|
||||
.map((s) => String(s ?? '').trim())
|
||||
.filter((s) => s.length > 0)
|
||||
return `
|
||||
<section class="benefits" aria-labelledby="benefits-heading">
|
||||
<div class="container">
|
||||
<h2 id="benefits-heading">Benefits</h2>
|
||||
<ul class="benefits-list">
|
||||
${items.map((it) => `<li class="benefit-item">${escapeHtml(String(it))}</li>`).join('')}
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
`
|
||||
}
|
||||
|
||||
function renderTestimonials(section: { props: { items: Array<{ author: string; quote: string }> } }) {
|
||||
const items: Array<{ author: string; quote: string }> = Array.isArray(section.props?.items)
|
||||
const items: Array<{ author: string; quote: string }> = (Array.isArray(section.props?.items)
|
||||
? section.props.items
|
||||
: []
|
||||
: [])
|
||||
.map((it) => ({ author: (it.author || '').trim(), quote: (it.quote || '').trim() }))
|
||||
// drop when both are blank
|
||||
.filter((it) => !(it.author.length === 0 && it.quote.length === 0))
|
||||
return `
|
||||
<section class="testimonials" aria-labelledby="testimonials-heading">
|
||||
<div class="container">
|
||||
@@ -52,8 +78,8 @@ function renderTestimonials(section: { props: { items: Array<{ author: string; q
|
||||
.map(
|
||||
(it) => `
|
||||
<figure class="testimonial">
|
||||
<blockquote>“${escapeHtml(it.quote || '')}”</blockquote>
|
||||
<figcaption>— ${escapeHtml(it.author || '')}</figcaption>
|
||||
<blockquote>“${escapeHtml(it.quote)}”</blockquote>
|
||||
${it.author.length > 0 ? `<figcaption>— ${escapeHtml(it.author)}</figcaption>` : ''}
|
||||
</figure>`
|
||||
)
|
||||
.join('')}
|
||||
@@ -63,7 +89,9 @@ function renderTestimonials(section: { props: { items: Array<{ author: string; q
|
||||
}
|
||||
|
||||
function renderCta(section: { props: { text: string; href?: string } }) {
|
||||
const { text, href } = section.props
|
||||
const href = section.props.href
|
||||
const text = (section.props.text || '').trim()
|
||||
if (text.length === 0) return ''
|
||||
return `
|
||||
<section class="cta" aria-labelledby="cta-heading">
|
||||
<div class="container">
|
||||
@@ -82,7 +110,9 @@ const escapeHtml = (s: string) =>
|
||||
.replaceAll('"', '"')
|
||||
|
||||
function renderHero(section: { props: { heading: string; subheading?: string; imageUrl: string } }, opts?: ExportOptions) {
|
||||
const { heading, subheading } = section.props
|
||||
const { heading } = section.props
|
||||
const subheadingRaw = section.props.subheading
|
||||
const subheading = subheadingRaw ? subheadingRaw.trim() : ''
|
||||
const am = opts?.assetManager
|
||||
const imageUrlRaw: string = section.props.imageUrl
|
||||
const imageUrl = am ? am.rewriteUrl(imageUrlRaw) : imageUrlRaw
|
||||
@@ -91,10 +121,10 @@ function renderHero(section: { props: { heading: string; subheading?: string; im
|
||||
<div class="container">
|
||||
<div class="text">
|
||||
<h1 id="hero-heading">${escapeHtml(heading)}</h1>
|
||||
${subheading ? `<p>${escapeHtml(subheading)}</p>` : ''}
|
||||
${subheading.length > 0 ? `<p>${escapeHtml(subheading)}</p>` : ''}
|
||||
</div>
|
||||
<div class="media">
|
||||
<img src="${escapeHtml(imageUrl)}" alt="${escapeHtml(heading)}" />
|
||||
<img src="${escapeHtml(imageUrl)}" alt="${escapeHtml(heading)}" loading="lazy" decoding="async" width="1200" height="675" />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@@ -102,45 +132,74 @@ function renderHero(section: { props: { heading: string; subheading?: string; im
|
||||
}
|
||||
|
||||
function renderField(field: FormField) {
|
||||
const id = `field-${escapeHtml(field.name)}`
|
||||
const helpId = `field-${escapeHtml(field.name)}-help`
|
||||
const hasHelp = !!field.help
|
||||
const helpHtml = hasHelp ? `<div id="${helpId}" class="form-help">${escapeHtml(field.help!)}</div>` : ''
|
||||
|
||||
const pat = 'pattern' in field && field.pattern ? ` pattern="${escapeHtml(field.pattern)}"` : ''
|
||||
const max = 'maxLength' in field && field.maxLength ? ` maxlength="${field.maxLength}"` : ''
|
||||
const common = `name="${escapeHtml(field.name)}" aria-label="${escapeHtml(field.label)}" ${field.required ? 'required' : ''}${pat}${max}`
|
||||
const describedBy = hasHelp ? ` aria-describedby="${helpId}"` : ''
|
||||
const common = `id="${id}" name="${escapeHtml(field.name)}" aria-label="${escapeHtml(field.label)}" ${field.required ? 'required' : ''}${pat}${max}${describedBy}`
|
||||
|
||||
switch (field.type) {
|
||||
case 'text':
|
||||
case 'email':
|
||||
case 'tel':
|
||||
case 'date':
|
||||
return `<label>${escapeHtml(field.label)}<input type="${field.type}" ${common} /></label>`
|
||||
return `
|
||||
<div class="form-control">
|
||||
<label for="${id}">${escapeHtml(field.label)}</label>
|
||||
<input type="${field.type}" ${common} />
|
||||
${helpHtml}
|
||||
</div>
|
||||
`
|
||||
case 'textarea':
|
||||
return `<label>${escapeHtml(field.label)}<textarea ${common}></textarea></label>`
|
||||
return `
|
||||
<div class="form-control">
|
||||
<label for="${id}">${escapeHtml(field.label)}</label>
|
||||
<textarea ${common}></textarea>
|
||||
${helpHtml}
|
||||
</div>
|
||||
`
|
||||
case 'checkbox':
|
||||
return `<label><input type="checkbox" ${common} />${escapeHtml(field.label)}</label>`
|
||||
return `
|
||||
<div class="form-control">
|
||||
<label for="${id}">${escapeHtml(field.label)}</label>
|
||||
<input type="checkbox" ${common} />
|
||||
${helpHtml}
|
||||
</div>
|
||||
`
|
||||
case 'radio': {
|
||||
const { options } = field as Extract<FormField, { type: 'radio' }>
|
||||
const fsDescribed = hasHelp ? ` aria-describedby="${helpId}"` : ''
|
||||
return `
|
||||
<fieldset>
|
||||
<fieldset${fsDescribed}>
|
||||
<legend>${escapeHtml(field.label)}</legend>
|
||||
${options
|
||||
.map(
|
||||
(opt: string) =>
|
||||
`<label><input type="radio" ${common} value="${escapeHtml(
|
||||
opt
|
||||
)}" />${escapeHtml(opt)}</label>`
|
||||
(opt: string, i: number) => {
|
||||
const optId = `${id}-opt-${i}`
|
||||
return `<div><input id="${optId}" type="radio" name="${escapeHtml(field.name)}" aria-label="${escapeHtml(field.label)}" value="${escapeHtml(opt)}" ${field.required ? 'required' : ''}${pat}${max} /><label for="${optId}">${escapeHtml(opt)}</label></div>`
|
||||
}
|
||||
)
|
||||
.join('')}
|
||||
${helpHtml}
|
||||
</fieldset>
|
||||
`
|
||||
}
|
||||
case 'select': {
|
||||
const { options } = field as Extract<FormField, { type: 'select' }>
|
||||
return `
|
||||
<label>${escapeHtml(field.label)}
|
||||
<div class="form-control">
|
||||
<label for="${id}">${escapeHtml(field.label)}</label>
|
||||
<select ${common}>
|
||||
${options
|
||||
.map((opt: string) => `<option value="${escapeHtml(opt)}">${escapeHtml(opt)}</option>`)
|
||||
.join('')}
|
||||
</select>
|
||||
</label>
|
||||
${helpHtml}
|
||||
</div>
|
||||
`
|
||||
}
|
||||
default:
|
||||
@@ -194,6 +253,10 @@ function buildHead(page: Page) {
|
||||
return `
|
||||
<meta charset="utf-8" />
|
||||
<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)}" />
|
||||
@@ -218,17 +281,20 @@ function buildCss(page: Page) {
|
||||
button:focus, a:focus, input:focus, select:focus, textarea:focus{ outline: 3px solid #2563eb; outline-offset:2px }
|
||||
.faq-list{ list-style:none; padding:0; margin:0 }
|
||||
.faq-item{ margin: .75rem 0 }
|
||||
.faq-q{ font-size: 1rem; font-weight:600; }
|
||||
.faq-a{ color:#334155 }
|
||||
.faq-q{ font-size: 1rem; font-weight:600; overflow-wrap:anywhere }
|
||||
.faq-a{ color:#334155; overflow-wrap:anywhere }
|
||||
.btn-cta{ background: var(--primary); color:#fff; padding:.75rem 1rem; border-radius:.5rem; display:inline-block; text-decoration:none }
|
||||
.features{ background:#f8fafc }
|
||||
.features-list{ list-style:none; padding:0; margin:0; display:grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .75rem }
|
||||
.feature-item{ background:#fff; border:1px solid #e2e8f0; border-radius:.5rem; padding:.75rem }
|
||||
.feature-item{ background:#fff; border:1px solid #e2e8f0; border-radius:.5rem; padding:.75rem; overflow-wrap:anywhere }
|
||||
.benefits-list{ list-style:none; padding:0; margin:0 }
|
||||
.benefit-item{ overflow-wrap:anywhere }
|
||||
.testimonials{ background:#ffffff }
|
||||
.testimonial{ border-left:4px solid var(--primary); padding:.5rem 1rem; margin: .75rem 0; background:#fefefe }
|
||||
.testimonial blockquote{ margin:0; font-style:italic; color:#1f2937 }
|
||||
.testimonial blockquote{ margin:0; font-style:italic; color:#1f2937; overflow-wrap:anywhere }
|
||||
.testimonial figcaption{ color:#475569; margin-top:.25rem }
|
||||
@media (max-width: 640px){ .container{ padding: 1rem } h1{ font-size: 1.5rem } }
|
||||
@media (prefers-color-scheme: dark){ body{ color:#e5e7eb; background:#0b1020 } .feature-item{ background:#0f172a; border-color:#1f2937 } a{ color:#93c5fd } a:hover{ text-decoration:underline } button{ background: var(--primary); color:#fff } .btn-cta{ background: var(--primary); color:#fff } .faq-a{ color:#cbd5e1 } }
|
||||
@media (prefers-reduced-motion: reduce){ *{ transition: none !important; animation: none !important } }
|
||||
`
|
||||
}
|
||||
@@ -239,6 +305,17 @@ function buildJs() {
|
||||
(function(){
|
||||
var ts = document.querySelector('input[name="_ts"]');
|
||||
if(ts){ ts.value = String(Date.now()); }
|
||||
// Ensure skip-link moves focus into main for a11y
|
||||
var skip = document.querySelector('a.skip-link');
|
||||
var main = document.getElementById('main');
|
||||
if (skip && main) {
|
||||
skip.addEventListener('click', function(){
|
||||
if (!main.hasAttribute('tabindex')) {
|
||||
main.setAttribute('tabindex', '-1');
|
||||
}
|
||||
main.focus();
|
||||
});
|
||||
}
|
||||
})();
|
||||
`
|
||||
}
|
||||
@@ -250,6 +327,7 @@ export function exportPage(page: Page, opts?: ExportOptions): Exported {
|
||||
if (s.type === 'faq') return renderFaq(s)
|
||||
if (s.type === 'cta') return renderCta(s)
|
||||
if (s.type === 'features') return renderFeatures(s)
|
||||
if (s.type === 'benefits') return renderBenefits(s)
|
||||
if (s.type === 'testimonials') return renderTestimonials(s)
|
||||
return ''
|
||||
})
|
||||
@@ -261,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,32 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { pageSchema, type Page } from '@/lib/schema/page'
|
||||
import { buildExtrasForPage } from '@/lib/exporter/extras'
|
||||
|
||||
function makePage(): Page {
|
||||
return pageSchema.parse({
|
||||
title: 'Auto Extras',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
||||
sections: [ { type: 'hero', props: { heading: 'Hello', subheading: 'World', imageUrl: 'https://img/h.png' } } ],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
seo: { title: 't', description: 'd' },
|
||||
})
|
||||
}
|
||||
|
||||
describe('extras 자동 생성', () => {
|
||||
it('robots.txt와 site.webmanifest가 extras에 포함된다', () => {
|
||||
const page = makePage()
|
||||
const extras = buildExtrasForPage(page)
|
||||
const keys = Object.keys(extras)
|
||||
expect(keys).toContain('robots.txt')
|
||||
expect(keys).toContain('site.webmanifest')
|
||||
|
||||
const robots = Buffer.from(extras['robots.txt']).toString('utf8')
|
||||
expect(robots).toContain('User-agent: *')
|
||||
|
||||
const manifestStr = Buffer.from(extras['site.webmanifest']).toString('utf8')
|
||||
const manifest = JSON.parse(manifestStr)
|
||||
expect(manifest.start_url).toBeDefined()
|
||||
expect(manifest.display).toBeDefined()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,28 @@
|
||||
import { describe, it } from 'vitest'
|
||||
import { pageSchema, type Page } from '@/lib/schema/page'
|
||||
import { exportPage } from '@/lib/exporter/html'
|
||||
import { assertSectionA11y } from '@/lib/exporter/testUtils/sectionA11y'
|
||||
|
||||
function makeFullPage(): Page {
|
||||
return pageSchema.parse({
|
||||
title: 'A11y Template',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#0ea5e9', fontFamily: 'Inter' },
|
||||
sections: [
|
||||
{ type: 'hero', props: { heading: 'Welcome', subheading: '', imageUrl: 'https://via.placeholder.com/800x400' } },
|
||||
{ type: 'features', props: { items: ['A','B','C'] } },
|
||||
{ type: 'testimonials', props: { items: [{ author: 'Jane', quote: 'Great!' }] } },
|
||||
{ type: 'faq', props: { items: [{ q: 'Q1', a: 'A1' }] } },
|
||||
{ type: 'cta', props: { text: 'Get Started', href: '#' } },
|
||||
],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
seo: { title: 'SEO', description: 'Desc' },
|
||||
})
|
||||
}
|
||||
|
||||
describe('Exporter - section a11y template', () => {
|
||||
it('validates basic a11y landmarks, headings and tokens', () => {
|
||||
const out = exportPage(makeFullPage())
|
||||
assertSectionA11y(out.html)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,28 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { pageSchema, type Page } from '@/lib/schema/page'
|
||||
import { exportPage } from '@/lib/exporter/html'
|
||||
|
||||
const makePage = (): Page =>
|
||||
pageSchema.parse({
|
||||
title: 'Benefits Test',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#0ea5e9', fontFamily: 'Inter' },
|
||||
sections: [
|
||||
{ type: 'benefits', props: { items: ['Fast setup', 'No code', 'Accessible by default'] } },
|
||||
],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
seo: { title: 'SEO', description: 'Desc' },
|
||||
})
|
||||
|
||||
describe('Exporter - benefits section', () => {
|
||||
it('renders benefits as a section with h2 and aria-labelledby + list items', () => {
|
||||
const out = exportPage(makePage())
|
||||
const html = out.html
|
||||
expect(html).toContain('<section class="benefits" aria-labelledby="benefits-heading">')
|
||||
expect(html).toContain('<h2 id="benefits-heading">Benefits</h2>')
|
||||
expect(html).toContain('<ul class="benefits-list">')
|
||||
expect(html).toContain('<li class="benefit-item">Fast setup</li>')
|
||||
expect(html).toContain('<li class="benefit-item">No code</li>')
|
||||
expect(html).toContain('<li class="benefit-item">Accessible by default</li>')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,57 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { exportPage } from '@/lib/exporter/html'
|
||||
import { pageSchema, type Page } from '@/lib/schema/page'
|
||||
|
||||
function makePage(overrides: Partial<Page> = {}): Page {
|
||||
const base: Page = {
|
||||
title: 'Edge',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
||||
sections: [
|
||||
{ type: 'features', props: { items: ['One', ' ', ' ', 'Two'] } },
|
||||
{ type: 'benefits', props: { items: ['A', ' ', ' ', 'B'] } },
|
||||
{ type: 'faq', props: { items: [
|
||||
{ q: ' ', a: ' ' },
|
||||
{ q: 'Valid Q', a: ' ' },
|
||||
{ q: 'Another', a: 'Answer' },
|
||||
] } },
|
||||
{ type: 'testimonials', props: { items: [
|
||||
{ author: ' ', quote: ' ' },
|
||||
{ author: 'Jane', quote: ' Great product ' },
|
||||
] } },
|
||||
] as Page['sections'],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
analytics: { ga4MeasurementId: '', metaPixelId: '', customHeadHtml: '' },
|
||||
seo: { title: 't', description: 'd' },
|
||||
}
|
||||
return pageSchema.parse({ ...base, ...overrides })
|
||||
}
|
||||
|
||||
describe('Exporter - sections edge cases', () => {
|
||||
it('filters out whitespace-only items and keeps valid ones', () => {
|
||||
const out = exportPage(makePage())
|
||||
const html = out.html
|
||||
|
||||
// features: only One, Two
|
||||
expect(html).toContain('<li class="feature-item">One</li>')
|
||||
expect(html).toContain('<li class="feature-item">Two</li>')
|
||||
expect(html).not.toMatch(/<li class="feature-item"><\/li>/)
|
||||
|
||||
// benefits: only A, B
|
||||
expect(html).toContain('<li class="benefit-item">A</li>')
|
||||
expect(html).toContain('<li class="benefit-item">B</li>')
|
||||
|
||||
// faq: drop fully empty, keep items even if answer empty when question is valid
|
||||
expect(html).toContain('<h3 class="faq-q">Valid Q</h3>')
|
||||
// testimonials: drop fully empty, keep trimmed quote
|
||||
expect(html).toContain('<blockquote>“Great product”</blockquote>')
|
||||
})
|
||||
|
||||
it('adds word-break tokens to avoid overflow for long words', () => {
|
||||
const out = exportPage(makePage())
|
||||
const css = out.css
|
||||
expect(css).toMatch(/\.feature-item\{[\s\S]*(?:word-break:break-word|overflow-wrap:anywhere)/i)
|
||||
expect(css).toMatch(/\.benefit-item\{[\s\S]*(?:word-break:break-word|overflow-wrap:anywhere)/i)
|
||||
expect(css).toMatch(/\.testimonial blockquote\{[\s\S]*(?:word-break:break-word|overflow-wrap:anywhere)/i)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,40 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { exportPage } from '@/lib/exporter/html'
|
||||
import { pageSchema, type Page } from '@/lib/schema/page'
|
||||
|
||||
function makePage(overrides: Partial<Page> = {}): Page {
|
||||
const base: Page = {
|
||||
title: 'Edge P3',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
||||
sections: [
|
||||
{ type: 'faq', props: { items: [ { q: 'VeryVeryVeryVeryVeryLongWordWithoutSpaces', a: 'AnotherSuperLongUnbreakableWord' } ] } },
|
||||
{ type: 'testimonials', props: { items: [
|
||||
{ author: ' ', quote: 'Great!' },
|
||||
{ author: 'Alice', quote: 'Nice' },
|
||||
] } },
|
||||
] as Page['sections'],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
analytics: { ga4MeasurementId: '', metaPixelId: '', customHeadHtml: '' },
|
||||
seo: { title: 't', description: 'd' },
|
||||
}
|
||||
return pageSchema.parse({ ...base, ...overrides })
|
||||
}
|
||||
|
||||
describe('Exporter - phase3 edge cases', () => {
|
||||
it('omits testimonial author line when author is blank', () => {
|
||||
const out = exportPage(makePage())
|
||||
const html = out.html
|
||||
// First item author blank -> no figcaption for that blockquote
|
||||
expect(html).toMatch(/<blockquote>“Great!\”<\/blockquote>[\s\S]*?<\/figure>/)
|
||||
// Ensure the next item with author renders figcaption
|
||||
expect(html).toMatch(/<figcaption>— Alice<\/figcaption>/)
|
||||
})
|
||||
|
||||
it('adds word-break/overflow-wrap for FAQ q/a to avoid overflow', () => {
|
||||
const out = exportPage(makePage())
|
||||
const css = out.css
|
||||
expect(css).toMatch(/\.faq-q\{[\s\S]*(?:overflow-wrap:anywhere|word-break:break-word)/i)
|
||||
expect(css).toMatch(/\.faq-a\{[\s\S]*(?:overflow-wrap:anywhere|word-break:break-word)/i)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,33 @@
|
||||
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: 'Escape Regression',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#0ea5e9', fontFamily: 'Inter' },
|
||||
sections: [
|
||||
{ type: 'features', props: { items: ['F<&>"', 'Safe'] } },
|
||||
{ type: 'faq', props: { items: [{ q: 'Q<&>"', a: 'A<&>"' }] } },
|
||||
],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
seo: { title: 'SEO', description: 'Desc' },
|
||||
})
|
||||
}
|
||||
|
||||
describe('Exporter - HTML escape regression (Features/FAQ)', () => {
|
||||
it('escapes HTML special characters in features items', () => {
|
||||
const out = exportPage(makePage())
|
||||
const html = out.html
|
||||
// feature item should contain escaped characters < & > "
|
||||
expect(html).toContain('<li class="feature-item">F<&>"</li>')
|
||||
})
|
||||
|
||||
it('escapes HTML special characters in faq q/a', () => {
|
||||
const out = exportPage(makePage())
|
||||
const html = out.html
|
||||
expect(html).toContain('<h3 class="faq-q">Q<&>"</h3>')
|
||||
expect(html).toContain('<p class="faq-a">A<&>"</p>')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,55 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { pageSchema, type Page } from '@/lib/schema/page'
|
||||
import { exportPage } from '@/lib/exporter/html'
|
||||
|
||||
function makePage(): Page {
|
||||
return pageSchema.parse({
|
||||
title: 'Sections Regression',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#0ea5e9', fontFamily: 'Inter' },
|
||||
sections: [
|
||||
{ type: 'hero', props: { heading: 'Welcome', subheading: '', imageUrl: 'https://via.placeholder.com/800x400' } },
|
||||
{ type: 'features', props: { items: ['F1','F2'] } },
|
||||
{ type: 'benefits', props: { items: ['B1','B2','B3'] } },
|
||||
{ type: 'testimonials', props: { items: [{ author: 'Ada', quote: 'Great' }] } },
|
||||
{ type: 'faq', props: { items: [{ q: 'Q1', a: 'A1' }] } },
|
||||
{ type: 'cta', props: { text: 'Start', href: '#' } },
|
||||
],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
seo: { title: 'SEO', description: 'Desc' },
|
||||
})
|
||||
}
|
||||
|
||||
describe('Exporter - sections regression (includes benefits)', () => {
|
||||
it('renders sections with correct ARIA/heading/list structures', () => {
|
||||
const out = exportPage(makePage())
|
||||
const html = out.html
|
||||
|
||||
// hero h1
|
||||
expect(html).toMatch(/<section class="hero" aria-labelledby="hero-heading">/)
|
||||
expect(html).toMatch(/<h1 id="hero-heading">Welcome<\/h1>/)
|
||||
|
||||
// features
|
||||
expect(html).toMatch(/<section class="features" aria-labelledby="features-heading">/)
|
||||
expect(html).toMatch(/<h2 id="features-heading">Features<\/h2>/)
|
||||
expect(html).toMatch(/<ul class="features-list">[\s\S]*<li class="feature-item">F1<\/li>[\s\S]*<li class="feature-item">F2<\/li>[\s\S]*<\/ul>/)
|
||||
|
||||
// benefits
|
||||
expect(html).toMatch(/<section class="benefits" aria-labelledby="benefits-heading">/)
|
||||
expect(html).toMatch(/<h2 id="benefits-heading">Benefits<\/h2>/)
|
||||
expect(html).toMatch(/<ul class="benefits-list">[\s\S]*<li class="benefit-item">B1<\/li>[\s\S]*<li class="benefit-item">B2<\/li>[\s\S]*<li class="benefit-item">B3<\/li>[\s\S]*<\/ul>/)
|
||||
|
||||
// testimonials
|
||||
expect(html).toMatch(/<section class="testimonials" aria-labelledby="testimonials-heading">/)
|
||||
expect(html).toMatch(/<h2 id="testimonials-heading">Testimonials<\/h2>/)
|
||||
|
||||
// faq with h3
|
||||
expect(html).toMatch(/<section class="faq" aria-labelledby="faq-heading">/)
|
||||
expect(html).toMatch(/<h2 id="faq-heading">FAQ<\/h2>/)
|
||||
expect(html).toMatch(/<h3 class="faq-q">Q1<\/h3>/)
|
||||
|
||||
// cta
|
||||
expect(html).toMatch(/<section class="cta" aria-labelledby="cta-heading">/)
|
||||
expect(html).toMatch(/<h2 id="cta-heading">CTA<\/h2>/)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,35 @@
|
||||
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: 'Sections Regression CTA/Testimonials',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#0ea5e9', fontFamily: 'Inter' },
|
||||
sections: [
|
||||
{ type: 'testimonials', props: { items: [{ author: 'Linus', quote: 'Simple and fast' }] } },
|
||||
{ type: 'cta', props: { text: 'Get Started', href: '/start' } },
|
||||
],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
seo: { title: 'SEO', description: 'Desc' },
|
||||
})
|
||||
}
|
||||
|
||||
describe('Exporter - CTA and Testimonials regression', () => {
|
||||
it('renders testimonials figure/blockquote/figcaption structure', () => {
|
||||
const out = exportPage(makePage())
|
||||
const html = out.html
|
||||
expect(html).toMatch(/<section class="testimonials" aria-labelledby="testimonials-heading">/)
|
||||
expect(html).toMatch(/<h2 id="testimonials-heading">Testimonials<\/h2>/)
|
||||
expect(html).toMatch(/<figure class="testimonial">[\s\S]*<blockquote>“Simple and fast”<\/blockquote>[\s\S]*<figcaption>— Linus<\/figcaption>[\s\S]*<\/figure>/)
|
||||
})
|
||||
|
||||
it('renders CTA link with correct class and href', () => {
|
||||
const out = exportPage(makePage())
|
||||
const html = out.html
|
||||
expect(html).toMatch(/<section class="cta" aria-labelledby="cta-heading">/)
|
||||
expect(html).toMatch(/<h2 id="cta-heading">CTA<\/h2>/)
|
||||
expect(html).toMatch(/<a class="btn-cta" href="\/start">Get Started<\/a>/)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,41 @@
|
||||
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: 'Sections Regression Features/FAQ',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#0ea5e9', fontFamily: 'Inter' },
|
||||
sections: [
|
||||
{ type: 'features', props: { items: ['F1', 'F2', 'F3'] } },
|
||||
{ type: 'faq', props: { items: [{ q: 'Q1', a: 'A1' }, { q: 'Q2', a: 'A2' }] } },
|
||||
],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
seo: { title: 'SEO', description: 'Desc' },
|
||||
})
|
||||
}
|
||||
|
||||
describe('Exporter - Features/FAQ regression (structure/classes/count)', () => {
|
||||
it('renders features with list, class names, and correct item count', () => {
|
||||
const out = exportPage(makePage())
|
||||
const html = out.html
|
||||
expect(html).toMatch(/<section class="features" aria-labelledby="features-heading">/)
|
||||
expect(html).toMatch(/<h2 id="features-heading">Features<\/h2>/)
|
||||
expect(html).toMatch(/<ul class="features-list">/)
|
||||
const featureItems = html.match(/<li class="feature-item">/g) || []
|
||||
expect(featureItems.length).toBe(3)
|
||||
})
|
||||
|
||||
it('renders faq with list, h3 question class, and correct item count', () => {
|
||||
const out = exportPage(makePage())
|
||||
const html = out.html
|
||||
expect(html).toMatch(/<section class="faq" aria-labelledby="faq-heading">/)
|
||||
expect(html).toMatch(/<h2 id="faq-heading">FAQ<\/h2>/)
|
||||
expect(html).toMatch(/<ul class="faq-list">/)
|
||||
const qCount = html.match(/<h3 class="faq-q">/g) || []
|
||||
const aCount = html.match(/<p class="faq-a">/g) || []
|
||||
expect(qCount.length).toBe(2)
|
||||
expect(aCount.length).toBe(2)
|
||||
})
|
||||
})
|
||||
@@ -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,34 @@
|
||||
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',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#0ea5e9', fontFamily: 'Inter' },
|
||||
sections: [
|
||||
{ type: 'hero', props: { heading: 'Welcome', subheading: 'Sub', imageUrl: 'https://img.example/hero.png' } },
|
||||
],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
seo: { title: 'SEO', description: 'Desc' },
|
||||
})
|
||||
}
|
||||
|
||||
describe('Exporter - small SEO/Perf improvements', () => {
|
||||
it('includes canonical link and dark mode tokens; hero image lazy/async', () => {
|
||||
const out = exportPage(makePage())
|
||||
const html = out.html
|
||||
const css = out.css
|
||||
|
||||
// canonical link present in head
|
||||
expect(html).toMatch(/<link[^>]+rel="canonical"/)
|
||||
|
||||
// hero image has loading/decoding attributes
|
||||
expect(html).toMatch(/<img[^>]*loading="lazy"/)
|
||||
expect(html).toMatch(/<img[^>]*decoding="async"/)
|
||||
|
||||
// dark mode media query token exists
|
||||
expect(css).toMatch(/@media \(prefers-color-scheme: dark\)/)
|
||||
})
|
||||
})
|
||||
@@ -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')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,30 @@
|
||||
import { expect } from 'vitest'
|
||||
|
||||
export function assertSectionA11y(html: string) {
|
||||
// basic landmarks
|
||||
expect(html).toContain('<main id="main" role="main">')
|
||||
expect(html).toContain('class="skip-link"')
|
||||
|
||||
// hero h1
|
||||
expect(html).toMatch(/<h1 id="hero-heading">[\s\S]*<\/h1>/)
|
||||
|
||||
// features h2 and aria-labelledby
|
||||
expect(html).toMatch(/<h2 id="features-heading">Features<\/h2>/)
|
||||
expect(html).toMatch(/<section class="features" aria-labelledby="features-heading">/)
|
||||
|
||||
// testimonials h2 and aria-labelledby
|
||||
expect(html).toMatch(/<h2 id="testimonials-heading">Testimonials<\/h2>/)
|
||||
expect(html).toMatch(/<section class="testimonials" aria-labelledby="testimonials-heading">/)
|
||||
|
||||
// FAQ heading levels and structure
|
||||
expect(html).toMatch(/<h2 id="faq-heading">FAQ<\/h2>/)
|
||||
// at least one h3 under FAQ
|
||||
expect(html).toMatch(/<h3 class="faq-q">[\s\S]*<\/h3>/)
|
||||
|
||||
// CTA h2 & aria-labelledby
|
||||
expect(html).toMatch(/<h2 id="cta-heading">CTA<\/h2>/)
|
||||
expect(html).toMatch(/<section class="cta" aria-labelledby="cta-heading">/)
|
||||
|
||||
// focus-visible tokens (CSS)
|
||||
expect(html).toContain('outline: 3px solid')
|
||||
}
|
||||
@@ -5,6 +5,8 @@ export type BuildZipInput = {
|
||||
css: string
|
||||
js: string
|
||||
assets?: Record<string, Uint8Array>
|
||||
// root-level extra files like favicon.ico, site.webmanifest, robots.txt
|
||||
extras?: Record<string, Uint8Array>
|
||||
}
|
||||
|
||||
export async function buildZip(input: BuildZipInput): Promise<Uint8Array> {
|
||||
@@ -19,6 +21,22 @@ export async function buildZip(input: BuildZipInput): Promise<Uint8Array> {
|
||||
zip.file(path, buf as unknown as Buffer)
|
||||
}
|
||||
}
|
||||
if (input.extras) {
|
||||
// validate manifest if present
|
||||
if (Object.prototype.hasOwnProperty.call(input.extras, 'site.webmanifest')) {
|
||||
try {
|
||||
const manifestBytes = input.extras['site.webmanifest']
|
||||
const manifestStr = Buffer.from(manifestBytes).toString('utf8')
|
||||
JSON.parse(manifestStr)
|
||||
} catch {
|
||||
throw new Error('Invalid site.webmanifest JSON')
|
||||
}
|
||||
}
|
||||
for (const [path, bytes] of Object.entries(input.extras)) {
|
||||
const buf = Buffer.from(bytes)
|
||||
zip.file(path, buf as unknown as Buffer)
|
||||
}
|
||||
}
|
||||
const content = await zip.generateAsync({ type: 'uint8array' })
|
||||
return content
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import JSZip from 'jszip'
|
||||
import { exportPage } from '@/lib/exporter/html'
|
||||
import { buildZip } from '@/lib/exporter/zip'
|
||||
import { AssetManager } from '@/lib/assets/assetManager'
|
||||
import { pageSchema, type Page } from '@/lib/schema/page'
|
||||
|
||||
function makePageWithLocalAsset(): { page: Page; am: AssetManager } {
|
||||
const am = new AssetManager({ maxBytes: 1024 * 1024, allowedExts: ['png','svg','jpg','jpeg','webp'] })
|
||||
// simulate adding a local image and referencing it by original name via local: prefix
|
||||
const bytes = new Uint8Array([7,8,9])
|
||||
// add as "hero.png"
|
||||
am.add({ name: 'hero.png', type: 'image/png', bytes })
|
||||
|
||||
const base: Page = pageSchema.parse({
|
||||
title: 'Integrated ZIP',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
||||
sections: [
|
||||
{ type: 'hero', props: { heading: 'Hello', subheading: 'World', imageUrl: 'local:hero.png' } },
|
||||
{ type: 'cta', props: { text: 'Go', href: '#' } },
|
||||
],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
analytics: { ga4MeasurementId: 'G-TEST', metaPixelId: '', customHeadHtml: '' },
|
||||
seo: { title: 't', description: 'd' },
|
||||
})
|
||||
return { page: base, am }
|
||||
}
|
||||
|
||||
describe('Export ZIP 통합 검증', () => {
|
||||
it('exportPage 출력 + buildZip 결과에서 assets 경로/메타가 보존된다', async () => {
|
||||
const { page, am } = makePageWithLocalAsset()
|
||||
const out = exportPage(page, { assetManager: am })
|
||||
const assets = am.toZipStructure()
|
||||
const zipBytes = await buildZip({ html: out.html, css: out.css, js: out.js, assets })
|
||||
|
||||
const zip = await JSZip.loadAsync(zipBytes)
|
||||
const names = Object.keys(zip.files)
|
||||
// assets 파일이 존재해야 함
|
||||
const assetKey = Object.keys(assets)[0]
|
||||
expect(names).toContain(assetKey)
|
||||
|
||||
// index.html에 canonical/meta/ga4 스니펫 보존
|
||||
const html = await zip.files['index.html'].async('string')
|
||||
expect(html).toMatch(/<link rel="canonical" href="\//)
|
||||
expect(html).toMatch(/<meta name="description" content="d"/)
|
||||
expect(html).toMatch(/gtag\('config', 'G-TEST'\)/)
|
||||
|
||||
// hero 이미지가 재작성된 경로를 사용한다
|
||||
const match = html.match(/<img[^>]*src="([^"]+)"/)
|
||||
expect(match && match[1]).toBe(assetKey)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,28 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import JSZip from 'jszip'
|
||||
import { buildZip } from '@/lib/exporter/zip'
|
||||
|
||||
describe('Export ZIP 메타 보존 검증', () => {
|
||||
it('index.html의 SEO/OG/Analytics 메타가 그대로 보존된다', async () => {
|
||||
const html = `<!DOCTYPE html><html><head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="canonical" href="/" />
|
||||
<meta name="description" content="desc" />
|
||||
<meta property="og:title" content="OT" />
|
||||
<meta property="og:description" content="OD" />
|
||||
<script>window.dataLayer=[];function gtag(){dataLayer.push(arguments);}gtag('js',new Date());</script>
|
||||
</head><body>ok</body></html>`
|
||||
const css = 'body{color:#222}'
|
||||
const js = 'console.log("ok")'
|
||||
|
||||
const zipBytes = await buildZip({ html, css, js, assets: {} })
|
||||
const zip = await JSZip.loadAsync(zipBytes)
|
||||
const htmlContent = await zip.files['index.html'].async('string')
|
||||
|
||||
expect(htmlContent).toMatch(/<link rel="canonical" href="\//)
|
||||
expect(htmlContent).toMatch(/<meta name="description" content="desc"/)
|
||||
expect(htmlContent).toMatch(/<meta property="og:title" content="OT"/)
|
||||
expect(htmlContent).toMatch(/<meta property="og:description" content="OD"/)
|
||||
expect(htmlContent).toMatch(/window\.dataLayer=\[\];/)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,53 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import JSZip from 'jszip'
|
||||
import { buildZip } from '@/lib/exporter/zip'
|
||||
import type { BuildZipInput } from '@/lib/exporter/zip'
|
||||
|
||||
const TE = new TextEncoder()
|
||||
|
||||
describe('Export ZIP 검증 강화 4차: 루트 파일(favicon/manifest/robots)', () => {
|
||||
it('루트 파일들을 포함한다: favicon.ico / site.webmanifest / robots.txt', async () => {
|
||||
const manifest = {
|
||||
name: 'Landing Builder',
|
||||
short_name: 'LB',
|
||||
start_url: '/',
|
||||
display: 'standalone',
|
||||
icons: [{ src: '/favicon.png', sizes: '512x512', type: 'image/png' }],
|
||||
}
|
||||
const input: BuildZipInput = {
|
||||
html: '<!DOCTYPE html><html><head><title>a</title></head><body>ok</body></html>',
|
||||
css: 'body{color:#111}',
|
||||
js: 'console.log("ok")',
|
||||
assets: {},
|
||||
extras: {
|
||||
'favicon.ico': new Uint8Array([0, 1, 2, 3]),
|
||||
'site.webmanifest': TE.encode(JSON.stringify(manifest)),
|
||||
'robots.txt': TE.encode('User-agent: *\nDisallow:'),
|
||||
},
|
||||
}
|
||||
const zipBytes = await buildZip(input)
|
||||
|
||||
const zip = await JSZip.loadAsync(zipBytes)
|
||||
const names = Object.keys(zip.files)
|
||||
expect(names).toContain('favicon.ico')
|
||||
expect(names).toContain('site.webmanifest')
|
||||
expect(names).toContain('robots.txt')
|
||||
|
||||
const robots = await zip.files['robots.txt'].async('string')
|
||||
expect(robots).toMatch(/User-agent: \*/)
|
||||
|
||||
const parsed = JSON.parse(await zip.files['site.webmanifest'].async('string'))
|
||||
expect(parsed.name).toBe('Landing Builder')
|
||||
expect(parsed.icons[0].type).toBe('image/png')
|
||||
})
|
||||
|
||||
it('잘못된 manifest JSON이면 실패한다', async () => {
|
||||
const badInput: BuildZipInput = {
|
||||
html: '<!DOCTYPE html><html><head><title>a</title></head><body>ok</body></html>',
|
||||
css: 'body{color:#111}',
|
||||
js: 'console.log("ok")',
|
||||
extras: { 'site.webmanifest': TE.encode('{ invalid json') },
|
||||
}
|
||||
await expect(buildZip(badInput)).rejects.toThrow()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,39 @@
|
||||
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 makePage(): Page {
|
||||
return pageSchema.parse({
|
||||
title: 'ZIP Phase5',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
||||
sections: [ { type: 'hero', props: { heading: 'Hello', subheading: 'World', imageUrl: 'https://img/h.png' } } ],
|
||||
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||
seo: { title: 't', description: 'd' },
|
||||
})
|
||||
}
|
||||
|
||||
describe('ZIP 검증 Phase5', () => {
|
||||
it('robots.txt 베이스라인과 site.webmanifest JSON 파싱 검증', async () => {
|
||||
const page = makePage()
|
||||
const extras = buildExtrasForPage(page)
|
||||
|
||||
// baseline robots
|
||||
const robots = Buffer.from(extras['robots.txt']).toString('utf8')
|
||||
expect(robots).toContain('User-agent: *')
|
||||
|
||||
// manifest JSON parseable
|
||||
const manifestStr = Buffer.from(extras['site.webmanifest']).toString('utf8')
|
||||
const manifest = JSON.parse(manifestStr)
|
||||
expect(manifest && typeof manifest === 'object').toBe(true)
|
||||
expect(manifest.start_url).toBeDefined()
|
||||
expect(manifest.display).toBeDefined()
|
||||
|
||||
// ZIP build should succeed
|
||||
const out = exportPage(page)
|
||||
const zipBytes = await buildZip({ html: out.html, css: out.css, js: out.js, assets: {}, extras })
|
||||
expect(zipBytes.byteLength).toBeGreaterThan(0)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,44 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import JSZip from 'jszip'
|
||||
import { buildZip } from '@/lib/exporter/zip'
|
||||
|
||||
const TE = new TextEncoder()
|
||||
|
||||
describe('Export ZIP 검증 강화', () => {
|
||||
it('assets가 비어있을 때 index.html/styles.css/app.js만 포함한다', async () => {
|
||||
const zipBytes = await buildZip({
|
||||
html: '<!DOCTYPE html><html><head><title>a</title></head><body>ok</body></html>',
|
||||
css: 'body{color:#111}',
|
||||
js: 'console.log("ok")',
|
||||
assets: {},
|
||||
})
|
||||
const zip = await JSZip.loadAsync(zipBytes)
|
||||
const names = Object.keys(zip.files).sort()
|
||||
expect(names).toEqual(['app.js','index.html','styles.css'])
|
||||
})
|
||||
|
||||
it('assets가 있으면 모든 파일을 그대로 포함한다(서브폴더 포함)', async () => {
|
||||
const assets = {
|
||||
'assets/img/logo.png': new Uint8Array([0,1,2,3]),
|
||||
'assets/svg/icon.svg': TE.encode('<svg></svg>'),
|
||||
'assets/fonts/inter.woff2': new Uint8Array([4,5,6]),
|
||||
}
|
||||
const zipBytes = await buildZip({
|
||||
html: '<!DOCTYPE html><html><head><title>a</title></head><body>ok</body></html>',
|
||||
css: 'body{color:#111}',
|
||||
js: 'console.log("ok")',
|
||||
assets,
|
||||
})
|
||||
const zip = await JSZip.loadAsync(zipBytes)
|
||||
const names = Object.keys(zip.files)
|
||||
expect(names).toContain('index.html')
|
||||
expect(names).toContain('styles.css')
|
||||
expect(names).toContain('app.js')
|
||||
expect(names).toContain('assets/img/logo.png')
|
||||
expect(names).toContain('assets/svg/icon.svg')
|
||||
expect(names).toContain('assets/fonts/inter.woff2')
|
||||
|
||||
const logo = await zip.files['assets/img/logo.png'].async('uint8array')
|
||||
expect(Array.from(logo)).toEqual([0,1,2,3])
|
||||
})
|
||||
})
|
||||
@@ -37,6 +37,11 @@ const sectionTestimonialsSchema = z.object({
|
||||
props: z.object({ items: z.array(z.object({ author: z.string().min(1), quote: z.string().min(1) })).min(1) }),
|
||||
})
|
||||
|
||||
const sectionBenefitsSchema = z.object({
|
||||
type: z.literal('benefits'),
|
||||
props: z.object({ items: z.array(z.string().min(1)).min(1) }),
|
||||
})
|
||||
|
||||
// 확장: hero, faq, cta, features, testimonials 허용
|
||||
const sectionSchema = z.union([
|
||||
sectionHeroSchema,
|
||||
@@ -44,6 +49,7 @@ const sectionSchema = z.union([
|
||||
sectionCtaSchema,
|
||||
sectionFeaturesSchema,
|
||||
sectionTestimonialsSchema,
|
||||
sectionBenefitsSchema,
|
||||
])
|
||||
|
||||
const baseField = {
|
||||
@@ -52,6 +58,7 @@ const baseField = {
|
||||
required: z.boolean().optional().default(false),
|
||||
pattern: z.string().optional(),
|
||||
maxLength: z.number().int().positive().optional(),
|
||||
help: z.string().optional(),
|
||||
}
|
||||
|
||||
const textField = z.object({ type: z.literal('text'), ...baseField })
|
||||
|
||||
+37
-25
@@ -1,27 +1,39 @@
|
||||
{
|
||||
"app.title": "Landing Page Builder",
|
||||
"builder.title": "Landing Page Builder",
|
||||
"builder.preview": "Preview (static)",
|
||||
"builder.field.title": "Title",
|
||||
"builder.field.locale": "Locale",
|
||||
"builder.field.primaryColor": "Primary Color",
|
||||
"builder.field.fontFamily": "Font Family",
|
||||
"builder.upload.hero": "Hero Image Upload",
|
||||
"builder.action.addHero": "Add Hero",
|
||||
"builder.action.addFAQ": "Add FAQ",
|
||||
"builder.action.addCTA": "Add CTA",
|
||||
"builder.action.export": "Export ZIP",
|
||||
"builder.action.addText": "Add Text",
|
||||
"builder.action.addEmail": "Add Email",
|
||||
"builder.action.addTel": "Add Tel",
|
||||
"builder.action.addDate": "Add Date",
|
||||
"builder.action.addTextarea": "Add Textarea",
|
||||
"builder.action.addCheckbox": "Add Checkbox",
|
||||
"builder.action.addSelect": "Add Select",
|
||||
"builder.action.addRadio": "Add Radio",
|
||||
"builder.sections": "Sections",
|
||||
"builder.form.fields": "Form Fields",
|
||||
"builder.form.actionUrl": "Action URL",
|
||||
"builder.form.honeypot": "Honeypot Field",
|
||||
"builder.form.minSeconds": "Min Submit Seconds"
|
||||
"app": {
|
||||
"title": "Landing Page Builder"
|
||||
},
|
||||
"builder": {
|
||||
"title": "Landing Page Builder",
|
||||
"preview": "Preview (static)",
|
||||
"field": {
|
||||
"title": "Title",
|
||||
"locale": "Locale",
|
||||
"primaryColor": "Primary Color",
|
||||
"fontFamily": "Font Family"
|
||||
},
|
||||
"upload": {
|
||||
"hero": "Hero Image Upload"
|
||||
},
|
||||
"action": {
|
||||
"addHero": "Add Hero",
|
||||
"addFAQ": "Add FAQ",
|
||||
"addCTA": "Add CTA",
|
||||
"export": "Export ZIP",
|
||||
"addText": "Add Text",
|
||||
"addEmail": "Add Email",
|
||||
"addTel": "Add Tel",
|
||||
"addDate": "Add Date",
|
||||
"addTextarea": "Add Textarea",
|
||||
"addCheckbox": "Add Checkbox",
|
||||
"addSelect": "Add Select",
|
||||
"addRadio": "Add Radio"
|
||||
},
|
||||
"sections": "Sections",
|
||||
"form": {
|
||||
"fields": "Form Fields",
|
||||
"actionUrl": "Action URL",
|
||||
"honeypot": "Honeypot Field",
|
||||
"minSeconds": "Min Submit Seconds"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+37
-14
@@ -1,16 +1,39 @@
|
||||
{
|
||||
"app.title": "랜딩 페이지 빌더",
|
||||
"builder.title": "랜딩 페이지 빌더",
|
||||
"builder.preview": "미리보기(정적)",
|
||||
"builder.field.title": "제목",
|
||||
"builder.field.locale": "로케일",
|
||||
"builder.field.primaryColor": "대표 색상",
|
||||
"builder.field.fontFamily": "폰트",
|
||||
"builder.upload.hero": "히어로 이미지 업로드",
|
||||
"builder.action.addHero": "히어로 추가",
|
||||
"builder.action.addFAQ": "FAQ 추가",
|
||||
"builder.action.addCTA": "CTA 추가",
|
||||
"builder.action.export": "ZIP 내보내기",
|
||||
"builder.sections": "섹션",
|
||||
"builder.form.fields": "폼 필드"
|
||||
"app": {
|
||||
"title": "랜딩 페이지 빌더"
|
||||
},
|
||||
"builder": {
|
||||
"title": "랜딩 페이지 빌더",
|
||||
"preview": "미리보기(정적)",
|
||||
"field": {
|
||||
"title": "제목",
|
||||
"locale": "로케일",
|
||||
"primaryColor": "대표 색상",
|
||||
"fontFamily": "폰트"
|
||||
},
|
||||
"upload": {
|
||||
"hero": "히어로 이미지 업로드"
|
||||
},
|
||||
"action": {
|
||||
"addHero": "히어로 추가",
|
||||
"addFAQ": "FAQ 추가",
|
||||
"addCTA": "CTA 추가",
|
||||
"export": "ZIP 내보내기",
|
||||
"addText": "텍스트 필드 추가",
|
||||
"addEmail": "이메일 필드 추가",
|
||||
"addTel": "전화번호 필드 추가",
|
||||
"addDate": "날짜 필드 추가",
|
||||
"addTextarea": "텍스트영역 추가",
|
||||
"addCheckbox": "체크박스 추가",
|
||||
"addSelect": "셀렉트 추가",
|
||||
"addRadio": "라디오 추가"
|
||||
},
|
||||
"sections": "섹션",
|
||||
"form": {
|
||||
"fields": "폼 필드",
|
||||
"actionUrl": "액션 URL",
|
||||
"honeypot": "허니팟 필드",
|
||||
"minSeconds": "최소 제출 대기(초)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
|
||||
type WindowWithExport = Window & {
|
||||
__exportPreview?: () => { html: string; css: string; js: string }
|
||||
}
|
||||
|
||||
const builderUrl = '/en/builder'
|
||||
|
||||
// Verify that focus outline tokens from CSS are applied in a real browser context
|
||||
// by focusing the submit button in the exported page and inspecting computed styles.
|
||||
test('Exported page shows 3px solid outline color on focused button', async ({ page, context }) => {
|
||||
await page.goto(builderUrl)
|
||||
// Minimal content to export
|
||||
await page.getByTestId('card-hero').click()
|
||||
|
||||
await page.waitForFunction(() => Boolean((window as unknown as WindowWithExport).__exportPreview), { timeout: 5000 })
|
||||
const exported = await page.evaluate(() => (window as unknown as WindowWithExport).__exportPreview?.() ?? null)
|
||||
expect(exported).not.toBeNull()
|
||||
|
||||
const preview = await context.newPage()
|
||||
await preview.setContent(exported!.html)
|
||||
await preview.addStyleTag({ content: exported!.css })
|
||||
|
||||
const submit = preview.locator('button[type="submit"]')
|
||||
await expect(submit).toHaveCount(1)
|
||||
await submit.focus()
|
||||
|
||||
// Read computed style in the page context
|
||||
const style = await preview.evaluate(() => {
|
||||
const el = document.querySelector('button[type="submit"]') as HTMLElement | null
|
||||
if (!el) return null
|
||||
const cs = window.getComputedStyle(el)
|
||||
return { outlineWidth: cs.outlineWidth, outlineStyle: cs.outlineStyle, outlineColor: cs.outlineColor }
|
||||
})
|
||||
expect(style).not.toBeNull()
|
||||
// Expect 3px solid and brand color (#2563eb => rgb(37, 99, 235))
|
||||
expect(style!.outlineWidth).toBe('3px')
|
||||
expect(style!.outlineStyle).toBe('solid')
|
||||
expect(style!.outlineColor.replace(/\s+/g, '')).toMatch(/rgb\(37,99,235\)|#2563eb/i)
|
||||
|
||||
await preview.close()
|
||||
})
|
||||
@@ -0,0 +1,41 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
|
||||
type WindowWithExport = Window & {
|
||||
__exportPreview?: () => { html: string; css: string; js: string }
|
||||
}
|
||||
|
||||
const builderUrl = '/en/builder'
|
||||
|
||||
// This test exports the preview, then loads the exported HTML/CSS in a fresh page
|
||||
// and verifies that the skip-link becomes visible on focus.
|
||||
test('Exported page skip-link becomes visible on focus', async ({ page, context }) => {
|
||||
await page.goto(builderUrl)
|
||||
|
||||
// Minimal content to allow export to produce sections and styles
|
||||
await page.getByTestId('card-hero').click()
|
||||
|
||||
await page.waitForFunction(() => Boolean((window as unknown as WindowWithExport).__exportPreview), { timeout: 5000 })
|
||||
const exported = await page.evaluate(() => (window as unknown as WindowWithExport).__exportPreview?.() ?? null)
|
||||
expect(exported).not.toBeNull()
|
||||
|
||||
// Open a clean page to render exported HTML/CSS and interact with it
|
||||
const preview = await context.newPage()
|
||||
await preview.setContent(exported!.html)
|
||||
|
||||
// Inject CSS into the same document head if not already present
|
||||
await preview.addStyleTag({ content: exported!.css })
|
||||
|
||||
// Ensure skip-link exists and is initially off-screen
|
||||
const skip = preview.locator('a.skip-link')
|
||||
await expect(skip).toHaveCount(1)
|
||||
|
||||
// Focus the skip-link and assert it moved on-screen (left not -9999px)
|
||||
await skip.focus()
|
||||
const box = await skip.boundingBox()
|
||||
expect(box).not.toBeNull()
|
||||
// left should be >= 0 when focused as per our CSS rule (left:1rem)
|
||||
if (!box) throw new Error('skip-link bounding box was null')
|
||||
expect(box.x).toBeGreaterThanOrEqual(0)
|
||||
|
||||
await preview.close()
|
||||
})
|
||||
@@ -0,0 +1,49 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
|
||||
type WindowWithExport = Window & {
|
||||
__exportPreview?: () => { html: string; css: string; js: string }
|
||||
}
|
||||
|
||||
const builderUrl = '/en/builder'
|
||||
|
||||
// Verify tab order after activating the skip-link: focus should move into <main>
|
||||
// Then the first Tab should reach a focusable descendant (e.g., form submit button)
|
||||
test('Skip-link Enter moves focus into main; next Tab reaches first focusable', async ({ page, context }) => {
|
||||
await page.goto(builderUrl)
|
||||
await page.getByTestId('card-hero').click()
|
||||
|
||||
await page.waitForFunction(() => Boolean((window as unknown as WindowWithExport).__exportPreview), { timeout: 5000 })
|
||||
const exported = await page.evaluate(() => (window as unknown as WindowWithExport).__exportPreview?.() ?? null)
|
||||
expect(exported).not.toBeNull()
|
||||
|
||||
const preview = await context.newPage()
|
||||
await preview.setContent(exported!.html)
|
||||
await preview.addStyleTag({ content: exported!.css })
|
||||
|
||||
const skip = preview.locator('a.skip-link')
|
||||
await expect(skip).toHaveCount(1)
|
||||
await skip.focus()
|
||||
await expect(skip).toBeFocused()
|
||||
|
||||
// Activate skip-link
|
||||
await preview.keyboard.press('Enter')
|
||||
|
||||
// Focus should be inside #main or on #main
|
||||
const focusedInMain = await preview.evaluate(() => {
|
||||
const main = document.getElementById('main')!
|
||||
const active = document.activeElement as HTMLElement | null
|
||||
if (!active) return false
|
||||
return active === main || main.contains(active)
|
||||
})
|
||||
expect(focusedInMain).toBeTruthy()
|
||||
|
||||
// Press Tab and expect a focusable inside main (submit button) to receive focus
|
||||
await preview.keyboard.press('Tab')
|
||||
const isSubmitFocused = await preview.evaluate(() => {
|
||||
const active = document.activeElement as HTMLElement | null
|
||||
return !!active && active.tagName.toLowerCase() === 'button' && (active as HTMLButtonElement).type === 'submit'
|
||||
})
|
||||
expect(isSubmitFocused).toBeTruthy()
|
||||
|
||||
await preview.close()
|
||||
})
|
||||
@@ -4,10 +4,14 @@ const builderUrl = '/en/builder'
|
||||
|
||||
test('Preview viewport toggle via keyboard (Tab + Enter/Space)', async ({ page }) => {
|
||||
await page.goto(builderUrl)
|
||||
await page.waitForLoadState('domcontentloaded')
|
||||
// Ensure the page has focus before sending keyboard events
|
||||
await page.locator('body').click({ position: { x: 1, y: 1 } })
|
||||
|
||||
// Tab to first button (Desktop)
|
||||
await page.keyboard.press('Tab')
|
||||
await expect(page.getByRole('button', { name: 'Desktop' })).toBeFocused()
|
||||
// Focus the Desktop button explicitly to avoid flakiness from skip-link/initial focus
|
||||
const desktopBtn = page.getByRole('button', { name: 'Desktop' })
|
||||
await desktopBtn.focus()
|
||||
await expect(desktopBtn).toBeFocused()
|
||||
|
||||
// Press Space to toggle Mobile (first ensure Desktop is selected, then move to Mobile with Tab)
|
||||
await page.keyboard.press('Tab')
|
||||
|
||||
Reference in New Issue
Block a user