diff options
Diffstat (limited to 'test/lib')
-rw-r--r-- | test/lib/content-function.js | 11 | ||||
-rw-r--r-- | test/lib/wiki-data.js | 35 |
2 files changed, 40 insertions, 6 deletions
diff --git a/test/lib/content-function.js b/test/lib/content-function.js index 5cb499b1..a4c5dac1 100644 --- a/test/lib/content-function.js +++ b/test/lib/content-function.js @@ -8,7 +8,7 @@ import {getColors} from '#colors'; import {quickLoadContentDependencies} from '#content-dependencies'; import {quickEvaluate} from '#content-function'; import * as html from '#html'; -import {processLanguageFile} from '#language'; +import {internalDefaultStringsFile, processLanguageFile} from '#language'; import {empty, showAggregate} from '#sugar'; import {generateURLs, thumb, urlSpec} from '#urls'; @@ -22,7 +22,7 @@ export function testContentFunctions(t, message, fn) { t.test(message, async t => { let loadedContentDependencies; - const language = await processLanguageFile('./src/strings-default.json'); + const language = await processLanguageFile(internalDefaultStringsFile); const mocks = []; const evaluate = ({ @@ -50,8 +50,15 @@ export function testContentFunctions(t, message, fn) { thumb, to, urls, + + pagePath: ['home'], appendIndexHTML: false, getColors: c => getColors(c, {chroma}), + + wikiData: { + wikiInfo: {}, + }, + ...extraDependencies, }, }); diff --git a/test/lib/wiki-data.js b/test/lib/wiki-data.js index c4083a56..5433de29 100644 --- a/test/lib/wiki-data.js +++ b/test/lib/wiki-data.js @@ -1,7 +1,32 @@ +import CacheableObject from '#cacheable-object'; +import find from '#find'; import {linkWikiDataArrays} from '#yaml'; -export function linkAndBindWikiData(wikiData) { - linkWikiDataArrays(wikiData); +export function linkAndBindWikiData(wikiData, { + inferAlbumsOwnTrackData = true, +} = {}) { + function customLinkWikiDataArrays(...args) { + linkWikiDataArrays(...args); + + // If albumData is present, automatically set albums' ownTrackData values + // by resolving track sections' references against the full array. This is + // just a nicety for working with albums throughout tests. + if (inferAlbumsOwnTrackData && wikiData.albumData && wikiData.trackData) { + for (const album of wikiData.albumData) { + const trackSections = + CacheableObject.getUpdateValue(album, 'trackSections'); + + const trackRefs = + trackSections.flatMap(section => section.tracks); + + album.ownTrackData = + trackRefs.map(ref => + find.track(ref, wikiData.trackData, {mode: 'error'})); + } + } + } + + customLinkWikiDataArrays(wikiData); return { // Mutate to make the below functions aware of new data objects, or of @@ -13,12 +38,14 @@ export function linkAndBindWikiData(wikiData) { // It'll automatically relink everything on wikiData so all the objects // are caught up to date. linkWikiDataArrays: - linkWikiDataArrays.bind(null, wikiData), + customLinkWikiDataArrays + .bind(null, wikiData), // Use this if you HAVEN'T mutated wikiData and just need to decache // indirect dependencies on exposed properties of other data objects. // See documentation on linkWikiDataArarys (in yaml.js) for more info. XXX_decacheWikiData: - linkWikiDataArrays.bind(null, wikiData, {XXX_decacheWikiData: true}), + customLinkWikiDataArrays + .bind(null, wikiData, {XXX_decacheWikiData: true}), }; } |