44 lines
1.6 KiB
TypeScript
44 lines
1.6 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { pageSchema, type Page } from '@/lib/schema/page'
|
|
import { exportPage } from '@/lib/exporter/html'
|
|
|
|
describe('Analytics snippet injection', () => {
|
|
const base = {
|
|
title: 'Analytics Test',
|
|
locale: 'en',
|
|
theme: { primaryColor: '#0ea5e9', fontFamily: 'Inter' },
|
|
sections: [],
|
|
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
|
seo: { title: 'Analytics Test', description: 'desc' },
|
|
}
|
|
|
|
it('GA4 measurement ID가 있으면 GA4 스니펫을 삽입한다', () => {
|
|
const page: Page = pageSchema.parse({
|
|
...base,
|
|
analytics: { ga4MeasurementId: 'G-ABC123', metaPixelId: '' },
|
|
})
|
|
const out = exportPage(page)
|
|
expect(out.html).toContain('https://www.googletagmanager.com/gtag/js?id=G-ABC123')
|
|
expect(out.html).toContain("gtag('config', 'G-ABC123')")
|
|
})
|
|
|
|
it('Meta Pixel ID가 있으면 Pixel 스니펫을 삽입한다', () => {
|
|
const page: Page = pageSchema.parse({
|
|
...base,
|
|
analytics: { ga4MeasurementId: '', metaPixelId: '1234567890' },
|
|
})
|
|
const out = exportPage(page)
|
|
expect(out.html).toContain('fbq(')
|
|
expect(out.html).toContain("fbq('init', '1234567890')")
|
|
})
|
|
|
|
it('customHeadHtml이 있으면 head에 그대로 삽입한다', () => {
|
|
const page: Page = pageSchema.parse({
|
|
...base,
|
|
analytics: { ga4MeasurementId: '', metaPixelId: '', customHeadHtml: '<meta name="robots" content="noindex">' },
|
|
})
|
|
const out = exportPage(page)
|
|
expect(out.html).toContain('<meta name="robots" content="noindex">')
|
|
})
|
|
})
|