From f82c43f594ee5eadde34c05d45b9ce7a14301a87 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 8 Sep 2023 11:30:27 -0300 Subject: test: Album.tracks (unit) --- test/unit/data/things/album.js | 50 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'test') 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`); +}); -- cgit 1.3.0-6-gf8a5