« get me outta code hell

test: generateContributionLinks -> linkContribution - 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-06-13 12:54:20 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-06-13 12:54:20 -0300
commitba41071d9b6647b2e12a78de774a55aef5b87876 (patch)
tree434759eb6bb9d45a96995bbefbaef003a3d79990
parent2ce5ddd844603b1c3d8f220a12603677104b7545 (diff)
test: generateContributionLinks -> linkContribution
-rw-r--r--tap-snapshots/test/snapshot/linkContribution.js.test.cjs (renamed from tap-snapshots/test/snapshot/generateContributionLinks.js.test.cjs)24
-rw-r--r--test/snapshot/generateContributionLinks.js55
-rw-r--r--test/snapshot/linkContribution.js54
-rw-r--r--test/unit/content/dependencies/linkContribution.js (renamed from test/unit/content/dependencies/generateContributionLinks.js)81
4 files changed, 117 insertions, 97 deletions
diff --git a/tap-snapshots/test/snapshot/generateContributionLinks.js.test.cjs b/tap-snapshots/test/snapshot/linkContribution.js.test.cjs
index 0abd2d38..cecad538 100644
--- a/tap-snapshots/test/snapshot/generateContributionLinks.js.test.cjs
+++ b/tap-snapshots/test/snapshot/linkContribution.js.test.cjs
@@ -5,21 +5,27 @@
  * Make sure to inspect the output below.  Do not ignore changes!
  */
 'use strict'
-exports[`test/snapshot/generateContributionLinks.js TAP generateContributionLinks (snapshot) > no accents 1`] = `
-<a href="artist/clark-powell/">Clark Powell</a>, <a href="artist/the-big-baddies/">Grounder & Scratch</a>, and <a href="artist/toby-fox/">Toby Fox</a>
+exports[`test/snapshot/linkContribution.js TAP linkContribution (snapshot) > no accents 1`] = `
+<a href="artist/clark-powell/">Clark Powell</a>
+<a href="artist/the-big-baddies/">Grounder & Scratch</a>
+<a href="artist/toby-fox/">Toby Fox</a>
 `
 
-exports[`test/snapshot/generateContributionLinks.js TAP generateContributionLinks (snapshot) > only showContribution 1`] = `
-<a href="artist/clark-powell/">Clark Powell</a>, <a href="artist/the-big-baddies/">Grounder & Scratch</a> (Snooping), and <a href="artist/toby-fox/">Toby Fox</a> (Arrangement)
+exports[`test/snapshot/linkContribution.js TAP linkContribution (snapshot) > only showContribution 1`] = `
+<a href="artist/clark-powell/">Clark Powell</a>
+<a href="artist/the-big-baddies/">Grounder & Scratch</a> (Snooping)
+<a href="artist/toby-fox/">Toby Fox</a> (Arrangement)
 `
 
