Vary illustration when multiple images match
Randomly select an illustration from the images that match the title of the event. The illustration is chosen on a hash of the event title so is the same for the same event every time. Signed-off-by: Robert Spencer <general@robertandrewspencer.com>
This commit is contained in:
parent
de850cefc3
commit
57763ea988
|
@ -56,7 +56,8 @@ function findIllustrationForString(str) {
|
|||
for (const illustrationString of illustration.strings) {
|
||||
const regex = new RegExp('\\b' + illustrationString.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&') + '\\b', 'gi')
|
||||
if (str.match(regex) !== null) {
|
||||
return imagePath('calendar', 'illustrations/' + illustration.illustrationNames[0])
|
||||
return imagePath('calendar', 'illustrations/'
|
||||
+ illustration.illustrationNames[str.charCodeAt(str.length - 1) % illustration.illustrationNames.length])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,19 +33,21 @@ describe('utils/illustration test suite', () => {
|
|||
imagePath.mockImplementation((app, image) => 'imagePath###' + app + '###' + image)
|
||||
|
||||
expect(getIllustrationForTitle('Watch movie with Jane')).toEqual('imagePath###calendar###illustrations/movie_night')
|
||||
expect(getIllustrationForTitle('Take time to relax')).toEqual('imagePath###calendar###illustrations/relaxation')
|
||||
expect(getIllustrationForTitle('Relaxing with Thabo')).toEqual('imagePath###calendar###illustrations/relaxation')
|
||||
expect(getIllustrationForTitle('Relax at home')).toEqual('imagePath###calendar###illustrations/a_moment_to_relax')
|
||||
expect(getIllustrationForTitle('Give presentation about calendar')).toEqual('imagePath###calendar###illustrations/presentation')
|
||||
expect(getIllustrationForTitle('Let\'s go camping')).toEqual('imagePath###calendar###illustrations/camping')
|
||||
expect(getIllustrationForTitle('Let\'s go camping')).toEqual('imagePath###calendar###illustrations/into_the_night')
|
||||
expect(getIllustrationForTitle('Prepare big campaign')).toEqual('imagePath###calendar###illustrations/no_data')
|
||||
|
||||
expect(getIllustrationForTitle('ABC', ['Watch', 'movie'])).toEqual('imagePath###calendar###illustrations/movie_night')
|
||||
|
||||
expect(imagePath).toHaveBeenCalledTimes(6)
|
||||
expect(imagePath).toHaveBeenCalledTimes(7)
|
||||
expect(imagePath).toHaveBeenNthCalledWith(1, 'calendar', 'illustrations/movie_night')
|
||||
expect(imagePath).toHaveBeenNthCalledWith(2, 'calendar', 'illustrations/relaxation')
|
||||
expect(imagePath).toHaveBeenNthCalledWith(3, 'calendar', 'illustrations/presentation')
|
||||
expect(imagePath).toHaveBeenNthCalledWith(4, 'calendar', 'illustrations/camping')
|
||||
expect(imagePath).toHaveBeenNthCalledWith(5, 'calendar', 'illustrations/no_data')
|
||||
expect(imagePath).toHaveBeenNthCalledWith(6, 'calendar', 'illustrations/movie_night')
|
||||
expect(imagePath).toHaveBeenNthCalledWith(3, 'calendar', 'illustrations/a_moment_to_relax')
|
||||
expect(imagePath).toHaveBeenNthCalledWith(4, 'calendar', 'illustrations/presentation')
|
||||
expect(imagePath).toHaveBeenNthCalledWith(5, 'calendar', 'illustrations/into_the_night')
|
||||
expect(imagePath).toHaveBeenNthCalledWith(6, 'calendar', 'illustrations/no_data')
|
||||
expect(imagePath).toHaveBeenNthCalledWith(7, 'calendar', 'illustrations/movie_night')
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue