« get me outta code hell

test: Album.tracks (unit) - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/test/unit/data/things
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-09-08 11:30:27 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-08 11:32:01 -0300
commitf82c43f594ee5eadde34c05d45b9ce7a14301a87 (patch)
tree57fb0b984b562cea1d81ed2ffe8a274ad73fc868 /test/unit/data/things
parent3ebe98d51d94a3e5277d65b2a4d2b5b433449214 (diff)
test: Album.tracks (unit)
Diffstat (limited to 'test/unit/data/things')
-rw-r--r--test/unit/data/things/album.js50
1 files changed, 49 insertions, 1 deletions
diff --git a/test/unit/data/things/album.js b/test/unit/data/things/album.js
index 42f73082..63d787e5 100644
--- a/test/unit/data/things/album.js
+++ b/test/unit/data/things/album.js
@@ -6,7 +6,6 @@ import thingConstructors from '#things';
 const {
   Album,
   Artist,
-  Thing,
   Track,
 } = thingConstructors;
 
@@ -20,6 +19,13 @@ function stubArtistAndContribs() {
   return {artist, contribs, badContribs};
 }
 
+function stubTrack(directory = 'foo') {
+  const track = new Track();
+  track.directory = directory;
+
+  return track;
+}
+
 t.test(`Album.coverArtDate`, t => {
   t.plan(6);
 
@@ -95,3 +101,45 @@ t.test(`Album.coverArtFileExtension`, t => {
   t.equal(album.coverArtFileExtension, null,
     `Album.coverArtFileExtension #5: is null if coverArtistContribs resolves empty`);
 });
+
+t.test(`Album.tracks`, t => {
+  t.plan(4);
+
+  const album = new Album();
+  const track1 = stubTrack('track1');
+  const track2 = stubTrack('track2');
+  const track3 = stubTrack('track3');
+
+  linkAndBindWikiData({
+    albumData: [album],
+    trackData: [track1, track2, track3],
+  });
+
+  t.same(album.tracks, [],
+    `Album.tracks #1: defaults to empty array`);
+
+  album.trackSections = [
+    {tracks: ['track:track1', 'track:track2', 'track:track3']},
+  ];
+
+  t.same(album.tracks, [track1, track2, track3],
+    `Album.tracks #2: pulls tracks from one track section`);
+
+  album.trackSections = [
+    {tracks: ['track:track1']},
+    {tracks: ['track:track2', 'track:track3']},
+  ];
+
+  t.same(album.tracks, [track1, track2, track3],
+    `Album.tracks #3: pulls tracks from multiple track sections`);
+
+  album.trackSections = [
+    {tracks: ['track:track1', 'track:does-not-exist']},
+    {tracks: ['track:this-one-neither', 'track:track2']},
+    {tracks: ['track:effectively-empty-section']},
+    {tracks: ['track:track3']},
+  ];
+
+  t.same(album.tracks, [track1, track2, track3],
+    `Album.tracks #4: filters out references without matches`);
+});