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
|
import t from 'tap';
import thingConstructors from '#things';
const {
Album,
Artist,
Thing,
Track,
TrackGroup,
} = thingConstructors;
function stubAlbum(tracks) {
const album = new Album();
album.trackSections = [
{
tracksByRef: tracks.map(t => Thing.getReference(t)),
},
];
album.trackData = tracks;
return album;
}
function stubTrack() {
const track = new Track();
track.directory = 'foo';
return track;
}
function stubTrackAndAlbum() {
const track = stubTrack();
const album = stubAlbum([track]);
track.albumData = [album];
return {track, album};
}
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 XXX_CLEAR_TRACK_ALBUM_CACHE(track, album) {
// XXX clear cache so change in album's property is reflected
track.albumData = [];
track.albumData = [album];
}
t.test(`Track.color`, t => {
t.plan(3);
const {track, album} = stubTrackAndAlbum();
t.equal(track.color, null,
`color #1: defaults to null`);
album.color = '#abcdef';
XXX_CLEAR_TRACK_ALBUM_CACHE(track, album);
t.equal(track.color, '#abcdef',
`color #2: inherits from album`);
track.color = '#123456';
t.equal(track.color, '#123456',
`color #3: is own value`);
});
t.test(`Track.coverArtDate`, t => {
t.plan(6);
const {track, album} = stubTrackAndAlbum();
const {artist, contribs} = stubArtistAndContribs();
track.coverArtistContribsByRef = contribs;
track.artistData = [artist];
t.equal(track.coverArtDate, null,
`coverArtDate #1: defaults to null`);
album.trackArtDate = new Date('2012-12-12');
XXX_CLEAR_TRACK_ALBUM_CACHE(track, album);
t.same(track.coverArtDate, new Date('2012-12-12'),
`coverArtDate #2: inherits album trackArtDate`);
track.coverArtDate = new Date('2009-09-09');
t.same(track.coverArtDate, new Date('2009-09-09'),
`coverArtDate #3: is own value`);
track.coverArtistContribsByRef = [];
t.equal(track.coverArtDate, null,
`coverArtDate #4: is null if track is missing coverArtists`);
album.trackCoverArtistContribsByRef = contribs;
XXX_CLEAR_TRACK_ALBUM_CACHE(track, album);
t.same(track.coverArtDate, new Date('2009-09-09'),
`coverArtDate #5: is not null if album specifies trackCoverArtistContribs`);
track.disableUniqueCoverArt = true;
t.equal(track.coverArtDate, null,
`coverArtDate #6: is null if track disables unique cover artwork`);
});
t.test(`Track.date`, t => {
t.plan(3);
const {track, album} = stubTrackAndAlbum();
t.equal(track.date, null,
`date #1: defaults to null`);
album.date = new Date('2012-12-12');
XXX_CLEAR_TRACK_ALBUM_CACHE(track, album);
t.same(track.date, album.date,
`date #2: inherits from album`);
track.dateFirstReleased = new Date('2009-09-09');
t.same(track.date, new Date('2009-09-09'),
`date #3: is own dateFirstReleased`);
});
t.test(`Track.hasUniqueCoverArt`, t => {
t.plan(7);
const {track, album} = stubTrackAndAlbum();
const {artist, contribs, badContribs} = stubArtistAndContribs();
track.artistData = [artist];
album.artistData = [artist];
t.equal(track.hasUniqueCoverArt, false,
`hasUniqueCoverArt #1: defaults to false`);
album.trackCoverArtistContribsByRef = contribs;
XXX_CLEAR_TRACK_ALBUM_CACHE(track, album);
t.equal(track.hasUniqueCoverArt, true,
`hasUniqueCoverArt #2: is true if album specifies trackCoverArtistContribs`);
track.disableUniqueCoverArt = true;
t.equal(track.hasUniqueCoverArt, false,
`hasUniqueCoverArt #3: is false if disableUniqueCoverArt is true (1/2)`);
track.disableUniqueCoverArt = false;
album.trackCoverArtistContribsByRef = badContribs;
XXX_CLEAR_TRACK_ALBUM_CACHE(track, album);
t.equal(track.hasUniqueCoverArt, false,
`hasUniqueCoverArt #4: is false if album's trackCoverArtistContribsByRef resolve empty`);
track.coverArtistContribsByRef = contribs;
t.equal(track.hasUniqueCoverArt, true,
`hasUniqueCoverArt #5: is true if track specifies coverArtistContribs`);
track.disableUniqueCoverArt = true;
t.equal(track.hasUniqueCoverArt, false,
`hasUniqueCoverArt #6: is false if disableUniqueCoverArt is true (2/2)`);
track.disableUniqueCoverArt = false;
track.coverArtistContribsByRef = badContribs;
t.equal(track.hasUniqueCoverArt, false,
`hasUniqueCoverArt #7: is false if track's coverArtistContribsByRef resolve empty`);
});
|