adding complex test case
This commit is contained in:
parent
549c53ce35
commit
ffc682f70b
@ -601,6 +601,7 @@ export default function fillOdtElementTemplate(rootElements, compartment) {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
traverse(rootElement, currentNode => {
|
traverse(rootElement, currentNode => {
|
||||||
//console.log('currentlyOpenBlocks', currentlyOpenBlocks)
|
//console.log('currentlyOpenBlocks', currentlyOpenBlocks)
|
||||||
|
//console.log('eachOpeningMarkerNode', eachOpeningMarkerNode)
|
||||||
|
|
||||||
const insideAnOpenBlock = currentlyOpenBlocks.length >= 1
|
const insideAnOpenBlock = currentlyOpenBlocks.length >= 1
|
||||||
|
|
||||||
@ -637,11 +638,10 @@ export default function fillOdtElementTemplate(rootElements, compartment) {
|
|||||||
|
|
||||||
if(isEachClosingBlock) {
|
if(isEachClosingBlock) {
|
||||||
|
|
||||||
//console.log('isEachClosingBlock', isEachClosingBlock)
|
//console.log('isEachClosingBlock', isEachClosingBlock, currentlyOpenBlocks)
|
||||||
|
|
||||||
if(!eachOpeningMarkerNode){
|
if(!insideAnOpenBlock)
|
||||||
throw new Error(`{/each} found without corresponding opening {#each x as y}`)
|
throw new Error('{/each} found without corresponding opening {#each x as y}')
|
||||||
}
|
|
||||||
|
|
||||||
if(currentlyOpenBlocks.at(-1) !== EACH)
|
if(currentlyOpenBlocks.at(-1) !== EACH)
|
||||||
throw new Error(`{/each} found while the last opened block was not an opening {#each x as y}`)
|
throw new Error(`{/each} found while the last opened block was not an opening {#each x as y}`)
|
||||||
|
|||||||
25
tests/fill-odt-template/complex.js
Normal file
25
tests/fill-odt-template/complex.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import test from 'ava';
|
||||||
|
import {join} from 'node:path';
|
||||||
|
|
||||||
|
import {getOdtTemplate} from '../../scripts/odf/odtTemplate-forNode.js'
|
||||||
|
|
||||||
|
import {fillOdtTemplate, getOdtTextContent} from '../../exports.js'
|
||||||
|
|
||||||
|
|
||||||
|
test('template with {#each} inside an {#if}', async t => {
|
||||||
|
const templatePath = join(import.meta.dirname, '../fixtures/if-then-each.odt')
|
||||||
|
const templateContent = `{#if liste_départements.length >= 2}{#each liste_départements as département}{département}, {/each} {/if}`
|
||||||
|
|
||||||
|
const data = {liste_départements : ['95', '33']}
|
||||||
|
|
||||||
|
const odtTemplate = await getOdtTemplate(templatePath)
|
||||||
|
const templateTextContent = await getOdtTextContent(odtTemplate)
|
||||||
|
t.deepEqual(templateTextContent.trim(), templateContent.trim(), 'reconnaissance du template')
|
||||||
|
|
||||||
|
const odtResult = await fillOdtTemplate(odtTemplate, data)
|
||||||
|
|
||||||
|
const odtResultTextContent = await getOdtTextContent(odtResult)
|
||||||
|
t.deepEqual(odtResultTextContent.trim(), `95, 33,`)
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user