-exports[`test/snapshot/generateContributionLinks.js TAP generateContributionLinks (snapshot) > only showIcons 1`] = `
+exports[`test/snapshot/linkContribution.js TAP linkContribution (snapshot) > only showIcons 1`] = `
 <a href="artist/clark-powell/">Clark Powell</a> (<span class="icons"><a href="https://soundcloud.com/plazmataz" class="icon">
         <svg>
             <title>SoundCloud</title>
             <use href="static/icons.svg#icon-soundcloud"></use>
         </svg>
-    </a></span>), <a href="artist/the-big-baddies/">Grounder & Scratch</a>, and <a href="artist/toby-fox/">Toby Fox</a> (<span class="icons"><a href="https://tobyfox.bandcamp.com/" class="icon">
+    </a></span>)
+<a href="artist/the-big-baddies/">Grounder & Scratch</a>
+<a href="artist/toby-fox/">Toby Fox</a> (<span class="icons"><a href="https://tobyfox.bandcamp.com/" class="icon">
         <svg>
             <title>Bandcamp</title>
             <use href="static/icons.svg#icon-bandcamp"></use>
@@ -32,13 +38,15 @@ exports[`test/snapshot/generateContributionLinks.js TAP generateContributionLink
     </a></span>)
 `
 
-exports[`test/snapshot/generateContributionLinks.js TAP generateContributionLinks (snapshot) > showContribution & showIcons 1`] = `
+exports[`test/snapshot/linkContribution.js TAP linkContribution (snapshot) > showContribution & showIcons 1`] = `
 <a href="artist/clark-powell/">Clark Powell</a> (<span class="icons"><a href="https://soundcloud.com/plazmataz" class="icon">
         <svg>
             <title>SoundCloud</title>
             <use href="static/icons.svg#icon-soundcloud"></use>
         </svg>
-    </a></span>), <a href="artist/the-big-baddies/">Grounder & Scratch</a> (Snooping), and <a href="artist/toby-fox/">Toby Fox</a> (Arrangement) (<span class="icons"><a href="https://tobyfox.bandcamp.com/" class="icon">
+    </a></span>)
+<a href="artist/the-big-baddies/">Grounder & Scratch</a> (Snooping)
+<a href="artist/toby-fox/">Toby Fox</a> (Arrangement) (<span class="icons"><a href="https://tobyfox.bandcamp.com/" class="icon">
         <svg>
             <title>Bandcamp</title>
             <use href="static/icons.svg#icon-bandcamp"></use>
diff --git a/test/snapshot/generateContributionLinks.js b/test/snapshot/generateContributionLinks.js
deleted file mode 100644
index 3283d3b2..00000000
--- a/test/snapshot/generateContributionLinks.js
+++ /dev/null
@@ -1,55 +0,0 @@
-// todo: this dependency was replaced with linkContribution, restructure test
-// remove generateContributionLinks.js.test.cjs snapshot file too!
-
-import t from 'tap';
-import {testContentFunctions} from '../lib/content-function.js';
-
-t.skip('generateContributionLinks (snapshot)');
-
-void (() => testContentFunctions(t, 'generateContributionLinks (snapshot)', async (t, evaluate) => {
-  const artist1 = {
-    name: 'Clark Powell',
-    directory: 'clark-powell',
-    urls: ['https://soundcloud.com/plazmataz'],
-  };
-
-  const artist2 = {
-    name: 'Grounder & Scratch',
-    directory: 'the-big-baddies',
-    urls: [],
-  };
-
-  const artist3 = {
-    name: 'Toby Fox',
-    directory: 'toby-fox',
-    urls: ['https://tobyfox.bandcamp.com/', 'https://toby.fox/'],
-  };
-
-  const contributions = [
-    {who: artist1, what: null},
-    {who: artist2, what: 'Snooping'},
-    {who: artist3, what: 'Arrangement'},
-  ];
-
-  await evaluate.load();
-
-  evaluate.snapshot('showContribution & showIcons', {
-    name: 'generateContributionLinks',
-    args: [contributions, {showContribution: true, showIcons: true}],
-  });
-
-  evaluate.snapshot('only showContribution', {
-    name: 'generateContributionLinks',
-    args: [contributions, {showContribution: true, showIcons: false}],
-  });
-
-  evaluate.snapshot('only showIcons', {
-    name: 'generateContributionLinks',
-    args: [contributions, {showContribution: false, showIcons: true}],
-  });
-
-  evaluate.snapshot('no accents', {
-    name: 'generateContributionLinks',
-    args: [contributions, {showContribution: false, showIcons: false}],
-  });
-}));
diff --git a/test/snapshot/linkContribution.js b/test/snapshot/linkContribution.js
new file mode 100644
index 00000000..758fa264
--- /dev/null
+++ b/test/snapshot/linkContribution.js
@@ -0,0 +1,54 @@
+import t from 'tap';
+import {testContentFunctions} from '../lib/content-function.js';
+
+testContentFunctions(t, 'linkContribution (snapshot)', async (t, evaluate) => {
+  const who1 = {
+    name: 'Clark Powell',
+    directory: 'clark-powell',
+    urls: ['https://soundcloud.com/plazmataz'],
+  };
+
+  const who2 = {
+    name: 'Grounder & Scratch',
+    directory: 'the-big-baddies',
+    urls: [],
+  };
+
+  const who3 = {
+    name: 'Toby Fox',
+    directory: 'toby-fox',
+    urls: ['https://tobyfox.bandcamp.com/', 'https://toby.fox/'],
+  };
+
+  const what1 = null;
+  const what2 = 'Snooping';
+  const what3 = 'Arrangement';
+
+  await evaluate.load();
+
+  const quickSnapshot = (message, slots) =>
+    evaluate.snapshot(message, {
+      name: 'linkContribution',
+      multiple: [
+        {args: [who1, what1]},
+        {args: [who2, what2]},
+        {args: [who3, what3]},
+      ],
+      slots,
+    });
+
+  quickSnapshot('showContribution & showIcons', {
+    showContribution: true,
+    showIcons: true,
+  });
+
+  quickSnapshot('only showContribution', {
+    showContribution: true,
+  });
+
+  quickSnapshot('only showIcons', {
+    showIcons: true,
+  });
+
+  quickSnapshot('no accents', {});
+});
diff --git a/test/unit/content/dependencies/generateContributionLinks.js b/test/unit/content/dependencies/linkContribution.js
index 328adc0b..6f3150f7 100644
--- a/test/unit/content/dependencies/generateContributionLinks.js
+++ b/test/unit/content/dependencies/linkContribution.js
@@ -1,32 +1,31 @@
-// todo: this dependency was replaced with linkContribution, restructure test
-
 import t from 'tap';
 import {testContentFunctions} from '../../../lib/content-function.js';
 
-t.skip('generateContributionLinks (unit)', async t => {
-  const artist1 = {
+t.test('generateContributionLinks (unit)', async t => {
+  const who1 = {
     name: 'Clark Powell',
+    directory: 'clark-powell',
     urls: ['https://soundcloud.com/plazmataz'],
   };
 
-  const artist2 = {
+  const who2 = {
     name: 'Grounder & Scratch',
+    directory: 'the-big-baddies',
     urls: [],
   };
 
-  const artist3 = {
+  const who3 = {
     name: 'Toby Fox',
+    directory: 'toby-fox',
     urls: ['https://tobyfox.bandcamp.com/', 'https://toby.fox/'],
   };
 
-  const contributions = [
-    {who: artist1, what: null},
-    {who: artist2, what: 'Snooping'},
-    {who: artist3, what: 'Arrangement'},
-  ];
+  const what1 = null;
+  const what2 = 'Snooping';
+  const what3 = 'Arrangement';
 
   await testContentFunctions(t, 'generateContributionLinks (unit 1)', async (t, evaluate) => {
-    const config = {
+    const slots = {
       showContribution: true,
       showIcons: true,
     };
@@ -35,14 +34,14 @@ t.skip('generateContributionLinks (unit)', async t => {
       mock: evaluate.mock(mock => ({
         linkArtist: {
           relations: mock.function('linkArtist.relations', () => ({}))
-            .args([undefined, artist1]).next()
-            .args([undefined, artist2]).next()
-            .args([undefined, artist3]),
+            .args([undefined, who1]).next()
+            .args([undefined, who2]).next()
+            .args([undefined, who3]),
 
           data: mock.function('linkArtist.data', () => ({}))
-            .args([artist1]).next()
-            .args([artist2]).next()
-            .args([artist3]),
+            .args([who1]).next()
+            .args([who2]).next()
+            .args([who3]),
 
           // This can be tweaked to return a specific (mocked) template
           // for each artist if we need to test for slots in the future.
@@ -52,9 +51,9 @@ t.skip('generateContributionLinks (unit)', async t => {
 
         linkExternalAsIcon: {
           data: mock.function('linkExternalAsIcon.data', () => ({}))
-            .args([artist1.urls[0]]).next()
-            .args([artist3.urls[0]]).next()
-            .args([artist3.urls[1]]),
+            .args([who1.urls[0]]).next()
+            .args([who3.urls[0]]).next()
+            .args([who3.urls[1]]),
 
           generate: mock.function('linkExternalAsIcon.generate', () => 'icon')
             .repeat(3),
@@ -63,13 +62,18 @@ t.skip('generateContributionLinks (unit)', async t => {
     });
 
     evaluate({
-      name: 'generateContributionLinks',
-      args: [contributions, config],
+      name: 'linkContribution',
+      multiple: [
+        {args: [who1, what1]},
+        {args: [who2, what2]},
+        {args: [who3, what3]},
+      ],
+      slots,
     });
   });
 
   await testContentFunctions(t, 'generateContributionLinks (unit 2)', async (t, evaluate) => {
-    const config = {
+    const slots = {
       showContribution: false,
       showIcons: false,
     };
@@ -78,32 +82,41 @@ t.skip('generateContributionLinks (unit)', async t => {
       mock: evaluate.mock(mock => ({
         linkArtist: {
           relations: mock.function('linkArtist.relations', () => ({}))
-            .args([undefined, artist1]).next()
-            .args([undefined, artist2]).next()
-            .args([undefined, artist3]),
+            .args([undefined, who1]).next()
+            .args([undefined, who2]).next()
+            .args([undefined, who3]),
 
           data: mock.function('linkArtist.data', () => ({}))
-            .args([artist1]).next()
-            .args([artist2]).next()
-            .args([artist3]),
+            .args([who1]).next()
+            .args([who2]).next()
+            .args([who3]),
 
           generate: mock.function(() => 'artist link')
             .repeat(3),
         },
 
+        // Even though icons are hidden, these are still called! The dependency
+        // tree is the same since whether or not the external icon links are
+        // shown is dependent on a slot, which is undefined and arbitrary at
+        // relations/data time (it might change on a whim at generate time).
         linkExternalAsIcon: {
           data: mock.function('linkExternalAsIcon.data', () => ({}))
-            .neverCalled(),
+            .repeat(3),
 
           generate: mock.function('linkExternalAsIcon.generate', () => 'icon')
-            .neverCalled(),
+            .repeat(3),
         },
       })),
     });
 
     evaluate({
-      name: 'generateContributionLinks',
-      args: [contributions, config],
+      name: 'linkContribution',
+      multiple: [
+        {args: [who1, what1]},
+        {args: [who2, what2]},
+        {args: [who3, what3]},
+      ],
+      slots,
     });
   });
 });