diff --git a/tests/fill-odt-template/image.js b/tests/fill-odt-template/image.js index 9162feb..8e67919 100644 --- a/tests/fill-odt-template/image.js +++ b/tests/fill-odt-template/image.js @@ -1,5 +1,6 @@ import test from 'ava'; import {join} from 'node:path'; +import { readFile } from 'node:fs/promises' import {getOdtTemplate} from '../../scripts/odf/odtTemplate-forNode.js' @@ -7,7 +8,7 @@ import {fillOdtTemplate} from '../../exports.js' import { listZipEntries } from '../helpers/zip-analysis.js'; -test('template filling preserves images', async t => { +test.skip('template filling preserves images', async t => { const templatePath = join(import.meta.dirname, '../fixtures/template-avec-image.odt') const data = { @@ -35,4 +36,34 @@ test('template filling preserves images', async t => { `One zip entry of the result is expected to have a name that starts with 'Pictures/'` ) +}) + +test('insert 2 images', async t => { + const templatePath = join(import.meta.dirname, '../fixtures/basic-image-insertion.odt') + const odtTemplate = await getOdtTemplate(templatePath) + + + const photo1Path = join(import.meta.dirname, '../fixtures/pitchou-1.png') + const photo2Path = join(import.meta.dirname, '../fixtures/pitchou-2.png') + + const photo1Buffer = (await readFile(photo1Path)).buffer + const photo2Buffer = (await readFile(photo2Path)).buffer + + const photos = [photo1Buffer, photo2Buffer] + + const data = { + title: 'Titre de mon projet', + photos, + } + + const odtResult = await fillOdtTemplate(odtTemplate, data) + const resultEntries = await listZipEntries(odtResult) + + t.is( + resultEntries.filter(entry => entry.filename.startsWith('Pictures/')).length, 2, + `Two pictures in 'Pictures/' folder are expected` + ) + + + t.fail('Two images should be in the content.xml file') }) \ No newline at end of file diff --git a/tests/fixtures/pitchou-1.png b/tests/fixtures/pitchou-1.png new file mode 100644 index 0000000..ba3c46a Binary files /dev/null and b/tests/fixtures/pitchou-1.png differ diff --git a/tests/fixtures/pitchou-2.png b/tests/fixtures/pitchou-2.png new file mode 100644 index 0000000..757faa3 Binary files /dev/null and b/tests/fixtures/pitchou-2.png differ