From b06c194fc02da22564bcb165db33282f411859a3 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 9 Sep 2023 18:31:09 -0300 Subject: data, test: filter out empty track sections Also test unmatched track references. --- src/data/things/album.js | 16 +++++++++++----- test/unit/data/things/album.js | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/data/things/album.js b/src/data/things/album.js index 9ca662a0..7569eb80 100644 --- a/src/data/things/album.js +++ b/src/data/things/album.js @@ -1,6 +1,7 @@ import find from '#find'; -import {stitchArrays} from '#sugar'; +import {empty, stitchArrays} from '#sugar'; import {isDate, isTrackSectionList} from '#validators'; +import {filterMultipleArrays} from '#wiki-data'; import { exitWithoutDependency, @@ -152,20 +153,25 @@ export class Album extends Thing { '#sections.startIndex', ], - transform: (trackSections, { + transform(trackSections, { '#sections.tracks': tracks, '#sections.color': color, '#sections.dateOriginallyReleased': dateOriginallyReleased, '#sections.isDefaultTrackSection': isDefaultTrackSection, '#sections.startIndex': startIndex, - }) => - stitchArrays({ + }) { + filterMultipleArrays( + tracks, color, dateOriginallyReleased, isDefaultTrackSection, startIndex, + tracks => !empty(tracks)); + + return stitchArrays({ tracks, color, dateOriginallyReleased, isDefaultTrackSection, startIndex, - }), + }); + } }, }, ], diff --git a/test/unit/data/things/album.js b/test/unit/data/things/album.js index 240150b0..0695fdb6 100644 --- a/test/unit/data/things/album.js +++ b/test/unit/data/things/album.js @@ -240,7 +240,7 @@ t.test(`Album.tracks`, t => { }); t.test(`Album.trackSections`, t => { - t.plan(5); + t.plan(6); const album = new Album(); const track1 = stubTrack('track1'); @@ -305,6 +305,20 @@ t.test(`Album.trackSections`, t => { {tracks: [track2], isDefaultTrackSection: false}, {tracks: [track3], isDefaultTrackSection: false}, ], `Album.trackSections #5: 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'}, + ]; + + t.match(album.trackSections, [ + {tracks: [track1, track2], color: '#112233'}, + {tracks: [track3], color: '#334455'}, + {tracks: [track4], color: '#778899'}, + ], `Album.trackSections #6: filters out references without matches & empty sections`); }); t.test(`Album.wallpaperFileExtension`, t => { -- cgit 1.3.0-6-gf8a5