« get me outta code hell

album.js « things « data « unit « test - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/test/unit/data/things/album.js
blob: 5a1261a4b8e261c55f73cb0f34f5b5cbd8135dfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
import t from 'tap';

import {linkAndBindWikiData} from '#test-lib';
import thingConstructors from '#things';

const {
  Album,
  Artist,
  Track,
} = thingConstructors;

function stubArtistAndContribs() {
  const artist = new Artist();
  artist.name = `Test Artist`;

  const contribs = [{who: `Test Artist`, what: null}];
  const badContribs = [{who: `Figment of Your Imagination`, what: null}];

  return {artist, contribs, badContribs};
}

function stubTrack(directory = 'foo') {
  const track = new Track();
  track.directory = directory;

  return track;
}

t.test(`Album.bannerDimensions`, t => {
  t.plan(4);

  const album = new Album();
  const {artist, contribs, badContribs} = stubArtistAndContribs();

  linkAndBindWikiData({
    albumData: [album],
    artistData: [artist],
  });

  t.equal(album.bannerDimensions, null,
    `Album.bannerDimensions #1: defaults to null`);

  album.bannerDimensions = [1200, 275];

  t.equal(album.bannerDimensions, null,
    `Album.bannerDimensions #2: is null if bannerArtistContribs empty`);

  album.bannerArtistContribs = badContribs;

  t.equal(album.bannerDimensions, null,
    `Album.bannerDimensions #3: is null if bannerArtistContribs resolves empty`);

  album.bannerArtistContribs = contribs;

  t.same(album.bannerDimensions, [1200, 275],
    `Album.bannerDimensions #4: is own value`);
});

t.test(`Album.bannerFileExtension`, t => {
  t.plan(5);

  const album = new Album();
  const {artist, contribs, badContribs} = stubArtistAndContribs();

  linkAndBindWikiData({
    albumData: [album],
    artistData: [artist],
  });

  t.equal(album.bannerFileExtension, null,
    `Album.bannerFileExtension #1: defaults to null`);

  album.bannerFileExtension = 'png';

  t.equal(album.bannerFileExtension, null,
    `Album.bannerFileExtension #2: is null if bannerArtistContribs empty`);

  album.bannerArtistContribs = badContribs;

  t.equal(album.bannerFileExtension, null,
    `Album.bannerFileExtension #3: is null if bannerArtistContribs resolves empty`);

  album.bannerArtistContribs = contribs;

  t.equal(album.bannerFileExtension, 'png',
    `Album.bannerFileExtension #4: is own value`);

  album.bannerFileExtension = null;

  t.equal(album.bannerFileExtension, 'jpg',
    `Album.bannerFileExtension #5: defaults to jpg`);
});

t.test(`Album.bannerStyle`, t => {
  t.plan(4);

  const album = new Album();
  const {artist, contribs, badContribs} = stubArtistAndContribs();

  linkAndBindWikiData({
    albumData: [album],
    artistData: [artist],
  });

  t.equal(album.bannerStyle, null,
    `Album.bannerStyle #1: defaults to null`);

  album.bannerStyle = `opacity: 0.5`;

  t.equal(album.bannerStyle, null,
    `Album.bannerStyle #2: is null if bannerArtistContribs empty`);

  album.bannerArtistContribs = badContribs;

  t.equal(album.bannerStyle, null,
    `Album.bannerStyle #3: is null if bannerArtistContribs resolves empty`);

  album.bannerArtistContribs = contribs;

  t.equal(album.bannerStyle, `opacity: 0.5`,
    `Album.bannerStyle #4: is own value`);
});

