« get me outta code hell

data, test: expose track section names - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-10-01 17:58:56 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-10-01 17:58:56 -0300
commita60c8906ed7580a21527c9f96cd0e6e277978263 (patch)
tree71c862e8c366294697afc6b980a8af5591c8e39c
parentd2174a01dda63ba233cbcdf48bb70ed50127d54d (diff)
data, test: expose track section names
-rw-r--r--src/data/composite/things/album/withTrackSections.js11
-rw-r--r--test/unit/data/things/album.js22
2 files changed, 27 insertions, 6 deletions
diff --git a/src/data/composite/things/album/withTrackSections.js b/src/data/composite/things/album/withTrackSections.js
index c99b94d2..baa3cb4a 100644
--- a/src/data/composite/things/album/withTrackSections.js
+++ b/src/data/composite/things/album/withTrackSections.js
@@ -41,6 +41,7 @@ export default templateCompositeFrom({
         'tracks',
         'dateOriginallyReleased',
         'isDefaultTrackSection',
+        'name',
         'color',
       ]),
     }),
@@ -56,6 +57,11 @@ export default templateCompositeFrom({
     }),
 
     fillMissingListItems({
+      list: '#sections.name',
+      fill: input.value('Unnamed Track Section'),
+    }),
+
+    fillMissingListItems({
       list: '#sections.color',
       fill: input.dependency('color'),
     }),
@@ -86,6 +92,7 @@ export default templateCompositeFrom({
     {
       dependencies: [
         '#sections.tracks',
+        '#sections.name',
         '#sections.color',
         '#sections.dateOriginallyReleased',
         '#sections.isDefaultTrackSection',
@@ -94,19 +101,21 @@ export default templateCompositeFrom({
 
       compute: (continuation, {
         '#sections.tracks': tracks,
+        '#sections.name': name,
         '#sections.color': color,
         '#sections.dateOriginallyReleased': dateOriginallyReleased,
         '#sections.isDefaultTrackSection': isDefaultTrackSection,
         '#sections.startIndex': startIndex,
       }) => {
         filterMultipleArrays(
-          tracks, color, dateOriginallyReleased, isDefaultTrackSection, startIndex,
+          tracks, name, color, dateOriginallyReleased, isDefaultTrackSection, startIndex,
           tracks => !empty(tracks));
 
         return continuation({
           ['#trackSections']:
             stitchArrays({
               tracks,
+              name,
               color,
               dateOriginallyReleased,
               isDefaultTrackSection,
diff --git a/test/unit/data/things/album.js b/test/unit/data/things/album.js
index c5f7fa98..76a2b90f 100644
--- a/test/unit/data/things/album.js
+++ b/test/unit/data/things/album.js
@@ -252,7 +252,7 @@ t.test(`Album.tracks`, t => {
 });
 
 t.test(`Album.trackSections`, t => {
-  t.plan(6);
+  t.plan(7);
 
   const album = new Album();
   const track1 = stubTrack('track1');
@@ -280,6 +280,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']},
+  ];
+
+  t.match(album.trackSections, [
+    {name: 'First section', tracks: [track1]},
+    {name: 'Second section', tracks: [track2]},
+    {name: 'Unnamed Track Section', tracks: [track3]},
+  ], `Album.trackSections #3: exposes name, with fallback value`);
+
   album.color = '#123456';
 
   album.trackSections = [
@@ -292,7 +304,7 @@ t.test(`Album.trackSections`, t => {
     {tracks: [track1], color: '#123456'},
     {tracks: [track2], color: '#abcdef'},
     {tracks: [track3], color: '#123456'},
-  ], `Album.trackSections #3: exposes color, inherited from album`);
+  ], `Album.trackSections #4: exposes color, inherited from album`);
 
   album.trackSections = [
     {tracks: ['track:track1'], dateOriginallyReleased: null},
@@ -304,7 +316,7 @@ t.test(`Album.trackSections`, t => {
     {tracks: [track1], dateOriginallyReleased: null},
     {tracks: [track2], dateOriginallyReleased: new Date('2009-04-11')},
     {tracks: [track3], dateOriginallyReleased: null},
-  ], `Album.trackSections #4: exposes dateOriginallyReleased, if present`);
+  ], `Album.trackSections #5: exposes dateOriginallyReleased, if present`);
 
   album.trackSections = [
     {tracks: ['track:track1'], isDefaultTrackSection: true},
@@ -316,7 +328,7 @@ t.test(`Album.trackSections`, t => {
     {tracks: [track1], isDefaultTrackSection: true},
     {tracks: [track2], isDefaultTrackSection: false},
     {tracks: [track3], isDefaultTrackSection: false},
-  ], `Album.trackSections #5: exposes isDefaultTrackSection, defaults to false`);
+  ], `Album.trackSections #6: exposes isDefaultTrackSection, defaults to false`);
 
   album.trackSections = [
     {tracks: ['track:track1', 'track:track2', 'track:snooping'], color: '#112233'},
@@ -330,7 +342,7 @@ t.test(`Album.trackSections`, t => {
     {tracks: [track1, track2], color: '#112233'},
     {tracks: [track3],         color: '#334455'},
     {tracks: [track4],         color: '#778899'},
-  ], `Album.trackSections #6: filters out references without matches & empty sections`);
+  ], `Album.trackSections #7: filters out references without matches & empty sections`);
 });
 
 t.test(`Album.wallpaperFileExtension`, t => {