45 lines
1.8 KiB
TypeScript
45 lines
1.8 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { buildExtrasForPage } from '@/lib/exporter/extras'
|
|
import { pageSchema, type Page } from '@/lib/schema/page'
|
|
|
|
function makePage(): Page {
|
|
return pageSchema.parse({
|
|
title: 'My Product',
|
|
locale: 'en',
|
|
theme: { primaryColor: '#0ea5e9', fontFamily: 'Inter' },
|
|
sections: [ { type: 'hero', props: { heading: 'Hello', subheading: '', imageUrl: 'https://example.com/hero.png' } } ],
|
|
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
|
seo: { title: 't', description: 'd' },
|
|
})
|
|
}
|
|
|
|
function toStr(bytes: Uint8Array) {
|
|
return new TextDecoder().decode(bytes)
|
|
}
|
|
|
|
describe('extras 자동 보강', () => {
|
|
it('manifest: 잘못된 theme_color는 무시하고 기본(primaryColor) 사용', () => {
|
|
const page = makePage()
|
|
const out = buildExtrasForPage(page, { manifest: { theme_color: 'not-a-hex' } })
|
|
const manifest = JSON.parse(toStr(out['site.webmanifest']))
|
|
expect(manifest.theme_color).toBe('#0ea5e9')
|
|
})
|
|
|
|
it('manifest: short_name은 12자 이내로 자동 절단', () => {
|
|
const page = makePage()
|
|
const out = buildExtrasForPage(page, { manifest: { name: 'Super Long Product Name' } })
|
|
const manifest = JSON.parse(toStr(out['site.webmanifest']))
|
|
expect(manifest.short_name.length).toBeLessThanOrEqual(12)
|
|
})
|
|
|
|
it('robots: 주어진 plain 경로 목록을 자동으로 User-agent 헤더와 Disallow 라인으로 보강', () => {
|
|
const page = makePage()
|
|
const robotsPlain = "/admin\n/private"
|
|
const out = buildExtrasForPage(page, { robotsText: robotsPlain })
|
|
const robots = toStr(out['robots.txt'])
|
|
expect(robots).toMatch(/^User-agent: \*/)
|
|
expect(robots).toMatch(/Disallow: \/admin/)
|
|
expect(robots).toMatch(/Disallow: \/private/)
|
|
})
|
|
})
|