« get me outta code hell

test: transformContent (snapshot) for image processing - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-07-30 20:13:20 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-07-30 20:13:20 -0300
commit8bc0bd0205983fea97803a9993225b42830544c8 (patch)
treee0a5244a4d8f300ed47ab3a35351a1616bcc80d6
parentc992413b842c4a25dcee7e97a129557a781f0980 (diff)
test: transformContent (snapshot) for image processing
-rw-r--r--tap-snapshots/test/snapshot/transformContent.js.test.cjs46
-rw-r--r--test/snapshot/transformContent.js60
2 files changed, 106 insertions, 0 deletions
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`] = `
+<p><img src="snooping.png"> as USUAL...</p>
+<p>What do you know? <img src="cowabunga.png" width="24" height="32"></p>
+<p><a href="to-localized.album/cool-album" style="--primary-color: #123456; --dim-color: #000000">I&#39;m on the left.</a><img src="im-on-the-right.jpg"></p>
+<p><img src="im-on-the-left.jpg"><a href="to-localized.album/cool-album" style="--primary-color: #123456; --dim-color: #000000">I&#39;m on the right.</a></p>
+<p>Media time! <img src="to-media.path/misc/interesting.png"> Oh yeah!</p>
+<p><img src="must.png"><img src="stick.png"><img src="together.png"></p>
+<p>And... all done! <img src="end-of-source.png"></p>
+
+`
+
+exports[`test/snapshot/transformContent.js TAP transformContent (snapshot) > links to a thing 1`] = `
+<p>This is <a href="to-localized.album/cool-album" style="--primary-color: #123456; --dim-color: #000000">my favorite album</a>.</p>
+<p>That&#39;s right, <a href="to-localized.album/cool-album" style="--primary-color: #123456; --dim-color: #000000">Cool Album</a>!</p>
+
+`
+
+exports[`test/snapshot/transformContent.js TAP transformContent (snapshot) > non-inline image #1 1`] = `
+<p><a class="box image-link" href="spark.png"><div class="image-container"><div class="image-inner-area"><img src="spark.png"></div></div></a></p>
+
+`
+
+exports[`test/snapshot/transformContent.js TAP transformContent (snapshot) > non-inline image #2 1`] = `
+<p>Rad.</p>
+<p><a class="box image-link" href="spark.png"><div class="image-container"><div class="image-inner-area"><img src="spark.png"></div></div></a></p>
+
+`
+
+exports[`test/snapshot/transformContent.js TAP transformContent (snapshot) > non-inline image #3 1`] = `
+<p><a class="box image-link" href="spark.png"><div class="image-container"><div class="image-inner-area"><img src="spark.png"></div></div></a></p>
+<p>Baller.</p>
+
+`
+
+exports[`test/snapshot/transformContent.js TAP transformContent (snapshot) > two text paragraphs 1`] = `
+<p>Hello, world!</p>
+<p>Wow, this is very cool.</p>
+
+`
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',
+      `<img src="snooping.png"> as USUAL...\n` +
+      `What do you know? <img src="cowabunga.png" width="24" height="32">\n` +
+      `[[album:cool-album|I'm on the left.]]<img src="im-on-the-right.jpg">\n` +
+      `<img src="im-on-the-left.jpg">[[album:cool-album|I'm on the right.]]\n` +
+      `Media time! <img src="media/misc/interesting.png"> Oh yeah!\n` +
+      `<img src="must.png"><img src="stick.png"><img src="together.png">\n` +
+      `And... all done! <img src="end-of-source.png">`);
+
+  quickSnapshot(
+    'non-inline image #1',
+      `<img src="spark.png">`);
+
+  quickSnapshot(
+    'non-inline image #2',
+      `Rad.\n<img src="spark.png">`);
+
+  quickSnapshot(
+    'non-inline image #3',
+      `<img src="spark.png">\nBaller.`);
+});