« get me outta code hell

test: Track.coverArtFileExtension (unit) - 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-08-31 19:22:54 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-05 21:02:56 -0300
commit6f54b1211b5b07fe747ce4ebafdf917ce7851324 (patch)
treebf6869bee6eaf99c8dd13abe7cbb0618aaa43935
parentf0a94d03d01220ff44c9c7cf610373781dd4c09d (diff)
test: Track.coverArtFileExtension (unit)
-rw-r--r--src/data/things/track.js4
-rw-r--r--test/unit/data/things/track.js60
2 files changed, 63 insertions, 1 deletions
diff --git a/src/data/things/track.js b/src/data/things/track.js
index ad90dd2c..0b34de20 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -90,7 +90,9 @@ export class Track extends Thing {
       Thing.composite.exposeDependencyOrContinue('#album.trackCoverArtFileExtension'),
 
       // Fallback to 'jpg'.
-      Thing.composite.exposeConstant('jpg'),
+      Thing.composite.exposeConstant('jpg', {
+        update: {validate: isFileExtension},
+      }),
     ]),
 
     // Date of cover art release. Like coverArtFileExtension, this represents
diff --git a/test/unit/data/things/track.js b/test/unit/data/things/track.js
index 97d664ee..16162fb7 100644
--- a/test/unit/data/things/track.js
+++ b/test/unit/data/things/track.js
@@ -195,6 +195,66 @@ t.test(`Track.coverArtDate`, t => {
     `coverArtDate #6: is null if track disables unique cover artwork`);
 });
 
+t.test(`Track.coverArtFileExtension`, t => {
+  t.plan(8);
+
+  const {track, album} = stubTrackAndAlbum();
+  const {artist, contribs} = stubArtistAndContribs();
+
+  const {XXX_decacheWikiData} = linkAndBindWikiData({
+    trackData: [track],
+    albumData: [album],
+    artistData: [artist],
+  });
+
+  t.equal(track.coverArtFileExtension, null,
+    `coverArtFileExtension #1: defaults to null`);
+
+  track.coverArtistContribsByRef = contribs;
+
+  t.equal(track.coverArtFileExtension, 'jpg',
+    `coverArtFileExtension #2: is jpg if has cover art and not further specified`);
+
+  track.coverArtistContribsByRef = [];
+
+  album.coverArtistContribsByRef = contribs;
+  XXX_decacheWikiData();
+
+  t.equal(track.coverArtFileExtension, null,
+    `coverArtFileExtension #3: only has value for unique cover art`);
+
+  track.coverArtistContribsByRef = contribs;
+
+  album.trackCoverArtFileExtension = 'png';
+  XXX_decacheWikiData();
+
+  t.equal(track.coverArtFileExtension, 'png',
+    `coverArtFileExtension #4: inherits album trackCoverArtFileExtension (1/2)`);
+
+  track.coverArtFileExtension = 'gif';
+
+  t.equal(track.coverArtFileExtension, 'gif',
+    `coverArtFileExtension #5: is own value (1/2)`);
+
+  track.coverArtistContribsByRef = [];
+
+  album.trackCoverArtistContribsByRef = contribs;
+  XXX_decacheWikiData();
+
+  t.equal(track.coverArtFileExtension, 'gif',
+    `coverArtFileExtension #6: is own value (2/2)`);
+
+  track.coverArtFileExtension = null;
+
+  t.equal(track.coverArtFileExtension, 'png',
+    `coverArtFileExtension #7: inherits album trackCoverArtFileExtension (2/2)`);
+
+  track.disableUniqueCoverArt = true;
+
+  t.equal(track.coverArtFileExtension, null,
+    `coverArtFileExtension #8: is null if track disables unique cover art`);
+});
+
 t.test(`Track.date`, t => {
   t.plan(3);