« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/content/dependencies/generateAlbumTrackListItem.js13
-rw-r--r--tap-snapshots/test/snapshot/generateAlbumTrackList.js.test.cjs4
-rw-r--r--test/snapshot/generateAlbumTrackList.js13
3 files changed, 21 insertions, 9 deletions
diff --git a/src/content/dependencies/generateAlbumTrackListItem.js b/src/content/dependencies/generateAlbumTrackListItem.js
index 794c4201..15aecba0 100644
--- a/src/content/dependencies/generateAlbumTrackListItem.js
+++ b/src/content/dependencies/generateAlbumTrackListItem.js
@@ -24,9 +24,12 @@ export default {
   data(track, album) {
     const data = {};
 
-    data.color = track.color;
     data.duration = track.duration ?? 0;
 
+    if (track.color !== album.color) {
+      data.color = track.color;
+    }
+
     data.showArtists =
       !compareArrays(
         track.artistContribs.map(c => c.who),
@@ -47,8 +50,12 @@ export default {
     const parts = ['trackList.item.withDuration'];
     const options = {};
 
-    options.duration = language.formatDuration(data.duration);
-    options.track = relations.trackLink;
+    options.duration =
+      language.formatDuration(data.duration);
+
+    options.track =
+      relations.trackLink
+        .slot('color', false);
 
     if (data.showArtists) {
       parts.push('withArtists');
diff --git a/tap-snapshots/test/snapshot/generateAlbumTrackList.js.test.cjs b/tap-snapshots/test/snapshot/generateAlbumTrackList.js.test.cjs
index c1248814..59eb4456 100644
--- a/tap-snapshots/test/snapshot/generateAlbumTrackList.js.test.cjs
+++ b/tap-snapshots/test/snapshot/generateAlbumTrackList.js.test.cjs
@@ -10,7 +10,7 @@ exports[`test/snapshot/generateAlbumTrackList.js TAP generateAlbumTrackList (sna
     <li>(0:20) <a href="track/t1/">Track 1</a></li>
     <li>(0:30) <a href="track/t2/">Track 2</a></li>
     <li>(0:40) <a href="track/t3/">Track 3</a></li>
-    <li>(0:05) <a href="track/t4/">Track 4</a> <span class="by">by <a href="artist/apricot/">Apricot</a> and <a href="artist/peach/">Peach</a></span></li>
+    <li style="--primary-color: #ea2e83">(0:05) <a href="track/t4/">Track 4</a> <span class="by">by <a href="artist/apricot/">Apricot</a> and <a href="artist/peach/">Peach</a></span></li>
 </ul>
 `
 
@@ -25,6 +25,6 @@ exports[`test/snapshot/generateAlbumTrackList.js TAP generateAlbumTrackList (sna
         </ul>
     </dd>
     <dt class="content-heading" tabindex="0">Second section (0:05):</dt>
-    <dd><ul><li>(0:05) <a href="track/t4/">Track 4</a> <span class="by">by <a href="artist/apricot/">Apricot</a> and <a href="artist/peach/">Peach</a></span></li></ul></dd>
+    <dd><ul><li style="--primary-color: #ea2e83">(0:05) <a href="track/t4/">Track 4</a> <span class="by">by <a href="artist/apricot/">Apricot</a> and <a href="artist/peach/">Peach</a></span></li></ul></dd>
 </dl>
 `
diff --git a/test/snapshot/generateAlbumTrackList.js b/test/snapshot/generateAlbumTrackList.js
index 3fc95716..ea3cfef3 100644
--- a/test/snapshot/generateAlbumTrackList.js
+++ b/test/snapshot/generateAlbumTrackList.js
@@ -13,16 +13,20 @@ testContentFunctions(t, 'generateAlbumTrackList (snapshot)', async (t, evaluate)
     {who: {name: 'Peach', directory: 'peach', urls: ['https://peach.bandcamp.com/']}},
   ];
 
+  const color1 = '#fb07ff';
+  const color2 = '#ea2e83';
+
   const tracks = [
-    {name: 'Track 1', directory: 't1', duration: 20, artistContribs: contribs1},
-    {name: 'Track 2', directory: 't2', duration: 30, artistContribs: contribs1},
-    {name: 'Track 3', directory: 't3', duration: 40, artistContribs: contribs1},
-    {name: 'Track 4', directory: 't4', duration: 5, artistContribs: contribs2},
+    {name: 'Track 1', directory: 't1', duration: 20, artistContribs: contribs1, color: color1},
+    {name: 'Track 2', directory: 't2', duration: 30, artistContribs: contribs1, color: color1},
+    {name: 'Track 3', directory: 't3', duration: 40, artistContribs: contribs1, color: color1},
+    {name: 'Track 4', directory: 't4', duration: 5, artistContribs: contribs2, color: color2},
   ];
 
   evaluate.snapshot('basic behavior, with track sections', {
     name: 'generateAlbumTrackList',
     args: [{
+      color: color1,
       artistContribs: contribs1,
       trackSections: [
         {name: 'First section', tracks: tracks.slice(0, 3)},
@@ -35,6 +39,7 @@ testContentFunctions(t, 'generateAlbumTrackList (snapshot)', async (t, evaluate)
   evaluate.snapshot('basic behavior, default track section', {
     name: 'generateAlbumTrackList',
     args: [{
+      color: color1,
       artistContribs: contribs1,
       trackSections: [{isDefaultTrackSection: true, tracks}],
       tracks,