t.test(`Album.coverArtDate`, t => {
  t.plan(6);

  const album = new Album();
  const {artist, contribs, badContribs} = stubArtistAndContribs();

  linkAndBindWikiData({
    albumData: [album],
    artistData: [artist],
  });

  t.equal(album.coverArtDate, null,
    `Album.coverArtDate #1: defaults to null`);

  album.date = new Date('2012-10-25');

  t.equal(album.coverArtDate, null,
    `Album.coverArtDate #2: is null if coverArtistContribs empty (1/2)`);

  album.coverArtDate = new Date('2011-04-13');

  t.equal(album.coverArtDate, null,
    `Album.coverArtDate #3: is null if coverArtistContribs empty (2/2)`);

  album.coverArtistContribs = contribs;

  t.same(album.coverArtDate, new Date('2011-04-13'),
    `Album.coverArtDate #4: is own value`);

  album.coverArtDate = null;

  t.same(album.coverArtDate, new Date(`2012-10-25`),
    `Album.coverArtDate #5: inherits album release date`);

  album.coverArtistContribs = badContribs;

  t.equal(album.coverArtDate, null,
    `Album.coverArtDate #6: is null if coverArtistContribs resolves empty`);
});

t.test(`Album.coverArtFileExtension`, t => {
  t.plan(5);

  const album = new Album();
  const {artist, contribs, badContribs} = stubArtistAndContribs();

  linkAndBindWikiData({
    albumData: [album],
    artistData: [artist],
  });

  t.equal(album.coverArtFileExtension, null,
    `Album.coverArtFileExtension #1: is null if coverArtistContribs empty (1/2)`);

  album.coverArtFileExtension = 'png';

  t.equal(album.coverArtFileExtension, null,
    `Album.coverArtFileExtension #2: is null if coverArtistContribs empty (2/2)`);

  album.coverArtFileExtension = null;
  album.coverArtistContribs = contribs;

  t.equal(album.coverArtFileExtension, 'jpg',
    `Album.coverArtFileExtension #3: defaults to jpg`);

  album.coverArtFileExtension = 'png';

  t.equal(album.coverArtFileExtension, 'png',
    `Album.coverArtFileExtension #4: is own value`);

  album.coverArtistContribs = badContribs;

  t.equal(album.coverArtFileExtension, null,
    `Album.coverArtFileExtension #5: is null if coverArtistContribs resolves empty`);
});

t.test(`Album.tracks`, t => {
  t.plan(5);

  const album = new Album();
  const track1 = stubTrack('track1');
  const track2 = stubTrack('track2');
  const track3 = stubTrack('track3');
  const tracks = [track1, track2, track3];

  album.ownTrackData = tracks;

  for (const track of tracks) {
    track.albumData = [album];
  }

  t.same(album.tracks, [],
    `Album.tracks #1: defaults to empty array`);

  album.trackSections = [
    {tracks: ['track:track1', 'track:track2', 'track:track3']},
  ];

  t.same(album.tracks, [track1, track2, track3],
    `Album.tracks #2: pulls tracks from one track section`);

  album.trackSections = [
    {tracks: ['track:track1']},
    {tracks: ['track:track2', 'track:track3']},
  ];

  t.same(album.tracks, [track1, track2, track3],
    `Album.tracks #3: pulls tracks from multiple track sections`);

  album.trackSections = [
    {tracks: ['track:track1', 'track:does-not-exist']},
    {tracks: ['track:this-one-neither', 'track:track2']},
    {tracks: ['track:effectively-empty-section']},
    {tracks: ['track:track3']},
  ];

  t.same(album.tracks, [track1, track2, track3],
    `Album.tracks #4: filters out references without matches`);

  album.trackSections = [
    {tracks: ['track:track1']},
    {},
    {tracks: ['track:track2']},
    {},
    {},
    {tracks: ['track:track3']},
  ];

  t.same(album.tracks, [track1, track2, track3],
    `Album.tracks #5: skips missing tracks property`);
});

