« get me outta code hell

test (unit): generateContributionLinks - 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-03-28 19:50:16 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-03-28 19:50:16 -0300
commit8a1740168b260cd2f7a9ab6e8befff489943d2b1 (patch)
tree36932809e82a338c07c60246ace74fd7897b948b
parentb6393b1d3fc9adc59bc387b8013cbad30e3a164f (diff)
test (unit): generateContributionLinks
-rw-r--r--test/unit/content/dependencies/generateContributionLinks.js120
-rw-r--r--test/unit/content/dependencies/linkArtist.js2
2 files changed, 121 insertions, 1 deletions
diff --git a/test/unit/content/dependencies/generateContributionLinks.js b/test/unit/content/dependencies/generateContributionLinks.js
new file mode 100644
index 00000000..a0bb64ec
--- /dev/null
+++ b/test/unit/content/dependencies/generateContributionLinks.js
@@ -0,0 +1,120 @@
+import t from 'tap';
+import {testContentFunctions} from '../../../lib/content-function.js';
+
+t.test('generateContributionLinks (unit)', async t => {
+  await testContentFunctions(t, 'generateContributionLinks (unit 1)', async (t, evaluate) => {
+    const artist1 = {
+      name: 'Clark Powell',
+      urls: ['https://soundcloud.com/plazmataz'],
+    };
+
+    const artist2 = {
+      name: 'Grounder & Scratch',
+      urls: [],
+    };
+
+    const artist3 = {
+      name: '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 config = {
+      showContribution: true,
+      showIcons: true,
+    };
+
+    await evaluate.load({
+      mock: evaluate.mock(mock => ({
+        linkArtist: {
+          relations: mock.function('linkArtist.relations', () => ({}))
+            .args([undefined, artist1]).next()
+            .args([undefined, artist2]).next()
+            .args([undefined, artist3]),
+
+          data: mock.function('linkArtist.data', () => ({}))
+            .args([artist1]).next()
+            .args([artist2]).next()
+            .args([artist3]),
+
+          // This can be tweaked to return a specific (mocked) template
+          // for each artist if we need to test for slots in the future.
+          generate: mock.function(() => 'artist link')
+            .repeat(3),
+        },
+      })),
+    });
+
+    evaluate({
+      name: 'generateContributionLinks',
+      args: [contributions, config],
+      extraDependencies: evaluate.mock(mock => ({
+        iconifyURL: mock.function(() => 'icon')
+          .args([artist1.urls[0], undefined]).next()
+          .args([artist3.urls[0], undefined]).next()
+          .args([artist3.urls[1], undefined]),
+      })),
+    });
+  });
+
+  await testContentFunctions(t, 'generateContributionLinks (unit 2)', async (t, evaluate) => {
+    const artist1 = {
+      name: 'Clark Powell',
+      urls: ['https://soundcloud.com/plazmataz'],
+    };
+
+    const artist2 = {
+      name: 'Grounder & Scratch',
+      urls: [],
+    };
+
+    const artist3 = {
+      name: '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 config = {
+      showContribution: false,
+      showIcons: false,
+    };
+
+    await evaluate.load({
+      mock: evaluate.mock(mock => ({
+        linkArtist: {
+          relations: mock.function('linkArtist.relations', () => ({}))
+            .args([undefined, artist1]).next()
+            .args([undefined, artist2]).next()
+            .args([undefined, artist3]),
+
+          data: mock.function('linkArtist.data', () => ({}))
+            .args([artist1]).next()
+            .args([artist2]).next()
+            .args([artist3]),
+
+          generate: mock.function(() => 'artist link')
+            .repeat(3),
+        },
+      })),
+    });
+
+    evaluate({
+      name: 'generateContributionLinks',
+      args: [contributions, config],
+      extraDependencies: evaluate.mock(mock => ({
+        iconifyURL: mock.function(() => 'icon')
+          .neverCalled(),
+      })),
+    });
+  });
+});
diff --git a/test/unit/content/dependencies/linkArtist.js b/test/unit/content/dependencies/linkArtist.js
index 6d9e637d..9fceb97d 100644
--- a/test/unit/content/dependencies/linkArtist.js
+++ b/test/unit/content/dependencies/linkArtist.js
@@ -1,7 +1,7 @@
 import t from 'tap';
 import {testContentFunctions} from '../../../lib/content-function.js';
 
-testContentFunctions(t, 'linkArtist', async (t, evaluate) => {
+testContentFunctions(t, 'linkArtist (unit)', async (t, evaluate) => {
   const artistObject = {};
   const linkTemplate = {};