David Bruant c9284343e8
If blocks (#4)
* Adding {#if} test case

* Expression evaluation based on ses Compartments

* New Compartment usage

* split template filling tests

* passing tests except the if one

* in progress

* Refactoring: extracting extractBlockContent method

* test if qui passe

* Move tree preparation to its own function so it's done ony once

* if in a single text node works
2025-05-07 09:15:29 +02:00

37 lines
1000 B
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import test from 'ava';
import {join} from 'node:path';
import {getOdtTemplate} from '../../scripts/odf/odtTemplate-forNode.js'
import {fillOdtTemplate, getOdtTextContent} from '../../exports.js'
test('basic template filling with variable substitution', async t => {
const templatePath = join(import.meta.dirname, '../fixtures/template-anniversaire.odt')
const templateContent = `Yo {nom} !
Tu es né.e le {dateNaissance}
Bonjoir ☀️
`
const data = {
nom: 'David Bruant',
dateNaissance: '8 mars 1987'
}
const odtTemplate = await getOdtTemplate(templatePath)
const templateTextContent = await getOdtTextContent(odtTemplate)
t.deepEqual(templateTextContent, templateContent, 'reconnaissance du template')
const odtResult = await fillOdtTemplate(odtTemplate, data)
const odtResultTextContent = await getOdtTextContent(odtResult)
t.deepEqual(odtResultTextContent, `Yo David Bruant !
Tu es né.e le 8 mars 1987
Bonjoir ☀️
`)
});