t.test(`Album.trackSections`, t => {
  t.plan(7);

  const album = new Album();
  const track1 = stubTrack('track1');
  const track2 = stubTrack('track2');
  const track3 = stubTrack('track3');
  const track4 = stubTrack('track4');
  const tracks = [track1, track2, track3, track4];

  album.ownTrackData = tracks;

  for (const track of tracks) {
    track.albumData = [album];
  }

  album.trackSections = [
    {tracks: ['track:track1', 'track:track2']},
    {tracks: ['track:track3', 'track:track4']},
  ];

  t.match(album.trackSections, [
    {tracks: [track1, track2]},
    {tracks: [track3, track4]},
  ], `Album.trackSections #1: exposes tracks`);

  t.match(album.trackSections, [
    {tracks: [track1, track2], startIndex: 0},
    {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 = [
    {tracks: ['track:track1'], color: null},
    {tracks: ['track:track2'], color: '#abcdef'},
    {tracks: ['track:track3'], color: null},
  ];

  t.match(album.trackSections, [
    {tracks: [track1], color: '#123456'},
    {tracks: [track2], color: '#abcdef'},
    {tracks: [track3], color: '#123456'},
  ], `Album.trackSections #4: exposes color, inherited from album`);

  album.trackSections = [
    {tracks: ['track:track1'], dateOriginallyReleased: null},
    {tracks: ['track:track2'], dateOriginallyReleased: new Date('2009-04-11')},
    {tracks: ['track:track3'], dateOriginallyReleased: null},
  ];

  t.match(album.trackSections, [
    {tracks: [track1], dateOriginallyReleased: null},
    {tracks: [track2], dateOriginallyReleased: new Date('2009-04-11')},
    {tracks: [track3], dateOriginallyReleased: null},
  ], `Album.trackSections #5: exposes dateOriginallyReleased, if present`);

  album.trackSections = [
    {tracks: ['track:track1'], isDefaultTrackSection: true},
    {tracks: ['track:track2'], isDefaultTrackSection: false},
    {tracks: ['track:track3'], isDefaultTrackSection: null},
  ];

  t.match(album.trackSections, [
    {tracks: [track1], isDefaultTrackSection: true},
    {tracks: [track2], isDefaultTrackSection: false},
    {tracks: [track3], isDefaultTrackSection: false},
  ], `Album.trackSections #6: 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 #7: filters out references without matches & empty sections`);
});

t.test(`Album.wallpaperFileExtension`, t => {
  t.plan(5);

  const album = new Album();
  const {artist, contribs, badContribs} = stubArtistAndContribs();

  linkAndBindWikiData({
    albumData: [album],
    artistData: [artist],
  });

  t.equal(album.wallpaperFileExtension, null,
    `Album.wallpaperFileExtension #1: defaults to null`);

  album.wallpaperFileExtension = 'png';

  t.equal(album.wallpaperFileExtension, null,
    `Album.wallpaperFileExtension #2: is null if wallpaperArtistContribs empty`);

  album.wallpaperArtistContribs = contribs;

  t.equal(album.wallpaperFileExtension, 'png',
    `Album.wallpaperFileExtension #3: is own value`);

  album.wallpaperFileExtension = null;

  t.equal(album.wallpaperFileExtension, 'jpg',
    `Album.wallpaperFileExtension #4: defaults to jpg`);

  album.wallpaperArtistContribs = badContribs;

  t.equal(album.wallpaperFileExtension, null,
    `Album.wallpaperFileExtension #5: is null if wallpaperArtistContribs resolves empty`);
});

t.test(`Album.wallpaperStyle`, t => {
  t.plan(4);

  const album = new Album();
  const {artist, contribs, badContribs} = stubArtistAndContribs();

  linkAndBindWikiData({
    albumData: [album],
    artistData: [artist],
  });

  t.equal(album.wallpaperStyle, null,
    `Album.wallpaperStyle #1: defaults to null`);

  album.wallpaperStyle = `opacity: 0.5`;

  t.equal(album.wallpaperStyle, null,
    `Album.wallpaperStyle #2: is null if wallpaperArtistContribs empty`);

  album.wallpaperArtistContribs = badContribs;

  t.equal(album.wallpaperStyle, null,
    `Album.wallpaperStyle #3: is null if wallpaperArtistContribs resolves empty`);

  album.wallpaperArtistContribs = contribs;

  t.equal(album.wallpaperStyle, `opacity: 0.5`,
    `Album.wallpaperStyle #4: is own value`);
});