diff options
-rw-r--r-- | test/unit/data/things/album.js | 181 | ||||
-rw-r--r-- | test/unit/data/things/art-tag.js | 14 | ||||
-rw-r--r-- | test/unit/data/things/track.js | 59 |
3 files changed, 179 insertions, 75 deletions
diff --git a/test/unit/data/things/album.js b/test/unit/data/things/album.js index bf9992ae..d28ab709 100644 --- a/test/unit/data/things/album.js +++ b/test/unit/data/things/album.js @@ -8,6 +8,7 @@ const { ArtTag, Artist, Track, + TrackSection, } = thingConstructors; function stubArtTag(tagName = `Test Art Tag`) { @@ -34,6 +35,15 @@ function stubTrack(directory = 'foo') { return track; } +function stubTrackSection(album, tracks, directory = 'baz') { + const trackSection = new TrackSection(); + trackSection.unqualifiedDirectory = directory; + trackSection.tracks = tracks.map(t => Thing.getReference(t)); + trackSection.ownTrackData = tracks; + trackSection.ownAlbumData = [album]; + return trackSection; +} + t.test(`Album.artTags`, t => { t.plan(3); @@ -237,78 +247,115 @@ t.test(`Album.tracks`, t => { t.plan(5); const album = new Album(); + album.directory = 'foo'; + const track1 = stubTrack('track1'); const track2 = stubTrack('track2'); const track3 = stubTrack('track3'); const tracks = [track1, track2, track3]; - album.ownTrackData = tracks; + const section1 = stubTrackSection(album, [], 'section1'); + const section2 = stubTrackSection(album, [], 'section2'); + const section3 = stubTrackSection(album, [], 'section3'); + const section4 = stubTrackSection(album, [], 'section4'); + const section5 = stubTrackSection(album, [], 'section5'); + const section6 = stubTrackSection(album, [], 'section6'); + const sections = [section1, section2, section3, section4, section5, section6]; for (const track of tracks) { track.albumData = [album]; } + for (const section of sections) { + section.ownAlbumData = [album]; + } + t.same(album.tracks, [], `Album.tracks #1: defaults to empty array`); - album.trackSections = [ - {tracks: ['track:track1', 'track:track2', 'track:track3']}, - ]; + section1.tracks = ['track:track1', 'track:track2', 'track:track3']; + section1.ownTrackData = [track1, track2, track3]; + + album.trackSections = [section1]; 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']}, - ]; + section1.tracks = ['track:track1']; + section2.tracks = ['track:track2', 'track:track3']; + + section1.ownTrackData = [track1]; + section2.ownTrackData = [track2, track3]; + + album.trackSections = [section1, section2]; 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']}, - ]; + section1.tracks = ['track:track1', 'track:does-not-exist']; + section2.tracks = ['track:this-one-neither', 'track:track2']; + section3.tracks = ['track:effectively-empty-section']; + section4.tracks = ['track:track3']; + + section1.ownTrackData = [track1]; + section2.ownTrackData = [track2]; + section3.ownTrackData = []; + section4.ownTrackData = [track3]; + + album.trackSections = [section1, section2, section3, section4]; t.same(album.tracks, [track1, track2, track3], `Album.tracks #4: filters out references without matches`); - album.trackSections = [ - {tracks: ['track:track1']}, - {}, - {tracks: ['track:track2']}, - {}, - {}, - {tracks: ['track:track3']}, - ]; + section1.tracks = ['track:track1']; + section2.tracks = []; + section3.tracks = ['track:track2']; + section4.tracks = []; + section5.tracks = []; + section6.tracks = ['track:track3']; + + section1.ownTrackData = [track1]; + section2.ownTrackData = []; + section3.ownTrackData = [track2]; + section4.ownTrackData = []; + section5.ownTrackData = []; + section6.ownTrackData = [track3]; + + album.trackSections = [section1, section2, section3, section4, section5, section6]; t.same(album.tracks, [track1, track2, track3], - `Album.tracks #5: skips missing tracks property`); + `Album.tracks #5: skips empty track sections`); }); t.test(`Album.trackSections`, t => { t.plan(7); const album = new Album(); + const track1 = stubTrack('track1'); const track2 = stubTrack('track2'); const track3 = stubTrack('track3'); const track4 = stubTrack('track4'); const tracks = [track1, track2, track3, track4]; - album.ownTrackData = tracks; + const section1 = stubTrackSection(album, [], 'section1'); + const section2 = stubTrackSection(album, [], 'section2'); + const section3 = stubTrackSection(album, [], 'section3'); + const section4 = stubTrackSection(album, [], 'section4'); + const section5 = stubTrackSection(album, [], 'section5'); + const sections = [section1, section2, section3, section4, section5]; for (const track of tracks) { track.albumData = [album]; } - album.trackSections = [ - {tracks: ['track:track1', 'track:track2']}, - {tracks: ['track:track3', 'track:track4']}, - ]; + section1.tracks = ['track:track1', 'track:track2']; + section2.tracks = ['track:track3', 'track:track4']; + + section1.ownTrackData = [track1, track2]; + section2.ownTrackData = [track3, track4]; + + album.trackSections = [section1, section2]; t.match(album.trackSections, [ {tracks: [track1, track2]}, @@ -320,11 +367,18 @@ t.test(`Album.trackSections`, t => { {tracks: [track3, track4], startIndex: 2}, ], `Album.trackSections #2: exposes startIndex`); - album.trackSections = [ - {name: 'First section', tracks: ['track:track1']}, - {name: 'Second section', tracks: ['track:track2']}, - {tracks: ['track:track3']}, - ]; + section1.tracks = ['track:track1']; + section2.tracks = ['track:track2']; + section3.tracks = ['track:track3']; + + section1.ownTrackData = [track1]; + section2.ownTrackData = [track2]; + section3.ownTrackData = [track3]; + + section1.name = 'First section'; + section2.name = 'Second section'; + + album.trackSections = [section1, section2, section3]; t.match(album.trackSections, [ {name: 'First section', tracks: [track1]}, @@ -334,11 +388,11 @@ t.test(`Album.trackSections`, t => { album.color = '#123456'; - album.trackSections = [ - {tracks: ['track:track1'], color: null}, - {tracks: ['track:track2'], color: '#abcdef'}, - {tracks: ['track:track3'], color: null}, - ]; + section2.color = '#abcdef'; + + // XXX_decacheWikiData + album.trackSections = []; + album.trackSections = [section1, section2, section3]; t.match(album.trackSections, [ {tracks: [track1], color: '#123456'}, @@ -346,11 +400,11 @@ t.test(`Album.trackSections`, t => { {tracks: [track3], color: '#123456'}, ], `Album.trackSections #4: exposes color, inherited from album`); - album.trackSections = [ - {tracks: ['track:track1'], dateOriginallyReleased: null}, - {tracks: ['track:track2'], dateOriginallyReleased: new Date('2009-04-11')}, - {tracks: ['track:track3'], dateOriginallyReleased: null}, - ]; + section2.dateOriginallyReleased = new Date('2009-04-11'); + + // XXX_decacheWikiData + album.trackSections = []; + album.trackSections = [section1, section2, section3]; t.match(album.trackSections, [ {tracks: [track1], dateOriginallyReleased: null}, @@ -358,11 +412,12 @@ t.test(`Album.trackSections`, t => { {tracks: [track3], dateOriginallyReleased: null}, ], `Album.trackSections #5: exposes dateOriginallyReleased, if present`); - album.trackSections = [ - {tracks: ['track:track1'], isDefaultTrackSection: true}, - {tracks: ['track:track2'], isDefaultTrackSection: false}, - {tracks: ['track:track3'], isDefaultTrackSection: null}, - ]; + section1.isDefaultTrackSection = true; + section2.isDefaultTrackSection = false; + + // XXX_decacheWikiData + album.trackSections = []; + album.trackSections = [section1, section2, section3]; t.match(album.trackSections, [ {tracks: [track1], isDefaultTrackSection: true}, @@ -370,19 +425,33 @@ t.test(`Album.trackSections`, t => { {tracks: [track3], isDefaultTrackSection: false}, ], `Album.trackSections #6: exposes isDefaultTrackSection, defaults to false`); - album.trackSections = [ - {tracks: ['track:track1', 'track:track2', 'track:snooping'], color: '#112233'}, - {tracks: ['track:track3', 'track:as-usual'], color: '#334455'}, - {tracks: [], color: '#bbbbba'}, - {tracks: ['track:icy', 'track:chilly', 'track:frigid'], color: '#556677'}, - {tracks: ['track:track4'], color: '#778899'}, - ]; + section1.tracks = ['track:track1', 'track:track2', 'track:snooping']; + section2.tracks = ['track:track3', 'track:as-usual']; + section3.tracks = []; + section4.tracks = ['track:icy', 'track:chilly', 'track:frigid']; + section5.tracks = ['track:track4']; + + section1.ownTrackData = [track1, track2]; + section2.ownTrackData = [track3]; + section3.ownTrackData = []; + section4.ownTrackData = []; + section5.ownTrackData = [track4]; + + section1.color = '#112233'; + section2.color = '#334455'; + section3.color = '#bbbbba'; + section4.color = '#556677'; + section5.color = '#778899'; + + album.trackSections = [section1, section2, section3, section4, section5]; t.match(album.trackSections, [ {tracks: [track1, track2], color: '#112233'}, {tracks: [track3], color: '#334455'}, + {tracks: [], color: '#bbbbba'}, + {tracks: [], color: '#556677'}, {tracks: [track4], color: '#778899'}, - ], `Album.trackSections #7: filters out references without matches & empty sections`); + ], `Album.trackSections #7: filters out references without matches, keeps empty sections`); }); t.test(`Album.wallpaperFileExtension`, t => { diff --git a/test/unit/data/things/art-tag.js b/test/unit/data/things/art-tag.js index 836bb1c3..427b357b 100644 --- a/test/unit/data/things/art-tag.js +++ b/test/unit/data/things/art-tag.js @@ -8,18 +8,28 @@ const { Artist, ArtTag, Track, + trackSection, } = thingConstructors; function stubAlbum(tracks, directory = 'bar') { const album = new Album(); album.directory = directory; - const trackRefs = tracks.map(t => Thing.getReference(t)); - album.trackSections = [{tracks: trackRefs}]; + const trackSection = stubTrackSection(album, tracks); + album.trackSections = [trackSection]; return album; } +function stubTrackSection(album, tracks, directory = 'baz') { + const trackSection = new TrackSection(); + trackSection.unqualifiedDirectory = directory; + trackSection.tracks = tracks.map(t => Thing.getReference(t)); + trackSection.ownTrackData = tracks; + trackSection.ownAlbumData = [album]; + return trackSection; +} + function stubTrack(directory = 'foo') { const track = new Track(); track.directory = directory; diff --git a/test/unit/data/things/track.js b/test/unit/data/things/track.js index 14d724bf..644d21ce 100644 --- a/test/unit/data/things/track.js +++ b/test/unit/data/things/track.js @@ -11,18 +11,28 @@ const { FlashAct, Thing, Track, + TrackSection, } = thingConstructors; function stubAlbum(tracks, directory = 'bar') { const album = new Album(); album.directory = directory; - const trackRefs = tracks.map(t => Thing.getReference(t)); - album.trackSections = [{tracks: trackRefs}]; + const trackSection = stubTrackSection(album, tracks); + album.trackSections = [trackSection]; return album; } +function stubTrackSection(album, tracks, directory = 'baz') { + const trackSection = new TrackSection(); + trackSection.unqualifiedDirectory = directory; + trackSection.tracks = tracks.map(t => Thing.getReference(t)); + trackSection.ownTrackData = tracks; + trackSection.ownAlbumData = [album]; + return trackSection; +} + function stubTrack(directory = 'foo') { const track = new Track(); track.directory = directory; @@ -81,16 +91,22 @@ t.test(`Track.album`, t => { const track2 = stubTrack('track2'); const album1 = new Album(); const album2 = new Album(); + const section1 = new TrackSection(); + const section2 = new TrackSection(); t.equal(track1.album, null, `album #1: defaults to null`); track1.albumData = [album1, album2]; track2.albumData = [album1, album2]; - album1.ownTrackData = [track1, track2]; - album2.ownTrackData = [track1, track2]; - album1.trackSections = [{tracks: ['track:track1']}]; - album2.trackSections = [{tracks: ['track:track2']}]; + section1.ownTrackData = [track1]; + section2.ownTrackData = [track2]; + section1.ownAlbumData = [album1]; + section2.ownAlbumData = [album2]; + section1.tracks = ['track:track1']; + section2.tracks = ['track:track2']; + album1.trackSections = [section1]; + album2.trackSections = [section2]; t.equal(track1.album, album1, `album #2: is album when album's trackSections matches track`); @@ -105,21 +121,28 @@ t.test(`Track.album`, t => { t.equal(track1.album, null, `album #4: is null when track missing albumData`); - album1.ownTrackData = []; - track1.albumData = [album1, album2]; + section1.ownTrackData = []; + + // XXX_decacheWikiData + album1.trackSections = []; + album1.trackSections = [section1]; + track1.albumData = []; + track1.albumData = [album2, album1]; t.equal(track1.album, null, - `album #5: is null when album missing ownTrackData`); + `album #5: is null when album track section missing ownTrackData`); - album1.ownTrackData = [track1, track2]; - album1.trackSections = [{tracks: ['track:track2']}]; + section1.ownTrackData = [track2]; + section1.tracks = ['track:track2']; // XXX_decacheWikiData + album1.trackSections = []; + album1.trackSections = [section1]; track1.albumData = []; - track1.albumData = [album1, album2]; + track1.albumData = [album2, album1]; t.equal(track1.album, null, - `album #6: is null when album's trackSections don't match track`); + `album #6: is null when album track section doesn't match track`); }); t.test(`Track.alwaysReferenceByDirectory`, t => { @@ -285,11 +308,13 @@ t.test(`Track.color`, t => { t.equal(track.color, null, `color #1: defaults to null`); + const section = stubTrackSection(album, [track]); + album.color = '#abcdef'; - album.trackSections = [{ - color: '#beeeef', - tracks: [Thing.getReference(track)], - }]; + section.color = '#beeeef'; + + album.trackSections = [section]; + XXX_decacheWikiData(); t.equal(track.color, '#beeeef', |