« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit')
-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`);
+});