« get me outta code hell

data, test: Track.color inherits from track section - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/test/unit/data/things
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-08-26 21:18:43 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-05 21:02:53 -0300
commite6038d8c07971447f444cf597328ca8d9863f8fd (patch)
tree6fac7eb33b4a987e7e8c0415f46de298480b53e9 /test/unit/data/things
parent12b8040b05e81a523ef59ba583dde751206f2e1d (diff)
data, test: Track.color inherits from track section
Diffstat (limited to 'test/unit/data/things')
-rw-r--r--test/unit/data/things/track.js34
1 files changed, 29 insertions, 5 deletions
diff --git a/test/unit/data/things/track.js b/test/unit/data/things/track.js
index dbc8434f..9132376c 100644
--- a/test/unit/data/things/track.js
+++ b/test/unit/data/things/track.js
@@ -97,11 +97,11 @@ t.test(`Track.album`, t => {
 });
 
 t.test(`Track.color`, t => {
-  t.plan(4);
+  t.plan(5);
 
   const {track, album} = stubTrackAndAlbum();
 
-  const {XXX_decacheWikiData} = linkAndBindWikiData({
+  const {wikiData, linkWikiDataArrays, XXX_decacheWikiData} = linkAndBindWikiData({
     albumData: [album],
     trackData: [track],
   });
@@ -110,18 +110,42 @@ t.test(`Track.color`, t => {
     `color #1: defaults to null`);
 
   album.color = '#abcdef';
+  album.trackSections = [{
+    color: '#beeeef',
+    tracksByRef: [Thing.getReference(track)],
+  }];
   XXX_decacheWikiData();
 
+  t.equal(track.color, '#beeeef',
+    `color #2: inherits from track section before album`);
+
+  // Replace the album with a completely fake one. This isn't realistic, since
+  // in correct data, Album.tracks depends on Albums.trackSections and so the
+  // track's album will always have a corresponding track section. But if that
+  // connection breaks for some future reason (with the album still present),
+  // Track.color should still inherit directly from the album.
+  wikiData.albumData = [
+    new Proxy({
+      color: '#abcdef',
+      tracks: [track],
+      trackSections: [
+        {color: '#baaaad', tracks: []},
+      ],
+    }, {getPrototypeOf: () => Album.prototype}),
+  ];
+
+  linkWikiDataArrays();
+
   t.equal(track.color, '#abcdef',
-    `color #2: inherits from album`);
+    `color #3: inherits from album without matching track section`);
 
   track.color = '#123456';
 
   t.equal(track.color, '#123456',
-    `color #3: is own value`);
+    `color #4: is own value`);
 
   t.throws(() => { track.color = '#aeiouw'; }, TypeError,
-    `color #4: must be set to valid color`);
+    `color #5: must be set to valid color`);
 });
 
 t.test(`Track.coverArtDate`, t => {