48 lines
2.0 KiB
TypeScript
48 lines
2.0 KiB
TypeScript
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')
|
|
})
|
|
})
|