import { describe, it, expect } from 'vitest' import { buildExtrasForPage } from '@/lib/exporter/extras' import type { Page } from '@/lib/schema/page' function td(b: Uint8Array){ return new TextDecoder().decode(b) } const basePage: Page = { title: 'Test', seo: { title: 'T', description: 'D' }, theme: { primaryColor: '#0ea5e9', fontFamily: 'Inter' }, analytics: { ga4MeasurementId: '', metaPixelId: '', customHeadHtml: '' }, sections: [], form: { fields: [], actionUrl: '', spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 }, }, locale: 'en', } describe('Sheets template enhance', () => { it('includes version/meta and mapping/error guide in Code.gs and README', () => { const extras = buildExtrasForPage(basePage, { sheetsMode: 'include' }) const code = td(extras['sheets/Code.gs']) const readme = td(extras['sheets/README.txt']) // version/meta header expect(code).toMatch(/@version:\s*\d+\.\d+\.\d+/) expect(code).toMatch(/@tool:\s*landing-builder/i) // field mapping and error handling guides expect(code).toMatch(/TODO:\s*map incoming fields to sheet columns/i) expect(code).toMatch(/try\s*\{/) expect(code).toMatch(/catch\s*\(e\)/) // README includes setup and mapping hint expect(readme).toMatch(/Apps Script/i) expect(readme).toMatch(/Deploy as Web App/i) expect(readme).toMatch(/Map fields to columns/i) }) it('respects exclude mode', () => { const extras = buildExtrasForPage(basePage, { sheetsMode: 'exclude' }) expect(Object.keys(extras).some(k => k.startsWith('sheets/'))).toBe(false) }) })