From 8bc0bd0205983fea97803a9993225b42830544c8 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 30 Jul 2023 20:13:20 -0300 Subject: test: transformContent (snapshot) for image processing --- .../test/snapshot/transformContent.js.test.cjs | 46 +++++++++++++++++ test/snapshot/transformContent.js | 60 ++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 tap-snapshots/test/snapshot/transformContent.js.test.cjs create mode 100644 test/snapshot/transformContent.js diff --git a/tap-snapshots/test/snapshot/transformContent.js.test.cjs b/tap-snapshots/test/snapshot/transformContent.js.test.cjs new file mode 100644 index 00000000..a59f8b5d --- /dev/null +++ b/tap-snapshots/test/snapshot/transformContent.js.test.cjs @@ -0,0 +1,46 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/snapshot/transformContent.js TAP transformContent (snapshot) > inline images 1`] = ` +

as USUAL...

+

What do you know?

+

I'm on the left.

+

I'm on the right.

+

Media time! Oh yeah!

+

+

And... all done!

+ +` + +exports[`test/snapshot/transformContent.js TAP transformContent (snapshot) > links to a thing 1`] = ` +

This is my favorite album.

+

That's right, Cool Album!

+ +` + +exports[`test/snapshot/transformContent.js TAP transformContent (snapshot) > non-inline image #1 1`] = ` +

+ +` + +exports[`test/snapshot/transformContent.js TAP transformContent (snapshot) > non-inline image #2 1`] = ` +

Rad.

+

+ +` + +exports[`test/snapshot/transformContent.js TAP transformContent (snapshot) > non-inline image #3 1`] = ` +

+

Baller.

+ +` + +exports[`test/snapshot/transformContent.js TAP transformContent (snapshot) > two text paragraphs 1`] = ` +

Hello, world!

+

Wow, this is very cool.

+ +` diff --git a/test/snapshot/transformContent.js b/test/snapshot/transformContent.js new file mode 100644 index 00000000..f55ca4fa --- /dev/null +++ b/test/snapshot/transformContent.js @@ -0,0 +1,60 @@ +import t from 'tap'; +import {testContentFunctions} from '../lib/content-function.js'; + +testContentFunctions(t, 'transformContent (snapshot)', async (t, evaluate) => { + await evaluate.load(); + + const extraDependencies = { + wikiData: { + albumData: [ + {directory: 'cool-album', name: 'Cool Album', color: '#123456'}, + ], + }, + + getSizeOfImageFile: () => 0, + + to: (key, ...args) => `to-${key}/${args.join('/')}`, + }; + + const quickSnapshot = (message, content, slots) => + evaluate.snapshot(message, { + name: 'transformContent', + args: [content], + extraDependencies, + slots, + }); + + // TODO: Snapshots for different transformContent modes + + quickSnapshot( + 'two text paragraphs', + `Hello, world!\n` + + `Wow, this is very cool.`); + + quickSnapshot( + 'links to a thing', + `This is [[album:cool-album|my favorite album]].\n` + + `That's right, [[album:cool-album]]!`); + + quickSnapshot( + 'inline images', + ` as USUAL...\n` + + `What do you know? \n` + + `[[album:cool-album|I'm on the left.]]\n` + + `[[album:cool-album|I'm on the right.]]\n` + + `Media time! Oh yeah!\n` + + `\n` + + `And... all done! `); + + quickSnapshot( + 'non-inline image #1', + ``); + + quickSnapshot( + 'non-inline image #2', + `Rad.\n`); + + quickSnapshot( + 'non-inline image #3', + `\nBaller.`); +}); -- cgit 1.3.0-6-gf8a5