nextcloud-calendar/tests/javascript/unit/utils/illustration.test.js

54 lines
2.7 KiB
JavaScript

/**
* @copyright Copyright (c) 2019 Georg Ehrke
*
* @author Georg Ehrke <oc.list@georgehrke.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import getIllustrationForTitle from "../../../../src/utils/illustration.js";
import { imagePath } from '@nextcloud/router'
jest.mock('@nextcloud/router')
describe('utils/illustration test suite', () => {
beforeEach(() => {
imagePath.mockClear()
})
it('should return a matching illustration', () => {
imagePath.mockImplementation((app, image) => 'imagePath###' + app + '###' + image)
expect(getIllustrationForTitle('Watch movie with Jane')).toEqual('imagePath###calendar###illustrations/movie_night')
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/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(7)
expect(imagePath).toHaveBeenNthCalledWith(1, 'calendar', 'illustrations/movie_night')
expect(imagePath).toHaveBeenNthCalledWith(2, 'calendar', 'illustrations/relaxation')
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')
})
})