diff options
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/content/dependencies/linkContribution.js | 54 | ||||
-rw-r--r-- | test/unit/data/cacheable-object.js | 2 | ||||
-rw-r--r-- | test/unit/data/composite/things/track/withAlbum.js | 95 | ||||
-rw-r--r-- | test/unit/data/things/album.js | 4 | ||||
-rw-r--r-- | test/unit/data/things/art-tag.js | 4 | ||||
-rw-r--r-- | test/unit/data/things/track.js | 98 | ||||
-rw-r--r-- | test/unit/data/things/validators.js | 16 |
7 files changed, 152 insertions, 121 deletions
diff --git a/test/unit/content/dependencies/linkContribution.js b/test/unit/content/dependencies/linkContribution.js index 9490890..ab45b03 100644 --- a/test/unit/content/dependencies/linkContribution.js +++ b/test/unit/content/dependencies/linkContribution.js @@ -2,27 +2,27 @@ import t from 'tap'; import {testContentFunctions} from '#test-lib'; t.test('generateContributionLinks (unit)', async t => { - const who1 = { + const artist1 = { name: 'Clark Powell', directory: 'clark-powell', urls: ['https://soundcloud.com/plazmataz'], }; - const who2 = { + const artist2 = { name: 'Grounder & Scratch', directory: 'the-big-baddies', urls: [], }; - const who3 = { + const artist3 = { name: 'Toby Fox', directory: 'toby-fox', urls: ['https://tobyfox.bandcamp.com/', 'https://toby.fox/'], }; - const what1 = null; - const what2 = 'Snooping'; - const what3 = 'Arrangement'; + const annotation1 = null; + const annotation2 = 'Snooping'; + const annotation3 = 'Arrangement'; await testContentFunctions(t, 'generateContributionLinks (unit 1)', async (t, evaluate) => { const slots = { @@ -34,14 +34,14 @@ t.test('generateContributionLinks (unit)', async t => { mock: evaluate.mock(mock => ({ linkArtist: { relations: mock.function('linkArtist.relations', () => ({})) - .args([undefined, who1]).next() - .args([undefined, who2]).next() - .args([undefined, who3]), + .args([undefined, artist1]).next() + .args([undefined, artist2]).next() + .args([undefined, artist3]), data: mock.function('linkArtist.data', () => ({})) - .args([who1]).next() - .args([who2]).next() - .args([who3]), + .args([artist1]).next() + .args([artist2]).next() + .args([artist3]), // This can be tweaked to return a specific (mocked) template // for each artist if we need to test for slots in the future. @@ -51,9 +51,9 @@ t.test('generateContributionLinks (unit)', async t => { linkExternalAsIcon: { data: mock.function('linkExternalAsIcon.data', () => ({})) - .args([who1.urls[0]]).next() - .args([who3.urls[0]]).next() - .args([who3.urls[1]]), + .args([artist1.urls[0]]).next() + .args([artist3.urls[0]]).next() + .args([artist3.urls[1]]), generate: mock.function('linkExternalAsIcon.generate', () => 'icon') .repeat(3), @@ -64,9 +64,9 @@ t.test('generateContributionLinks (unit)', async t => { evaluate({ name: 'linkContribution', multiple: [ - {args: [{who: who1, what: what1}]}, - {args: [{who: who2, what: what2}]}, - {args: [{who: who3, what: what3}]}, + {args: [{artist: artist1, annotation: annotation1}]}, + {args: [{artist: artist2, annotation: annotation2}]}, + {args: [{artist: artist3, annotation: annotation3}]}, ], slots, }); @@ -82,14 +82,14 @@ t.test('generateContributionLinks (unit)', async t => { mock: evaluate.mock(mock => ({ linkArtist: { relations: mock.function('linkArtist.relations', () => ({})) - .args([undefined, who1]).next() - .args([undefined, who2]).next() - .args([undefined, who3]), + .args([undefined, artist1]).next() + .args([undefined, artist2]).next() + .args([undefined, artist3]), data: mock.function('linkArtist.data', () => ({})) - .args([who1]).next() - .args([who2]).next() - .args([who3]), + .args([artist1]).next() + .args([artist2]).next() + .args([artist3]), generate: mock.function(() => 'artist link') .repeat(3), @@ -112,9 +112,9 @@ t.test('generateContributionLinks (unit)', async t => { evaluate({ name: 'linkContribution', multiple: [ - {args: [{who: who1, what: what1}]}, - {args: [{who: who2, what: what2}]}, - {args: [{who: who3, what: what3}]}, + {args: [{artist: artist1, annotation: annotation1}]}, + {args: [{artist: artist2, annotation: annotation2}]}, + {args: [{artist: artist3, annotation: annotation3}]}, ], slots, }); diff --git a/test/unit/data/cacheable-object.js b/test/unit/data/cacheable-object.js index 8c31a5b..4b92724 100644 --- a/test/unit/data/cacheable-object.js +++ b/test/unit/data/cacheable-object.js @@ -4,7 +4,7 @@ import CacheableObject from '#cacheable-object'; function newCacheableObject(PD) { return new (class extends CacheableObject { - static propertyDescriptors = PD; + static [CacheableObject.propertyDescriptors] = PD; }); } diff --git a/test/unit/data/composite/things/track/withAlbum.js b/test/unit/data/composite/things/track/withAlbum.js index 30f8cc5..6f50776 100644 --- a/test/unit/data/composite/things/track/withAlbum.js +++ b/test/unit/data/composite/things/track/withAlbum.js @@ -1,5 +1,9 @@ import t from 'tap'; +import '#import-heck'; + +import Thing from '#thing'; + import {compositeFrom, input} from '#composite'; import {exposeConstant, exposeDependency} from '#composite/control-flow'; import {withAlbum} from '#composite/things/track'; @@ -21,9 +25,21 @@ t.test(`withAlbum: basic behavior`, t => { }, }); - const fakeTrack1 = {directory: 'foo'}; - const fakeTrack2 = {directory: 'bar'}; - const fakeAlbum = {directory: 'baz', tracks: [fakeTrack1]}; + const fakeTrack1 = { + [Thing.isThing]: true, + directory: 'foo', + }; + + const fakeTrack2 = { + [Thing.isThing]: true, + directory: 'bar', + }; + + const fakeAlbum = { + [Thing.isThing]: true, + directory: 'baz', + tracks: [fakeTrack1], + }; t.equal( composite.expose.compute({ @@ -40,7 +56,7 @@ t.test(`withAlbum: basic behavior`, t => { null); }); -t.test(`withAlbum: early exit conditions (notFoundMode: null)`, t => { +t.test(`withAlbum: early exit conditions`, t => { t.plan(4); const composite = compositeFrom({ @@ -53,9 +69,21 @@ t.test(`withAlbum: early exit conditions (notFoundMode: null)`, t => { ], }); - const fakeTrack1 = {directory: 'foo'}; - const fakeTrack2 = {directory: 'bar'}; - const fakeAlbum = {directory: 'baz', tracks: [fakeTrack1]}; + const fakeTrack1 = { + [Thing.isThing]: true, + directory: 'foo', + }; + + const fakeTrack2 = { + [Thing.isThing]: true, + directory: 'bar', + }; + + const fakeAlbum = { + [Thing.isThing]: true, + directory: 'baz', + tracks: [fakeTrack1], + }; t.equal( composite.expose.compute({ @@ -89,56 +117,3 @@ t.test(`withAlbum: early exit conditions (notFoundMode: null)`, t => { null, `early exits if albumData is null`); }); - -t.test(`withAlbum: early exit conditions (notFoundMode: exit)`, t => { - t.plan(4); - - const composite = compositeFrom({ - compose: false, - steps: [ - withAlbum({ - notFoundMode: input.value('exit'), - }), - - exposeConstant({ - value: input.value('bimbam'), - }), - ], - }); - - const fakeTrack1 = {directory: 'foo'}; - const fakeTrack2 = {directory: 'bar'}; - const fakeAlbum = {directory: 'baz', tracks: [fakeTrack1]}; - - t.equal( - composite.expose.compute({ - albumData: [fakeAlbum], - this: fakeTrack1, - }), - 'bimbam', - `does not early exit if albumData is present and contains the track`); - - t.equal( - composite.expose.compute({ - albumData: [fakeAlbum], - this: fakeTrack2, - }), - null, - `early exits if albumData is present and does not contain the track`); - - t.equal( - composite.expose.compute({ - albumData: [], - this: fakeTrack1, - }), - null, - `early exits if albumData is empty array`); - - t.equal( - composite.expose.compute({ - albumData: null, - this: fakeTrack1, - }), - null, - `early exits if albumData is null`); -}); diff --git a/test/unit/data/things/album.js b/test/unit/data/things/album.js index 46ea83b..bf9992a 100644 --- a/test/unit/data/things/album.js +++ b/test/unit/data/things/album.js @@ -21,8 +21,8 @@ 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}]; + const contribs = [{artist: `Test Artist`, annotation: null}]; + const badContribs = [{artist: `Figment of Your Imagination`, annotation: null}]; return {artist, contribs, badContribs}; } diff --git a/test/unit/data/things/art-tag.js b/test/unit/data/things/art-tag.js index 561c93e..836bb1c 100644 --- a/test/unit/data/things/art-tag.js +++ b/test/unit/data/things/art-tag.js @@ -43,8 +43,8 @@ function stubArtist(artistName = `Test Artist`) { function stubArtistAndContribs(artistName = `Test Artist`) { const artist = stubArtist(artistName); - const contribs = [{who: artistName, what: null}]; - const badContribs = [{who: `Figment of Your Imagination`, what: null}]; + const contribs = [{artist: artistName, annotation: null}]; + const badContribs = [{artist: `Figment of Your Imagination`, annotation: null}]; return {artist, contribs, badContribs}; } diff --git a/test/unit/data/things/track.js b/test/unit/data/things/track.js index b1c1611..14d724b 100644 --- a/test/unit/data/things/track.js +++ b/test/unit/data/things/track.js @@ -46,8 +46,8 @@ function stubArtist(artistName = `Test Artist`) { function stubArtistAndContribs(artistName = `Test Artist`) { const artist = stubArtist(artistName); - const contribs = [{who: artistName, what: null}]; - const badContribs = [{who: `Figment of Your Imagination`, what: null}]; + const contribs = [{artist: artistName, annotation: null}]; + const badContribs = [{artist: `Figment of Your Imagination`, annotation: null}]; return {artist, contribs, badContribs}; } @@ -122,6 +122,61 @@ t.test(`Track.album`, t => { `album #6: is null when album's trackSections don't match track`); }); +t.test(`Track.alwaysReferenceByDirectory`, t => { + t.plan(7); + + const {track: originalTrack, album: originalAlbum} = + stubTrackAndAlbum('original-track', 'original-album'); + + const {track: rereleaseTrack, album: rereleaseAlbum} = + stubTrackAndAlbum('rerelease-track', 'rerelease-album'); + + originalTrack.name = 'Cowabunga'; + rereleaseTrack.name = 'Cowabunga'; + + originalTrack.dataSourceAlbum = 'album:original-album'; + rereleaseTrack.dataSourceAlbum = 'album:rerelease-album'; + + rereleaseTrack.originalReleaseTrack = 'track:original-track'; + + const {XXX_decacheWikiData} = linkAndBindWikiData({ + albumData: [originalAlbum, rereleaseAlbum], + trackData: [originalTrack, rereleaseTrack], + }); + + t.equal(originalTrack.alwaysReferenceByDirectory, false, + `alwaysReferenceByDirectory #1: defaults to false`); + + t.equal(rereleaseTrack.alwaysReferenceByDirectory, true, + `alwaysReferenceByDirectory #2: is true if rerelease name matches original`); + + rereleaseTrack.name = 'Foo Dog!'; + + t.equal(rereleaseTrack.alwaysReferenceByDirectory, false, + `alwaysReferenceByDirectory #3: is false if rerelease name doesn't match original`); + + rereleaseTrack.name = `COWabunga`; + + t.equal(rereleaseTrack.alwaysReferenceByDirectory, false, + `alwaysReferenceByDirectory #4: is false if rerelease name doesn't match original exactly`); + + rereleaseAlbum.alwaysReferenceTracksByDirectory = true; + XXX_decacheWikiData(); + + t.equal(rereleaseTrack.alwaysReferenceByDirectory, true, + `alwaysReferenceByDirectory #5: is true if album's alwaysReferenceTracksByDirectory is true`); + + rereleaseTrack.alwaysReferenceByDirectory = false; + + t.equal(rereleaseTrack.alwaysReferenceByDirectory, false, + `alwaysReferenceByDirectory #6: doesn't inherit from album if set to false`); + + rereleaseTrack.name = 'Cowabunga'; + + t.equal(rereleaseTrack.alwaysReferenceByDirectory, false, + `alwaysReferenceByDirectory #7: doesn't compare original release name if set to false`); +}); + t.test(`Track.artTags`, t => { t.plan(6); @@ -189,31 +244,31 @@ t.test(`Track.artistContribs`, t => { `artistContribs #1: defaults to empty array`); album.artistContribs = [ - {who: `Artist 1`, what: `composition`}, - {who: `Artist 2`, what: null}, + {artist: `Artist 1`, annotation: `composition`}, + {artist: `Artist 2`, annotation: null}, ]; XXX_decacheWikiData(); t.same(track.artistContribs, - [{who: artist1, what: `composition`}, {who: artist2, what: null}], + [{artist: artist1, annotation: `composition`}, {artist: artist2, annotation: null}], `artistContribs #2: inherits album artistContribs`); track.artistContribs = [ - {who: `Artist 1`, what: `arrangement`}, + {artist: `Artist 1`, annotation: `arrangement`}, ]; - t.same(track.artistContribs, [{who: artist1, what: `arrangement`}], + t.same(track.artistContribs, [{artist: artist1, annotation: `arrangement`}], `artistContribs #3: resolves from own value`); track.artistContribs = [ - {who: `Artist 1`, what: `snooping`}, - {who: `Artist 413`, what: `as`}, - {who: `Artist 2`, what: `usual`}, + {artist: `Artist 1`, annotation: `snooping`}, + {artist: `Artist 413`, annotation: `as`}, + {artist: `Artist 2`, annotation: `usual`}, ]; t.same(track.artistContribs, - [{who: artist1, what: `snooping`}, {who: artist2, what: `usual`}], + [{artist: artist1, annotation: `snooping`}, {artist: artist2, annotation: `usual`}], `artistContribs #4: filters out names without matches`); }); @@ -248,6 +303,7 @@ t.test(`Track.color`, t => { track.albumData = [ { constructor: {[Thing.referenceType]: 'album'}, + [Thing.isThing]: true, color: '#abcdef', tracks: [track], trackSections: [ @@ -303,7 +359,7 @@ t.test(`Track.commentatorArtists`, t => { `Track.commentatorArtists #2: works with two commentators`); track.commentary = commentary += - `<i>Icy|<b>Icy What You Did There</b>:</i>\n` + + `<i>Icy|<b>Icy annotation You Did There</b>:</i>\n` + `Incredible.\n`; t.same(track.commentatorArtists, [artist1, artist2, artist3], @@ -362,31 +418,31 @@ t.test(`Track.coverArtistContribs`, t => { `coverArtistContribs #1: defaults to empty array`); album.trackCoverArtistContribs = [ - {who: `Artist 1`, what: `lines`}, - {who: `Artist 2`, what: null}, + {artist: `Artist 1`, annotation: `lines`}, + {artist: `Artist 2`, annotation: null}, ]; XXX_decacheWikiData(); t.same(track.coverArtistContribs, - [{who: artist1, what: `lines`}, {who: artist2, what: null}], + [{artist: artist1, annotation: `lines`}, {artist: artist2, annotation: null}], `coverArtistContribs #2: inherits album trackCoverArtistContribs`); track.coverArtistContribs = [ - {who: `Artist 1`, what: `collage`}, + {artist: `Artist 1`, annotation: `collage`}, ]; - t.same(track.coverArtistContribs, [{who: artist1, what: `collage`}], + t.same(track.coverArtistContribs, [{artist: artist1, annotation: `collage`}], `coverArtistContribs #3: resolves from own value`); track.coverArtistContribs = [ - {who: `Artist 1`, what: `snooping`}, - {who: `Artist 413`, what: `as`}, - {who: `Artist 2`, what: `usual`}, + {artist: `Artist 1`, annotation: `snooping`}, + {artist: `Artist 413`, annotation: `as`}, + {artist: `Artist 2`, annotation: `usual`}, ]; t.same(track.coverArtistContribs, - [{who: artist1, what: `snooping`}, {who: artist2, what: `usual`}], + [{artist: artist1, annotation: `snooping`}, {artist: artist2, annotation: `usual`}], `coverArtistContribs #4: filters out names without matches`); track.disableUniqueCoverArt = true; diff --git a/test/unit/data/things/validators.js b/test/unit/data/things/validators.js index 11134a9..3a217d6 100644 --- a/test/unit/data/things/validators.js +++ b/test/unit/data/things/validators.js @@ -1,5 +1,5 @@ import t from 'tap'; -import {showAggregate} from '#sugar'; +import {showAggregate} from '#aggregate'; import { // Basic types @@ -280,17 +280,17 @@ t.test('isContentString', t => { t.test('isContribution', t => { t.plan(4); - t.ok(isContribution({who: 'artist:toby-fox', what: 'Music'})); - t.ok(isContribution({who: 'Toby Fox'})); - t.throws(() => isContribution(({who: 'group:umspaf', what: 'Organizing'})), - {errors: /who/}); - t.throws(() => isContribution(({who: 'artist:toby-fox', what: 123})), - {errors: /what/}); + t.ok(isContribution({artist: 'artist:toby-fox', annotation: 'Music'})); + t.ok(isContribution({artist: 'Toby Fox'})); + t.throws(() => isContribution(({artist: 'group:umspaf', annotation: 'Organizing'})), + {errors: /artist/}); + t.throws(() => isContribution(({artist: 'artist:toby-fox', annotation: 123})), + {errors: /annotation/}); }); t.test('isContributionList', t => { t.plan(4); - t.ok(isContributionList([{who: 'Beavis'}, {who: 'Butthead', what: 'Wrangling'}])); + t.ok(isContributionList([{artist: 'Beavis'}, {artist: 'Butthead', annotation: 'Wrangling'}])); t.ok(isContributionList([])); t.throws(() => isContributionList(2)); t.throws(() => isContributionList(['Charlie', 'Woodstock'])); |