« get me outta code hell

test: generateAlbumAdditionalFilesList (snapshot) - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/test/snapshot
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-04-02 17:12:23 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-04-02 17:13:43 -0300
commitbcb0b8ac37d7f256b2b4f82f3c245501486bd52e (patch)
tree5b0b9dd6edd14d805807fa8303627ba61b97b38f /test/snapshot
parent1503827fb835299e4893f0adbb780a277ea2cdde (diff)
test: generateAlbumAdditionalFilesList (snapshot)
Diffstat (limited to 'test/snapshot')
-rw-r--r--test/snapshot/generateAdditionalFilesList.js64
-rw-r--r--test/snapshot/generateAlbumAdditionalFilesList.js80
2 files changed, 80 insertions, 64 deletions
diff --git a/test/snapshot/generateAdditionalFilesList.js b/test/snapshot/generateAdditionalFilesList.js
deleted file mode 100644
index 3ea1c37..0000000
--- a/test/snapshot/generateAdditionalFilesList.js
+++ /dev/null
@@ -1,64 +0,0 @@
-import t from 'tap';
-import {testContentFunctions} from '#test-lib';
-
-testContentFunctions(t, 'generateAdditionalFilesList (snapshot)', async (t, evaluate) => {
-  await evaluate.load();
-
-  evaluate.snapshot('no additional files', {
-    name: 'generateAdditionalFilesList',
-    args: [[]],
-  });
-
-  evaluate.snapshot('basic behavior', {
-    name: 'generateAdditionalFilesList',
-    args: [
-      [
-        {
-          title: 'SBURB Wallpaper',
-          files: [
-            'sburbwp_1280x1024.jpg',
-            'sburbwp_1440x900.jpg',
-            'sburbwp_1920x1080.jpg',
-          ],
-        },
-        {
-          title: 'Fake Section',
-          description: 'Ooo, what happens if there are NO file links provided?',
-          files: [
-            'oops.mp3',
-            'Internet Explorer.gif',
-            'daisy.mp3',
-          ],
-        },
-        {
-          title: 'Alternate Covers',
-          description: 'This is just an example description.',
-          files: [
-            'Homestuck_Vol4_alt1.jpg',
-            'Homestuck_Vol4_alt2.jpg',
-            'Homestuck_Vol4_alt3.jpg',
-          ],
-        },
-      ],
-    ],
-    slots: {
-      fileLinks: {
-        'sburbwp_1280x1024.jpg': 'link to 1280x1024',
-        'sburbwp_1440x900.jpg': 'link to 1440x900',
-        'sburbwp_1920x1080.jpg': null,
-        'Homestuck_Vol4_alt1.jpg': 'link to alt1',
-        'Homestuck_Vol4_alt2.jpg': null,
-        'Homestuck_Vol4_alt3.jpg': 'link to alt3',
-      },
-      fileSizes: {
-        'sburbwp_1280x1024.jpg': 2500,
-        'sburbwp_1440x900.jpg': null,
-        'sburbwp_1920x1080.jpg': null,
-        'Internet Explorer.gif': 1,
-        'Homestuck_Vol4_alt1.jpg': 1234567,
-        'Homestuck_Vol4_alt2.jpg': 1234567,
-        'Homestuck_Vol4_alt3.jpg': 1234567,
-      }
-    },
-  });
-});
diff --git a/test/snapshot/generateAlbumAdditionalFilesList.js b/test/snapshot/generateAlbumAdditionalFilesList.js
new file mode 100644
index 0000000..70a5c0d
--- /dev/null
+++ b/test/snapshot/generateAlbumAdditionalFilesList.js
@@ -0,0 +1,80 @@
+import t from 'tap';
+
+import {testContentFunctions} from '#test-lib';
+import thingConstructors from '#things';
+
+const {Album} = thingConstructors;
+
+testContentFunctions(t, 'generateAlbumAdditionalFilesList (snapshot)', async (t, evaluate) => {
+  const sizeMap = {
+    'sburbwp_1280x1024.jpg': 2500,
+    'sburbwp_1440x900.jpg': null,
+    'sburbwp_1920x1080.jpg': null,
+    'Internet Explorer.gif': 1,
+    'Homestuck_Vol4_alt1.jpg': 1234567,
+    'Homestuck_Vol4_alt2.jpg': 1234567,
+    'Homestuck_Vol4_alt3.jpg': 1234567,
+  };
+
+  const extraDependencies = {
+    getSizeOfAdditionalFile: file =>
+      Object.entries(sizeMap)
+        .find(key => file.includes(key))
+        ?.at(1) ?? null,
+  };
+
+  await evaluate.load();
+
+  const album = new Album();
+  album.directory = 'exciting-album';
+
+  evaluate.snapshot('no additional files', {
+    extraDependencies,
+    name: 'generateAlbumAdditionalFilesList',
+    args: [album, []],
+  });
+
+  try {
+    evaluate.snapshot('basic behavior', {
+      extraDependencies,
+      name: 'generateAlbumAdditionalFilesList',
+      args: [
+        album,
+        [
+          {
+            title: 'SBURB Wallpaper',
+            files: [
+              'sburbwp_1280x1024.jpg',
+              'sburbwp_1440x900.jpg',
+              'sburbwp_1920x1080.jpg',
+            ],
+          },
+          {
+            title: 'Fake Section',
+            description: 'No sizes for these files',
+            files: [
+              'oops.mp3',
+              'Internet Explorer.gif',
+              'daisy.mp3',
+            ],
+          },
+          {
+            title: `Empty Section`,
+            description: `These files haven't been made available.`,
+          },
+          {
+            title: 'Alternate Covers',
+            description: 'This is just an example description.',
+            files: [
+              'Homestuck_Vol4_alt1.jpg',
+              'Homestuck_Vol4_alt2.jpg',
+              'Homestuck_Vol4_alt3.jpg',
+            ],
+          },
+        ],
+      ],
+    });
+  } catch (error) {
+    console.log(error);
+  }
+});