« get me outta code hell

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:
Diffstat (limited to 'test/snapshot')
-rw-r--r--test/snapshot/generateAdditionalFilesList.js63
-rw-r--r--test/snapshot/generateAdditionalFilesShortcut.js36
-rw-r--r--test/snapshot/generateAlbumTrackListItem.js66
-rw-r--r--test/snapshot/generateContributionLinks.js55
-rw-r--r--test/snapshot/image.js92
-rw-r--r--test/snapshot/linkArtist.js30
-rw-r--r--test/snapshot/linkExternal.js57
-rw-r--r--test/snapshot/linkExternalFlash.js24
-rw-r--r--test/snapshot/linkTemplate.js33
9 files changed, 456 insertions, 0 deletions
diff --git a/test/snapshot/generateAdditionalFilesList.js b/test/snapshot/generateAdditionalFilesList.js
new file mode 100644
index 00000000..0c27ad19
--- /dev/null
+++ b/test/snapshot/generateAdditionalFilesList.js
@@ -0,0 +1,63 @@
+import t from 'tap';
+import {testContentFunctions} from '../lib/content-function.js';
+
+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',
+          ],
+        },
+      ],
+    ],
+    postprocess: template => template
+      .slot('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',
+      })
+      .slot('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/generateAdditionalFilesShortcut.js b/test/snapshot/generateAdditionalFilesShortcut.js
new file mode 100644
index 00000000..0ca777b4
--- /dev/null
+++ b/test/snapshot/generateAdditionalFilesShortcut.js
@@ -0,0 +1,36 @@
+import t from 'tap';
+import {testContentFunctions} from '../lib/content-function.js';
+
+testContentFunctions(t, 'generateAdditionalFilesShortcut (snapshot)', async (t, evaluate) => {
+  await evaluate.load();
+
+  evaluate.snapshot('no additional files', {
+    name: 'generateAdditionalFilesShortcut',
+    args: [[]],
+  });
+
+  evaluate.snapshot('basic behavior', {
+    name: 'generateAdditionalFilesShortcut',
+    args: [
+      [
+        {
+          title: 'SBURB Wallpaper',
+          files: [
+            'sburbwp_1280x1024.jpg',
+            'sburbwp_1440x900.jpg',
+            'sburbwp_1920x1080.jpg',
+          ],
+        },
+        {
+          title: 'Alternate Covers',
+          description: 'This is just an example description.',
+          files: [
+            'Homestuck_Vol4_alt1.jpg',
+            'Homestuck_Vol4_alt2.jpg',
+            'Homestuck_Vol4_alt3.jpg',
+          ],
+        },
+      ],
+    ],
+  });
+});
diff --git a/test/snapshot/generateAlbumTrackListItem.js b/test/snapshot/generateAlbumTrackListItem.js
new file mode 100644
index 00000000..e87c6de0
--- /dev/null
+++ b/test/snapshot/generateAlbumTrackListItem.js
@@ -0,0 +1,66 @@
+import t from 'tap';
+import {testContentFunctions} from '../lib/content-function.js';
+
+testContentFunctions(t, 'generateAlbumTrackListItem (snapshot)', async (t, evaluate) => {
+  const artist1 = {directory: 'toby-fox', name: 'Toby Fox', urls: ['https://toby.fox/']};
+  const artist2 = {directory: 'james-roach', name: 'James Roach'};
+  const artist3 = {directory: 'clark-powell', name: 'Clark Powell'};
+  const artist4 = {directory: ''}
+  const albumContribs = [{who: artist1}, {who: artist2}];
+
+  await evaluate.load();
+
+  evaluate.snapshot('basic behavior', {
+    name: 'generateAlbumTrackListItem',
+    args: [
+      {
+        // Just pretend Hiveswap Act 1 OST doesn't have its own Artists field OK?
+        // We test that kind of case later!
+        name: 'Final Spice',
+        directory: 'final-spice',
+        duration: 54,
+        color: '#33cc77',
+        artistContribs: [
+          {who: artist1, what: 'composition & arrangement'},
+          {who: artist2, what: 'arrangement'},
+        ],
+      },
+      {artistContribs: []},
+    ],
+  });
+
+  evaluate.snapshot('zero duration, zero artists', {
+    name: 'generateAlbumTrackListItem',
+    args: [
+      {
+        name: 'You have got to be about the most superficial commentator on con-langues since the idiotic B. Gilson.',
+        directory: 'you-have-got-to-be-about-the-most-superficial-commentator-on-con-langues-since-the-idiotic-b-gilson',
+        duration: 0,
+        artistContribs: [],
+      },
+      {artistContribs: []},
+    ],
+  });
+
+  evaluate.snapshot('hide artists if inherited from album', {
+    name: 'generateAlbumTrackListItem',
+    multiple: [
+      {args: [
+        {directory: 'track1', name: 'Same artists, same order', artistContribs: [{who: artist1}, {who: artist2}]},
+        {artistContribs: albumContribs},
+      ]},
+      {args: [
+        {directory: 'track2', name: 'Same artists, different order', artistContribs: [{who: artist2}, {who: artist1}]},
+        {artistContribs: albumContribs},
+      ]},
+      {args: [
+        {directory: 'track3', name: 'Extra artist', artistContribs: [{who: artist1}, {who: artist2}, {who: artist3}]},
+        {artistContribs: albumContribs},
+      ]},
+      {args: [
+        {directory: 'track4', name: 'Missing artist', artistContribs: [{who: artist1}]},
+        {artistContribs: albumContribs},
+      ]},
+    ],
+  });
+});
diff --git a/test/snapshot/generateContributionLinks.js b/test/snapshot/generateContributionLinks.js
new file mode 100644
index 00000000..3283d3b2
--- /dev/null
+++ b/test/snapshot/generateContributionLinks.js
@@ -0,0 +1,55 @@
+// 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/image.js b/test/snapshot/image.js
new file mode 100644
index 00000000..eeffb849
--- /dev/null
+++ b/test/snapshot/image.js
@@ -0,0 +1,92 @@
+import t from 'tap';
+import {testContentFunctions} from '../lib/content-function.js';
+
+testContentFunctions(t, 'image (snapshot)', async (t, evaluate) => {
+  await evaluate.load();
+
+  const quickSnapshot = (message, opts) =>
+    evaluate.snapshot(message, {
+      name: 'image',
+      extraDependencies: {
+        getSizeOfImageFile: () => 0,
+      },
+      ...opts,
+    });
+
+  quickSnapshot('source via path', {
+    postprocess: template => template
+      .slot('path', ['media.albumCover', 'beyond-canon', 'png']),
+  });
+
+  quickSnapshot('source via src', {
+    postprocess: template => template
+      .slot('src', 'https://example.com/bananas.gif'),
+  });
+
+  quickSnapshot('source missing', {
+    postprocess: template => template
+      .slot('missingSourceContent', 'Example of missing source message.'),
+  });
+
+  quickSnapshot('id without link', {
+    postprocess: template => template
+      .slot('src', 'foobar')
+      .slot('id', 'banana'),
+  });
+
+  quickSnapshot('id with link', {
+    postprocess: template => template
+      .slot('src', 'foobar')
+      .slot('link', true)
+      .slot('id', 'banana'),
+  });
+
+  quickSnapshot('id with square', {
+    postprocess: template => template
+      .slot('src', 'foobar')
+      .slot('square', true)
+      .slot('id', 'banana'),
+  })
+
+  quickSnapshot('width & height', {
+    postprocess: template => template
+      .slot('src', 'foobar')
+      .slot('width', 600)
+      .slot('height', 400),
+  });
+
+  quickSnapshot('square', {
+    postprocess: template => template
+      .slot('src', 'foobar')
+      .slot('square', true),
+  });
+
+  quickSnapshot('lazy with square', {
+    postprocess: template => template
+      .slot('src', 'foobar')
+      .slot('lazy', true)
+      .slot('square', true),
+  });
+
+  quickSnapshot('link with file size', {
+    extraDependencies: {
+      getSizeOfImageFile: () => 10 ** 6,
+    },
+
+    postprocess: template => template
+      .slot('path', ['media.albumCover', 'pingas', 'png'])
+      .slot('link', true),
+  });
+
+  quickSnapshot('content warnings via tags', {
+    args: [
+      [
+        {name: 'Dirk Strider', directory: 'dirk'},
+        {name: 'too cool for school', isContentWarning: true},
+      ],
+    ],
+
+    postprocess: template => template
+      .slot('path', ['media.albumCover', 'beyond-canon', 'png']),
+  })
+});
diff --git a/test/snapshot/linkArtist.js b/test/snapshot/linkArtist.js
new file mode 100644
index 00000000..0451f1c5
--- /dev/null
+++ b/test/snapshot/linkArtist.js
@@ -0,0 +1,30 @@
+import t from 'tap';
+import {testContentFunctions} from '../lib/content-function.js';
+
+testContentFunctions(t, 'linkArtist (snapshot)', async (t, evaluate) => {
+  await evaluate.load();
+
+  evaluate.snapshot('basic behavior', {
+    name: 'linkArtist',
+    args: [
+      {
+        name: `Toby Fox`,
+        directory: `toby-fox`,
+      }
+    ],
+  });
+
+  evaluate.snapshot('prefer short name', {
+    name: 'linkArtist',
+    args: [
+      {
+        name: 'ICCTTCMDMIROTMCWMWFTPFTDDOTARHPOESWGBTWEATFCWSEBTSSFOFG',
+        nameShort: '55gore',
+        directory: '55gore',
+      },
+    ],
+
+    postprocess: v => v
+      .slot('preferShortName', true),
+  });
+});
diff --git a/test/snapshot/linkExternal.js b/test/snapshot/linkExternal.js
new file mode 100644
index 00000000..9661aead
--- /dev/null
+++ b/test/snapshot/linkExternal.js
@@ -0,0 +1,57 @@
+import t from 'tap';
+import {testContentFunctions} from '../lib/content-function.js';
+
+testContentFunctions(t, 'linkExternal (snapshot)', async (t, evaluate) => {
+  await evaluate.load();
+
+  evaluate.snapshot('missing domain (arbitrary local path)', {
+    name: 'linkExternal',
+    args: ['/foo/bar/baz.mp3']
+  });
+
+  evaluate.snapshot('unknown domain (arbitrary world wide web path)', {
+    name: 'linkExternal',
+    args: ['https://snoo.ping.as/usual/i/see/'],
+  });
+
+  evaluate.snapshot('basic domain matches', {
+    name: 'linkExternal',
+    multiple: [
+      {args: ['https://homestuck.bandcamp.com/']},
+      {args: ['https://soundcloud.com/plazmataz']},
+      {args: ['https://aeritus.tumblr.com/']},
+      {args: ['https://twitter.com/awkwarddoesart']},
+      {args: ['https://www.deviantart.com/chesswanderlust-sama']},
+      {args: ['https://en.wikipedia.org/wiki/Haydn_Quartet_(vocal_ensemble)']},
+      {args: ['https://www.poetryfoundation.org/poets/christina-rossetti']},
+      {args: ['https://www.instagram.com/levc_egm/']},
+      {args: ['https://www.patreon.com/CecilyRenns']},
+      {args: ['https://open.spotify.com/artist/63SNNpNOicDzG3LY82G4q3']},
+      {args: ['https://buzinkai.newgrounds.com/']},
+    ],
+  });
+
+  evaluate.snapshot('custom matches - type: album', {
+    name: 'linkExternal',
+    multiple: [
+      {args: ['https://youtu.be/abc', {type: 'album'}]},
+      {args: ['https://youtube.com/watch?v=abc', {type: 'album'}]},
+      {args: ['https://youtube.com/Playlist?list=kweh', {type: 'album'}]},
+
+      // Reuse default when no type specified
+      {args: ['https://youtu.be/abc']},
+      {args: ['https://youtu.be/abc?list=kweh']},
+      {args: ['https://youtube.com/watch?v=abc']},
+      {args: ['https://youtube.com/watch?v=abc&list=kweh']},
+    ],
+  });
+
+  evaluate.snapshot('custom domains for common platforms', {
+    name: 'linkExternal',
+    multiple: [
+      // Just one domain of each platform is OK here
+      {args: ['https://music.solatrus.com/']},
+      {args: ['https://types.pl/']},
+    ],
+  });
+});
diff --git a/test/snapshot/linkExternalFlash.js b/test/snapshot/linkExternalFlash.js
new file mode 100644
index 00000000..7bb86c6a
--- /dev/null
+++ b/test/snapshot/linkExternalFlash.js
@@ -0,0 +1,24 @@
+import t from 'tap';
+import {testContentFunctions} from '../lib/content-function.js';
+
+testContentFunctions(t, 'linkExternalFlash (snapshot)', async (t, evaluate) => {
+  await evaluate.load();
+
+  evaluate.snapshot('basic behavior', {
+    name: 'linkExternalFlash',
+    multiple: [
+      {args: ['https://homestuck.com/story/4109/', {page: '4109'}]},
+      {args: ['https://youtu.be/FDt-SLyEcjI', {page: '4109'}]},
+      {args: ['https://www.bgreco.net/hsflash/006009.html', {page: '4109'}]},
+      {args: ['https://www.newgrounds.com/portal/view/582345', {page: '4109'}]},
+    ],
+  });
+
+  evaluate.snapshot('secret page', {
+    name: 'linkExternalFlash',
+    multiple: [
+      {args: ['https://homestuck.com/story/pony/', {page: 'pony'}]},
+      {args: ['https://youtu.be/USB1pj6hAjU', {page: 'pony'}]},
+    ],
+  });
+});
diff --git a/test/snapshot/linkTemplate.js b/test/snapshot/linkTemplate.js
new file mode 100644
index 00000000..e9a1ccd6
--- /dev/null
+++ b/test/snapshot/linkTemplate.js
@@ -0,0 +1,33 @@
+import t from 'tap';
+import {testContentFunctions} from '../lib/content-function.js';
+
+testContentFunctions(t, 'linkTemplate (snapshot)', async (t, evaluate) => {
+  await evaluate.load();
+
+  evaluate.snapshot('fill many slots', {
+    name: 'linkTemplate',
+
+    extraDependencies: {
+      getColors: c => ({primary: c + 'ff', dim: c + '77'}),
+    },
+
+    postprocess: v => v
+      .slot('color', '#123456')
+      .slot('href', 'https://hsmusic.wiki/media/cool file.pdf')
+      .slot('hash', 'fooey')
+      .slot('attributes', {class: 'dog', id: 'cat1'})
+      .slot('content', 'My Cool Link'),
+  });
+
+  evaluate.snapshot('fill path slot & provide appendIndexHTML', {
+    name: 'linkTemplate',
+
+    extraDependencies: {
+      to: (...path) => '/c*lzone/' + path.join('/') + '/',
+      appendIndexHTML: true,
+    },
+
+    postprocess: v => v
+      .slot('path', ['myCoolPath', 'ham', 'pineapple', 'tomato']),
+  });
+});