« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/snapshot/generateAlbumTrackList.js41
-rw-r--r--test/unit/content/dependencies/generateAlbumTrackList.js40
2 files changed, 81 insertions, 0 deletions
diff --git a/test/snapshot/generateAlbumTrackList.js b/test/snapshot/generateAlbumTrackList.js
new file mode 100644
index 00000000..055f189e
--- /dev/null
+++ b/test/snapshot/generateAlbumTrackList.js
@@ -0,0 +1,41 @@
+import t from 'tap';
+import {testContentFunctions} from '../lib/content-function.js';
+
+testContentFunctions(t, 'generateAlbumTrackList (snapshot)', async (t, evaluate) => {
+  await evaluate.load({
+    mock: {
+      generateAlbumTrackListItem: {
+        extraDependencies: ['html'],
+        data: track => track.name,
+        generate: (name, {html}) =>
+          html.tag('li', `Item: ${name}`),
+      },
+    },
+  });
+
+  const tracks = [
+    {name: 'Track 1', duration: 20},
+    {name: 'Track 2', duration: 30},
+    {name: 'Track 3', duration: 40},
+    {name: 'Track 4', duration: 5},
+  ];
+
+  evaluate.snapshot('basic behavior, with track sections', {
+    name: 'generateAlbumTrackList',
+    args: [{
+      trackSections: [
+        {name: 'First section', tracks: tracks.slice(0, 3)},
+        {name: 'Second section', tracks: tracks.slice(3)},
+      ],
+      tracks,
+    }],
+  });
+
+  evaluate.snapshot('basic behavior, default track section', {
+    name: 'generateAlbumTrackList',
+    args: [{
+      trackSections: [{isDefaultTrackSection: true, tracks}],
+      tracks,
+    }],
+  });
+});
diff --git a/test/unit/content/dependencies/generateAlbumTrackList.js b/test/unit/content/dependencies/generateAlbumTrackList.js
new file mode 100644
index 00000000..80b086ca
--- /dev/null
+++ b/test/unit/content/dependencies/generateAlbumTrackList.js
@@ -0,0 +1,40 @@
+import t from 'tap';
+import {testContentFunctions} from '../../../lib/content-function.js';
+
+testContentFunctions(t, 'generateAlbumTrackList (unit)', async (t, evaluate) => {
+  await evaluate.load({
+    mock: {
+      generateAlbumTrackListItem: {
+        extraDependencies: ['html'],
+        data: track => track.name,
+        generate: (name, {html}) =>
+          html.tag('li', `Item: ${name}`),
+      },
+    },
+  });
+
+  let readDuration = false;
+
+  const track = (name, duration) => ({
+    name,
+    get duration() {
+      readDuration = true;
+      return duration;
+    },
+  });
+
+  const tracks = [
+    track('Track 1', 30),
+    track('Track 2', 15),
+  ];
+
+  evaluate({
+    name: 'generateAlbumTrackList',
+    args: [{
+      trackSections: [{isDefaultTrackSection: true, tracks}],
+      tracks,
+    }],
+  });
+
+  t.notOk(readDuration, 'expect no access to track.duration property');
+});