39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { interpolate, renderReportHtml, renderEmailHtml } from './templateEngine.js'
|
|
|
|
test('interpolates nested values', () => {
|
|
assert.equal(interpolate('Hello {{customer.name}}', { customer: { name: 'Kauri' } }), 'Hello Kauri')
|
|
})
|
|
|
|
test('report output escapes injected markup', () => {
|
|
const html = renderReportHtml({ blocks: [{ type: 'text', props: { text: '{{value}}' } }] }, { value: '<script>x</script>' })
|
|
assert.match(html, /<script>/)
|
|
assert.doesNotMatch(html, /<script>x/)
|
|
})
|
|
|
|
test('email renderer produces HTML', () => {
|
|
const html = renderEmailHtml({ blocks: [{ type: 'heading', props: { text: 'Hello' } }] }, {})
|
|
assert.match(html, /Hello/)
|
|
assert.match(html, /doctype/i)
|
|
})
|
|
|
|
test('report renderer applies constrained pack theme styling', () => {
|
|
const html = renderReportHtml({
|
|
theme: {
|
|
backgroundColor: '#f6f1e8',
|
|
accentColor: '#8b5e34',
|
|
pageBackgroundImage: 'https://templates.arrowstack.dev/media/token/bg.webp'
|
|
},
|
|
blocks: [{
|
|
type: 'heading',
|
|
props: { text: 'Styled' },
|
|
style: { backgroundColor: '#fffaf2', padding: 18, borderRadius: 12 }
|
|
}]
|
|
}, {})
|
|
assert.match(html, /#f6f1e8/)
|
|
assert.match(html, /#8b5e34/)
|
|
assert.match(html, /bg\.webp/)
|
|
assert.match(html, /padding:18px/)
|
|
})
|