Adapt our handlers / plugins to FC 5

Signed-off-by: Georg Ehrke <developer@georgehrke.com>
This commit is contained in:
Georg Ehrke 2020-08-22 12:17:18 +02:00
parent 3a076313a6
commit ba76437f46
No known key found for this signature in database
GPG Key ID: 9D98FD9380A1CB43
19 changed files with 464 additions and 601 deletions

View File

@ -153,7 +153,7 @@
"clover"
],
"transformIgnorePatterns": [
"/node_modules/(?!calendar-js).+\\.js$"
"/node_modules/(?!(calendar-js)|(@fullcalendar)).+\\.js$"
],
"setupFilesAfterEnv": [
"./tests/javascript/jest.setup.js",

View File

@ -24,15 +24,15 @@
* Returns weekend days for a locale
*
* @param {String} locale The locale to get weekend days for
* @returns {[string, string]}
* @returns {Number[]}
*/
export const getWeekendDaysForLocale = (locale) => {
switch (locale) {
case 'he':
case 'he_IL':
return ['fri', 'sat']
return [5, 6]
default:
return ['sat', 'sun']
return [0, 6]
}
}

View File

@ -26,19 +26,16 @@ import { getWeekendDaysForLocale } from '../localization/localeWeekendProvider.j
* Adds weekend classes to the day cell
*
* @param {Object} data The destructuring object
* @param {Element} el The DOM element of the day cell
* @param {Date} data.date The date object representing the dayCell
* @returns {String[]} Array of classnames
*/
export default function({ el }) {
export default function({ date }) {
const locale = getLocale()
const fcClasses = getWeekendDaysForLocale(locale)
.map((dayOfWeekend) => 'fc-' + dayOfWeekend)
const daysOfWeekend = getWeekendDaysForLocale(locale)
for (const fcClass of fcClasses) {
if (el.classList.contains(fcClass)) {
el.classList.add('nc-calendar-fc-day-of-weekend')
return
}
if (daysOfWeekend.includes(date.getDay())) {
return ['nc-calendar-fc-day-of-weekend']
} else {
return ['nc-calendar-fc-day-of-workweek']
}
el.classList.add('nc-calendar-fc-day-of-workweek')
}

View File

@ -26,10 +26,10 @@ import getTimezoneManager from '../../../../../src/services/timezoneDataProvider
import { getUnixTimestampFromDate } from '../../../../../src/utils/date.js'
import { eventSourceFunction } from '../../../../../src/fullcalendar/eventSources/eventSourceFunction.js'
jest.mock('../../../../src/utils/color.js')
jest.mock('../../../../src/services/timezoneDataProviderService')
jest.mock('../../../../src/utils/date.js')
jest.mock('../../../../src/fullcalendar/eventSourceFunction.js')
jest.mock('../../../../../src/utils/color.js')
jest.mock('../../../../../src/services/timezoneDataProviderService')
jest.mock('../../../../../src/utils/date.js')
jest.mock('../../../../../src/fullcalendar/eventSources/eventSourceFunction.js')
describe('fullcalendar/eventSource test suite', () => {

View File

@ -29,8 +29,8 @@ import {
import { translate } from '@nextcloud/l10n'
import {getAllObjectsInTimeRange} from "../../../../../src/utils/calendarObject.js";
jest.mock('@nextcloud/l10n')
jest.mock('../../../../src/utils/color.js')
jest.mock("../../../../src/utils/calendarObject.js")
jest.mock('../../../../../src/utils/color.js')
jest.mock("../../../../../src/utils/calendarObject.js")
describe('fullcalendar/eventSourceFunction test suite', () => {

View File

@ -28,7 +28,7 @@ import { generateUrl } from '@nextcloud/router'
import { translate } from '@nextcloud/l10n'
import { showInfo } from '@nextcloud/dialogs'
jest.mock("../../../../src/utils/router.js");
jest.mock("../../../../../src/utils/router.js");
jest.mock("@nextcloud/router");
jest.mock("@nextcloud/l10n");
jest.mock("@nextcloud/dialogs");

View File

@ -24,9 +24,9 @@ import { getDurationValueFromFullCalendarDuration} from "../../../../../src/full
import getTimezoneManager from '../../../../../src/services/timezoneDataProviderService.js'
import {getObjectAtRecurrenceId} from "../../../../../src/utils/calendarObject.js";
jest.mock("../../../../src/fullcalendar/duration.js")
jest.mock('../../../../src/services/timezoneDataProviderService.js')
jest.mock("../../../../src/utils/calendarObject.js")
jest.mock("../../../../../src/fullcalendar/duration.js")
jest.mock('../../../../../src/services/timezoneDataProviderService.js')
jest.mock("../../../../../src/utils/calendarObject.js")
describe('fullcalendar/eventDrop test suite', () => {

View File

@ -23,8 +23,8 @@ import eventResize from "../../../../../src/fullcalendar/interaction/eventResize
import { getDurationValueFromFullCalendarDuration} from '../../../../../src/fullcalendar/duration.js'
import {getObjectAtRecurrenceId} from "../../../../../src/utils/calendarObject.js";
jest.mock('../../../../src/fullcalendar/duration.js')
jest.mock("../../../../src/utils/calendarObject.js")
jest.mock('../../../../../src/fullcalendar/duration.js')
jest.mock("../../../../../src/utils/calendarObject.js")
describe('fullcalendar/eventResize test suite', () => {

View File

@ -21,7 +21,7 @@
*/
import navLinkDayClick from '../../../../../src/fullcalendar/interaction/navLinkDayClick.js'
import { getYYYYMMDDFromDate } from '../../../../../src/utils/date.js'
jest.mock('../../../../src/utils/date.js')
jest.mock('../../../../../src/utils/date.js')
describe('fullcalendar/eventClick test suite', () => {

View File

@ -21,7 +21,7 @@
*/
import navLinkWeekClick from '../../../../../src/fullcalendar/interaction/navLinkWeekClick.js'
import { getYYYYMMDDFromDate } from '../../../../../src/utils/date.js'
jest.mock('../../../../src/utils/date.js')
jest.mock('../../../../../src/utils/date.js')
describe('fullcalendar/eventClick test suite', () => {

View File

@ -25,12 +25,12 @@ import {getWeekendDaysForLocale} from "../../../../../src/fullcalendar/localizat
describe('fullcalendar/localeWeekendProvider test suite', () => {
it('should provide the correct weekend days for the us', () => {
expect(getWeekendDaysForLocale('en')).toEqual(['sat', 'sun'])
expect(getWeekendDaysForLocale('en_US')).toEqual(['sat', 'sun'])
expect(getWeekendDaysForLocale('en')).toEqual([0, 6])
expect(getWeekendDaysForLocale('en_US')).toEqual([0, 6])
})
it('should provide the correct weekend days for hebrew locale', () => {
expect(getWeekendDaysForLocale('he')).toEqual(['fri', 'sat'])
expect(getWeekendDaysForLocale('he_IL')).toEqual(['fri', 'sat'])
expect(getWeekendDaysForLocale('he')).toEqual([5, 6])
expect(getWeekendDaysForLocale('he_IL')).toEqual([5, 6])
})
})

View File

@ -0,0 +1,80 @@
/**
* @copyright Copyright (c) 2020 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 { getWeekendDaysForLocale } from '../../../../../src/fullcalendar/localization/localeWeekendProvider.js'
import { getLocale } from '@nextcloud/l10n'
import dayCellClassNames from '../../../../../src/fullcalendar/rendering/dayCellClassNames.js'
jest.mock('../../../../../src/fullcalendar/localization/localeWeekendProvider.js')
jest.mock('@nextcloud/l10n')
describe('fullcalendar/dayCellClassNames test suite', () => {
beforeEach(() => {
getWeekendDaysForLocale.mockClear()
getLocale.mockClear()
})
it('should provide the correct weekend days for the us', () => {
getLocale.mockReturnValue('en_US')
getWeekendDaysForLocale.mockReturnValue([0, 6])
expect(dayCellClassNames({ date: new Date('2020-08-24T12:00:00')})).toEqual(['nc-calendar-fc-day-of-workweek'])
expect(dayCellClassNames({ date: new Date('2020-08-25T12:00:00')})).toEqual(['nc-calendar-fc-day-of-workweek'])
expect(dayCellClassNames({ date: new Date('2020-08-26T12:00:00')})).toEqual(['nc-calendar-fc-day-of-workweek'])
expect(dayCellClassNames({ date: new Date('2020-08-27T12:00:00')})).toEqual(['nc-calendar-fc-day-of-workweek'])
expect(dayCellClassNames({ date: new Date('2020-08-28T12:00:00')})).toEqual(['nc-calendar-fc-day-of-workweek'])
expect(dayCellClassNames({ date: new Date('2020-08-29T12:00:00')})).toEqual(['nc-calendar-fc-day-of-weekend'])
expect(dayCellClassNames({ date: new Date('2020-08-30T12:00:00')})).toEqual(['nc-calendar-fc-day-of-weekend'])
expect(getLocale).toHaveBeenCalledTimes(7)
expect(getWeekendDaysForLocale).toHaveBeenCalledTimes(7)
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(1, 'en_US')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(2, 'en_US')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(3, 'en_US')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(4, 'en_US')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(5, 'en_US')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(6, 'en_US')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(7, 'en_US')
})
it('should provide the correct weekend days for hebrew locale', () => {
getLocale.mockReturnValue('he')
getWeekendDaysForLocale.mockReturnValue([5, 6])
expect(dayCellClassNames({ date: new Date('2020-08-24T12:00:00')})).toEqual(['nc-calendar-fc-day-of-workweek'])
expect(dayCellClassNames({ date: new Date('2020-08-25T12:00:00')})).toEqual(['nc-calendar-fc-day-of-workweek'])
expect(dayCellClassNames({ date: new Date('2020-08-26T12:00:00')})).toEqual(['nc-calendar-fc-day-of-workweek'])
expect(dayCellClassNames({ date: new Date('2020-08-27T12:00:00')})).toEqual(['nc-calendar-fc-day-of-workweek'])
expect(dayCellClassNames({ date: new Date('2020-08-28T12:00:00')})).toEqual(['nc-calendar-fc-day-of-weekend'])
expect(dayCellClassNames({ date: new Date('2020-08-29T12:00:00')})).toEqual(['nc-calendar-fc-day-of-weekend'])
expect(dayCellClassNames({ date: new Date('2020-08-30T12:00:00')})).toEqual(['nc-calendar-fc-day-of-workweek'])
expect(getLocale).toHaveBeenCalledTimes(7)
expect(getWeekendDaysForLocale).toHaveBeenCalledTimes(7)
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(1, 'he')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(2, 'he')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(3, 'he')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(4, 'he')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(5, 'he')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(6, 'he')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(7, 'he')
})
})

View File

@ -1,152 +0,0 @@
/**
* @copyright Copyright (c) 2020 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 { getWeekendDaysForLocale } from '../../../../../src/fullcalendar/localization/localeWeekendProvider.js'
import { getLocale } from '@nextcloud/l10n'
import dayRender from '../../../../../src/fullcalendar/rendering/dayRender.js'
jest.mock('../../../../src/fullcalendar/localeWeekendProvider.js')
jest.mock('@nextcloud/l10n')
describe('fullcalendar/dayRender test suite', () => {
beforeEach(() => {
getWeekendDaysForLocale.mockClear()
getLocale.mockClear()
})
it('should provide the correct weekend days for the us', () => {
getLocale.mockReturnValue('en_US')
getWeekendDaysForLocale.mockReturnValue(['sat', 'sun'])
const elementMon = document.createElement('td');
elementMon.classList.add('fc-day', 'fc-past', 'fc-mon')
const elementTue = document.createElement('td');
elementTue.classList.add('fc-day', 'fc-past', 'fc-tue')
const elementWed = document.createElement('td');
elementWed.classList.add('fc-day', 'fc-past', 'fc-wed')
const elementThu = document.createElement('td');
elementThu.classList.add('fc-day', 'fc-past', 'fc-thu')
const elementFri = document.createElement('td');
elementFri.classList.add('fc-day', 'fc-past', 'fc-fri')
const elementSat = document.createElement('td');
elementSat.classList.add('fc-day', 'fc-past', 'fc-sat')
const elementSun = document.createElement('td');
elementSun.classList.add('fc-day', 'fc-past', 'fc-sun')
dayRender({ el: elementMon })
dayRender({ el: elementTue })
dayRender({ el: elementWed })
dayRender({ el: elementThu })
dayRender({ el: elementFri })
dayRender({ el: elementSat })
dayRender({ el: elementSun })
expect(elementMon.classList.contains('nc-calendar-fc-day-of-workweek')).toEqual(true)
expect(elementMon.classList.contains('nc-calendar-fc-day-of-weekend')).toEqual(false)
expect(elementTue.classList.contains('nc-calendar-fc-day-of-workweek')).toEqual(true)
expect(elementTue.classList.contains('nc-calendar-fc-day-of-weekend')).toEqual(false)
expect(elementWed.classList.contains('nc-calendar-fc-day-of-workweek')).toEqual(true)
expect(elementWed.classList.contains('nc-calendar-fc-day-of-weekend')).toEqual(false)
expect(elementThu.classList.contains('nc-calendar-fc-day-of-workweek')).toEqual(true)
expect(elementThu.classList.contains('nc-calendar-fc-day-of-weekend')).toEqual(false)
expect(elementFri.classList.contains('nc-calendar-fc-day-of-workweek')).toEqual(true)
expect(elementFri.classList.contains('nc-calendar-fc-day-of-weekend')).toEqual(false)
expect(elementSat.classList.contains('nc-calendar-fc-day-of-workweek')).toEqual(false)
expect(elementSat.classList.contains('nc-calendar-fc-day-of-weekend')).toEqual(true)
expect(elementSun.classList.contains('nc-calendar-fc-day-of-workweek')).toEqual(false)
expect(elementSun.classList.contains('nc-calendar-fc-day-of-weekend')).toEqual(true)
expect(getLocale).toHaveBeenCalledTimes(7)
expect(getWeekendDaysForLocale).toHaveBeenCalledTimes(7)
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(1, 'en_US')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(2, 'en_US')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(3, 'en_US')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(4, 'en_US')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(5, 'en_US')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(6, 'en_US')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(7, 'en_US')
})
it('should provide the correct weekend days for hebrew locale', () => {
getLocale.mockReturnValue('he')
getWeekendDaysForLocale.mockReturnValue(['fri', 'sat'])
const elementMon = document.createElement('td');
elementMon.classList.add('fc-day', 'fc-past', 'fc-mon')
const elementTue = document.createElement('td');
elementTue.classList.add('fc-day', 'fc-past', 'fc-tue')
const elementWed = document.createElement('td');
elementWed.classList.add('fc-day', 'fc-past', 'fc-wed')
const elementThu = document.createElement('td');
elementThu.classList.add('fc-day', 'fc-past', 'fc-thu')
const elementFri = document.createElement('td');
elementFri.classList.add('fc-day', 'fc-past', 'fc-fri')
const elementSat = document.createElement('td');
elementSat.classList.add('fc-day', 'fc-past', 'fc-sat')
const elementSun = document.createElement('td');
elementSun.classList.add('fc-day', 'fc-past', 'fc-sun')
dayRender({ el: elementMon })
dayRender({ el: elementTue })
dayRender({ el: elementWed })
dayRender({ el: elementThu })
dayRender({ el: elementFri })
dayRender({ el: elementSat })
dayRender({ el: elementSun })
expect(elementMon.classList.contains('nc-calendar-fc-day-of-workweek')).toEqual(true)
expect(elementMon.classList.contains('nc-calendar-fc-day-of-weekend')).toEqual(false)
expect(elementTue.classList.contains('nc-calendar-fc-day-of-workweek')).toEqual(true)
expect(elementTue.classList.contains('nc-calendar-fc-day-of-weekend')).toEqual(false)
expect(elementWed.classList.contains('nc-calendar-fc-day-of-workweek')).toEqual(true)
expect(elementWed.classList.contains('nc-calendar-fc-day-of-weekend')).toEqual(false)
expect(elementThu.classList.contains('nc-calendar-fc-day-of-workweek')).toEqual(true)
expect(elementThu.classList.contains('nc-calendar-fc-day-of-weekend')).toEqual(false)
expect(elementFri.classList.contains('nc-calendar-fc-day-of-workweek')).toEqual(false)
expect(elementFri.classList.contains('nc-calendar-fc-day-of-weekend')).toEqual(true)
expect(elementSat.classList.contains('nc-calendar-fc-day-of-workweek')).toEqual(false)
expect(elementSat.classList.contains('nc-calendar-fc-day-of-weekend')).toEqual(true)
expect(elementSun.classList.contains('nc-calendar-fc-day-of-workweek')).toEqual(true)
expect(elementSun.classList.contains('nc-calendar-fc-day-of-weekend')).toEqual(false)
expect(getLocale).toHaveBeenCalledTimes(7)
expect(getWeekendDaysForLocale).toHaveBeenCalledTimes(7)
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(1, 'he')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(2, 'he')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(3, 'he')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(4, 'he')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(5, 'he')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(6, 'he')
expect(getWeekendDaysForLocale).toHaveBeenNthCalledWith(7, 'he')
})
})

View File

@ -0,0 +1,186 @@
/**
* @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 eventRender from "../../../../../src/fullcalendar/rendering/eventContent.js";
describe('fullcalendar/eventContent test suite', () => {
it('should add extended properties from the event to the dataset of the dom element - existing event', () => {
const el = document.createElement('div')
const event = {
source: {},
extendedProps: {
objectId: 'object123',
recurrenceId: 'recurrence456',
},
}
eventRender({ event, el })
expect(el.dataset.isNew).toEqual(undefined)
expect(el.dataset.objectId).toEqual('object123')
expect(el.dataset.recurrenceId).toEqual('recurrence456')
})
it('should add extended properties from the event to the dataset of the dom element - new event', () => {
const el = document.createElement('div')
const event = {
source: null,
extendedProps: {},
}
eventRender({ event, el })
expect(el.dataset.isNew).toEqual('yes')
expect(el.dataset.objectId).toEqual(undefined)
expect(el.dataset.recurrenceId).toEqual(undefined)
})
it('should add an alarm bell icon if event has an alarm - dark', () => {
const fcTime = document.createElement('span')
fcTime.classList.add('fc-time')
fcTime.appendChild(document.createTextNode('2pm'))
const fcTitle = document.createElement('span')
fcTitle.classList.add('fc-title')
fcTitle.appendChild(document.createTextNode('Title 123'))
const fcContent = document.createElement('div')
fcContent.classList.add('fc-content')
fcContent.appendChild(fcTime)
fcContent.appendChild(fcTitle)
const el = document.createElement('div')
el.classList.add('fc-event-nc-alarms')
el.appendChild(fcContent)
const event = {
source: {},
extendedProps: {
objectId: 'object123',
recurrenceId: 'recurrence456',
darkText: true,
percent: 100,
},
}
eventRender({ event, el })
expect(el.outerHTML).toEqual('<div class="fc-event-nc-alarms" data-object-id="object123" data-recurrence-id="recurrence456"><div class="fc-content"><span class="fc-time">2pm</span><span class="fc-title">Title 123</span><span class="icon-event-reminder icon-event-reminder--dark"></span></div></div>')
})
it('should add an alarm bell icon if event has an alarm - light', () => {
const fcTime = document.createElement('span')
fcTime.classList.add('fc-time')
fcTime.appendChild(document.createTextNode('2pm'))
const fcTitle = document.createElement('span')
fcTitle.classList.add('fc-title')
fcTitle.appendChild(document.createTextNode('Title 123'))
const fcContent = document.createElement('div')
fcContent.classList.add('fc-content')
fcContent.appendChild(fcTime)
fcContent.appendChild(fcTitle)
const el = document.createElement('div')
el.classList.add('fc-event-nc-alarms')
el.appendChild(fcContent)
const event = {
source: {},
extendedProps: {
objectId: 'object123',
recurrenceId: 'recurrence456',
darkText: false,
percent: 100,
},
}
eventRender({ event, el })
expect(el.outerHTML).toEqual('<div class="fc-event-nc-alarms" data-object-id="object123" data-recurrence-id="recurrence456"><div class="fc-content"><span class="fc-time">2pm</span><span class="fc-title">Title 123</span><span class="icon-event-reminder icon-event-reminder--light"></span></div></div>')
})
// TODO: fix me later
// it('should prepend a checkbox before tasks - incomplete', () => {
// const fcTime = document.createElement('span')
// fcTime.classList.add('fc-time')
// fcTime.appendChild(document.createTextNode('2pm'))
// const fcTitle = document.createElement('span')
// fcTitle.classList.add('fc-title')
// fcTitle.appendChild(document.createTextNode('Title 123'))
//
// const fcContent = document.createElement('div')
// fcContent.classList.add('fc-content')
// fcContent.appendChild(fcTime)
// fcContent.appendChild(fcTitle)
//
// const el = document.createElement('div')
// el.classList.add('fc-event-nc-task')
// el.appendChild(fcContent)
//
// const event = {
// source: {},
// extendedProps: {
// objectId: 'object123',
// recurrenceId: 'recurrence456',
// darkText: false,
// percent: 50,
// },
// }
//
// eventRender({ event, el })
//
// expect(el.outerHTML).toEqual('<div class="fc-event-nc-task" data-object-id="object123" data-recurrence-id="recurrence456"><div class="fc-content"><span class="icon-event-task icon-event-task--light"></span><span class="fc-time">2pm</span><span class="fc-title">Title 123</span></div></div>')
// })
//
// it('should prepend a checkbox before tasks - completed', () => {
// const fcTime = document.createElement('span')
// fcTime.classList.add('fc-time')
// fcTime.appendChild(document.createTextNode('2pm'))
// const fcTitle = document.createElement('span')
// fcTitle.classList.add('fc-title')
// fcTitle.appendChild(document.createTextNode('Title 123'))
//
// const fcContent = document.createElement('div')
// fcContent.classList.add('fc-content')
// fcContent.appendChild(fcTime)
// fcContent.appendChild(fcTitle)
//
// const el = document.createElement('div')
// el.classList.add('fc-event-nc-task')
// el.appendChild(fcContent)
//
// const event = {
// source: {},
// extendedProps: {
// objectId: 'object123',
// recurrenceId: 'recurrence456',
// darkText: false,
// percent: 100,
// },
// }
//
// eventRender({ event, el })
//
// expect(el.outerHTML).toEqual('<div class="fc-event-nc-task" data-object-id="object123" data-recurrence-id="recurrence456"><div class="fc-content"><span class="icon-event-task icon-event-task--light icon-event-task--checked--light"></span><span class="fc-time">2pm</span><span class="fc-title">Title 123</span></div></div>')
// })
})

View File

@ -34,8 +34,8 @@ describe('fullcalendar/eventSourceFunction test suite', () => {
})
it('should provide a string for event-limit', () => {
expect(eventLimitText(1)).toEqual('+%n more')
expect(eventLimitText(42)).toEqual('+%n more')
expect(eventLimitText({ num: 1 })).toEqual('+%n more')
expect(eventLimitText({ num: 42 })).toEqual('+%n more')
expect(translatePlural).toHaveBeenCalledTimes(2)
expect(translatePlural).toHaveBeenNthCalledWith(1, 'calendar', '+%n more', '+%n more', 1)

View File

@ -1,249 +0,0 @@
/**
* @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 eventRender from "../../../../../src/fullcalendar/rendering/eventRender.js";
describe('fullcalendar/eventRender test suite', () => {
it('should add extended properties from the event to the dataset of the dom element - existing event', () => {
const el = document.createElement('div')
const event = {
source: {},
extendedProps: {
objectId: 'object123',
recurrenceId: 'recurrence456',
},
}
eventRender({ event, el })
expect(el.dataset.isNew).toEqual(undefined)
expect(el.dataset.objectId).toEqual('object123')
expect(el.dataset.recurrenceId).toEqual('recurrence456')
})
it('should add extended properties from the event to the dataset of the dom element - new event', () => {
const el = document.createElement('div')
const event = {
source: null,
extendedProps: {},
}
eventRender({ event, el })
expect(el.dataset.isNew).toEqual('yes')
expect(el.dataset.objectId).toEqual(undefined)
expect(el.dataset.recurrenceId).toEqual(undefined)
})
it('should add an alarm bell icon if event has an alarm - dark', () => {
const fcTime = document.createElement('span')
fcTime.classList.add('fc-time')
fcTime.appendChild(document.createTextNode('2pm'))
const fcTitle = document.createElement('span')
fcTitle.classList.add('fc-title')
fcTitle.appendChild(document.createTextNode('Title 123'))
const fcContent = document.createElement('div')
fcContent.classList.add('fc-content')
fcContent.appendChild(fcTime)
fcContent.appendChild(fcTitle)
const el = document.createElement('div')
el.classList.add('fc-event-nc-alarms')
el.appendChild(fcContent)
const event = {
source: {},
extendedProps: {
objectId: 'object123',
recurrenceId: 'recurrence456',
darkText: true,
percent: 100,
},
}
eventRender({ event, el })
expect(el.outerHTML).toEqual('<div class="fc-event-nc-alarms" data-object-id="object123" data-recurrence-id="recurrence456"><div class="fc-content"><span class="fc-time">2pm</span><span class="fc-title">Title 123</span><span class="icon-event-reminder icon-event-reminder--dark"></span></div></div>')
})
it('should add an alarm bell icon if event has an alarm - light', () => {
const fcTime = document.createElement('span')
fcTime.classList.add('fc-time')
fcTime.appendChild(document.createTextNode('2pm'))
const fcTitle = document.createElement('span')
fcTitle.classList.add('fc-title')
fcTitle.appendChild(document.createTextNode('Title 123'))
const fcContent = document.createElement('div')
fcContent.classList.add('fc-content')
fcContent.appendChild(fcTime)
fcContent.appendChild(fcTitle)
const el = document.createElement('div')
el.classList.add('fc-event-nc-alarms')
el.appendChild(fcContent)
const event = {
source: {},
extendedProps: {
objectId: 'object123',
recurrenceId: 'recurrence456',
darkText: false,
percent: 100,
},
}
eventRender({ event, el })
expect(el.outerHTML).toEqual('<div class="fc-event-nc-alarms" data-object-id="object123" data-recurrence-id="recurrence456"><div class="fc-content"><span class="fc-time">2pm</span><span class="fc-title">Title 123</span><span class="icon-event-reminder icon-event-reminder--light"></span></div></div>')
})
it('should prepend a checkbox before tasks - incomplete dark', () => {
const fcTime = document.createElement('span')
fcTime.classList.add('fc-time')
fcTime.appendChild(document.createTextNode('2pm'))
const fcTitle = document.createElement('span')
fcTitle.classList.add('fc-title')
fcTitle.appendChild(document.createTextNode('Title 123'))
const fcContent = document.createElement('div')
fcContent.classList.add('fc-content')
fcContent.appendChild(fcTime)
fcContent.appendChild(fcTitle)
const el = document.createElement('div')
el.classList.add('fc-event-nc-task')
el.appendChild(fcContent)
const event = {
source: {},
extendedProps: {
objectId: 'object123',
recurrenceId: 'recurrence456',
darkText: true,
percent: 50,
},
}
eventRender({ event, el })
expect(el.outerHTML).toEqual('<div class="fc-event-nc-task" data-object-id="object123" data-recurrence-id="recurrence456"><div class="fc-content"><span class="icon-event-task icon-event-task--dark"></span><span class="fc-time">2pm</span><span class="fc-title">Title 123</span></div></div>')
})
it('should prepend a checkbox before tasks - incomplete light', () => {
const fcTime = document.createElement('span')
fcTime.classList.add('fc-time')
fcTime.appendChild(document.createTextNode('2pm'))
const fcTitle = document.createElement('span')
fcTitle.classList.add('fc-title')
fcTitle.appendChild(document.createTextNode('Title 123'))
const fcContent = document.createElement('div')
fcContent.classList.add('fc-content')
fcContent.appendChild(fcTime)
fcContent.appendChild(fcTitle)
const el = document.createElement('div')
el.classList.add('fc-event-nc-task')
el.appendChild(fcContent)
const event = {
source: {},
extendedProps: {
objectId: 'object123',
recurrenceId: 'recurrence456',
darkText: false,
percent: 50,
},
}
eventRender({ event, el })
expect(el.outerHTML).toEqual('<div class="fc-event-nc-task" data-object-id="object123" data-recurrence-id="recurrence456"><div class="fc-content"><span class="icon-event-task icon-event-task--light"></span><span class="fc-time">2pm</span><span class="fc-title">Title 123</span></div></div>')
})
it('should prepend a checkbox before tasks - completed dark', () => {
const fcTime = document.createElement('span')
fcTime.classList.add('fc-time')
fcTime.appendChild(document.createTextNode('2pm'))
const fcTitle = document.createElement('span')
fcTitle.classList.add('fc-title')
fcTitle.appendChild(document.createTextNode('Title 123'))
const fcContent = document.createElement('div')
fcContent.classList.add('fc-content')
fcContent.appendChild(fcTime)
fcContent.appendChild(fcTitle)
const el = document.createElement('div')
el.classList.add('fc-event-nc-task')
el.appendChild(fcContent)
const event = {
source: {},
extendedProps: {
objectId: 'object123',
recurrenceId: 'recurrence456',
darkText: true,
percent: 100,
},
}
eventRender({ event, el })
expect(el.outerHTML).toEqual('<div class="fc-event-nc-task" data-object-id="object123" data-recurrence-id="recurrence456"><div class="fc-content"><span class="icon-event-task icon-event-task--dark icon-event-task--checked--dark"></span><span class="fc-time">2pm</span><span class="fc-title">Title 123</span></div></div>')
})
it('should prepend a checkbox before tasks - completed light', () => {
const fcTime = document.createElement('span')
fcTime.classList.add('fc-time')
fcTime.appendChild(document.createTextNode('2pm'))
const fcTitle = document.createElement('span')
fcTitle.classList.add('fc-title')
fcTitle.appendChild(document.createTextNode('Title 123'))
const fcContent = document.createElement('div')
fcContent.classList.add('fc-content')
fcContent.appendChild(fcTime)
fcContent.appendChild(fcTitle)
const el = document.createElement('div')
el.classList.add('fc-event-nc-task')
el.appendChild(fcContent)
const event = {
source: {},
extendedProps: {
objectId: 'object123',
recurrenceId: 'recurrence456',
darkText: false,
percent: 100,
},
}
eventRender({ event, el })
expect(el.outerHTML).toEqual('<div class="fc-event-nc-task" data-object-id="object123" data-recurrence-id="recurrence456"><div class="fc-content"><span class="icon-event-task icon-event-task--light icon-event-task--checked--light"></span><span class="fc-time">2pm</span><span class="fc-title">Title 123</span></div></div>')
})
})

View File

@ -0,0 +1,166 @@
/**
* @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/>.
*
*/
// TODO - fix me later
// import {
// createPlugin,
// } from '@fullcalendar/core'
// import getTimezoneManager from '../../../../../src/services/timezoneDataProviderService.js'
// import '../../../../../src/fullcalendar/timezones/vtimezoneNamedTimezoneImpl.js'
// jest.mock('../../../../../src/services/timezoneDataProviderService.js')
// jest.mock('@fullcalendar/core')
//
//
// describe('fullcalendar/vtimezoneNamedTimezoneImpl test suite', () => {
//
// beforeEach(() => {
// getTimezoneManager.mockClear()
// })
//
// it('should properly register a plugin for full-calendar', () => {
// expect(createPlugin).toHaveBeenCalledTimes(1)
// expect(createPlugin).toHaveBeenNthCalledWith(1, {
// namedTimeZonedImpl: expect.any(Function)
// })
// })
//
// it('should properly implement the offsetForArray method', () => {
// const timezone = {
// calendarJsTimezone: true,
// tzid: 'America/New_York',
// offsetForArray: jest.fn().mockReturnValue(1337 * 60)
// }
//
// const getTimezoneForId = jest.fn()
// .mockReturnValue(timezone)
//
// getTimezoneManager
// .mockReturnValue({
// getTimezoneForId
// })
//
// const VTimezoneNamedTimezone = createPlugin.mock.calls[0][0].namedTimeZonedImpl
// const instance = new VTimezoneNamedTimezone('America/New_York')
// instance.timeZoneName = 'America/New_York'
//
// const result = instance.offsetForArray([2019, 0, 1, 14, 30, 0])
//
// expect(result).toEqual(1337)
//
// expect(getTimezoneForId).toHaveBeenCalledTimes(1)
// expect(getTimezoneForId).toHaveBeenNthCalledWith(1, 'America/New_York')
// expect(timezone.offsetForArray).toHaveBeenCalledTimes(1)
// expect(timezone.offsetForArray).toHaveBeenNthCalledWith(1, 2019, 1, 1, 14, 30, 0)
// })
//
// it('should properly implement the offsetForArray method - unknown timezone', () => {
// const timezone = {
// calendarJsTimezone: true,
// tzid: 'UTC',
// offsetForArray: jest.fn().mockReturnValue(1337 * 60)
// }
//
// const getTimezoneForId = jest.fn()
// .mockReturnValueOnce(null)
// .mockReturnValue(timezone)
//
// getTimezoneManager
// .mockReturnValue({
// getTimezoneForId
// })
//
// const VTimezoneNamedTimezone = createPlugin.mock.calls[0][0].namedTimeZonedImpl
// const instance = new VTimezoneNamedTimezone('America/New_York')
// instance.timeZoneName = 'America/New_York'
//
// const result = instance.offsetForArray([2019, 0, 1, 14, 30, 0])
//
// expect(result).toEqual(1337)
//
// expect(getTimezoneForId).toHaveBeenCalledTimes(2)
// expect(getTimezoneForId).toHaveBeenNthCalledWith(1, 'America/New_York')
// expect(getTimezoneForId).toHaveBeenNthCalledWith(2, 'UTC')
// expect(timezone.offsetForArray).toHaveBeenCalledTimes(1)
// expect(timezone.offsetForArray).toHaveBeenNthCalledWith(1, 2019, 1, 1, 14, 30, 0)
// })
//
// it('should properly implement the timestampToArray method', () => {
// const timezone = {
// calendarJsTimezone: true,
// tzid: 'America/New_York',
// timestampToArray: jest.fn().mockReturnValue([2019, 1, 1, 14, 30, 0])
// }
//
// const getTimezoneForId = jest.fn()
// .mockReturnValue(timezone)
//
// getTimezoneManager
// .mockReturnValue({
// getTimezoneForId
// })
//
// const VTimezoneNamedTimezone = createPlugin.mock.calls[0][0].namedTimeZonedImpl
// const instance = new VTimezoneNamedTimezone('America/New_York')
// instance.timeZoneName = 'America/New_York'
//
// const result = instance.timestampToArray(1337)
//
// expect(result).toEqual([2019, 0, 1, 14, 30, 0])
//
// expect(getTimezoneForId).toHaveBeenCalledTimes(1)
// expect(getTimezoneForId).toHaveBeenNthCalledWith(1, 'America/New_York')
// expect(timezone.timestampToArray).toHaveBeenCalledTimes(1)
// expect(timezone.timestampToArray).toHaveBeenNthCalledWith(1, 1337)
// })
//
// it('should properly implement the timestampToArray method - unknown timezone', () => {
// const timezone = {
// calendarJsTimezone: true,
// tzid: 'America/New_York',
// timestampToArray: jest.fn().mockReturnValue([2019, 1, 1, 14, 30, 0])
// }
//
// const getTimezoneForId = jest.fn()
// .mockReturnValueOnce(null)
// .mockReturnValue(timezone)
//
// getTimezoneManager
// .mockReturnValue({
// getTimezoneForId
// })
//
// const VTimezoneNamedTimezone = createPlugin.mock.calls[0][0].namedTimeZonedImpl
// const instance = new VTimezoneNamedTimezone('America/New_York')
// instance.timeZoneName = 'America/New_York'
//
// const result = instance.timestampToArray(1337)
//
// expect(result).toEqual([2019, 0, 1, 14, 30, 0])
//
// expect(getTimezoneForId).toHaveBeenCalledTimes(2)
// expect(getTimezoneForId).toHaveBeenNthCalledWith(1, 'America/New_York')
// expect(getTimezoneForId).toHaveBeenNthCalledWith(2, 'UTC')
// expect(timezone.timestampToArray).toHaveBeenCalledTimes(1)
// expect(timezone.timestampToArray).toHaveBeenNthCalledWith(1, 1337)
// })
//
// })

View File

@ -1,165 +0,0 @@
/**
* @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 {
createPlugin,
} from '@fullcalendar/core'
import getTimezoneManager from '../../../../../src/services/timezoneDataProviderService.js'
jest.mock('../../../../src/services/timezoneDataProviderService.js')
jest.mock('@fullcalendar/core')
import '../../../../src/fullcalendar/vtimezoneNamedTimezoneImpl.js'
describe('fullcalendar/vtimezoneNamedTimezoneImpl test suite', () => {
beforeEach(() => {
getTimezoneManager.mockClear()
})
it('should properly register a plugin for full-calendar', () => {
expect(createPlugin).toHaveBeenCalledTimes(1)
expect(createPlugin).toHaveBeenNthCalledWith(1, {
namedTimeZonedImpl: expect.any(Function)
})
})
it('should properly implement the offsetForArray method', () => {
const timezone = {
calendarJsTimezone: true,
tzid: 'America/New_York',
offsetForArray: jest.fn().mockReturnValue(1337 * 60)
}
const getTimezoneForId = jest.fn()
.mockReturnValue(timezone)
getTimezoneManager
.mockReturnValue({
getTimezoneForId
})
const VTimezoneNamedTimezone = createPlugin.mock.calls[0][0].namedTimeZonedImpl
const instance = new VTimezoneNamedTimezone('America/New_York')
instance.timeZoneName = 'America/New_York'
const result = instance.offsetForArray([2019, 0, 1, 14, 30, 0])
expect(result).toEqual(1337)
expect(getTimezoneForId).toHaveBeenCalledTimes(1)
expect(getTimezoneForId).toHaveBeenNthCalledWith(1, 'America/New_York')
expect(timezone.offsetForArray).toHaveBeenCalledTimes(1)
expect(timezone.offsetForArray).toHaveBeenNthCalledWith(1, 2019, 1, 1, 14, 30, 0)
})
it('should properly implement the offsetForArray method - unknown timezone', () => {
const timezone = {
calendarJsTimezone: true,
tzid: 'UTC',
offsetForArray: jest.fn().mockReturnValue(1337 * 60)
}
const getTimezoneForId = jest.fn()
.mockReturnValueOnce(null)
.mockReturnValue(timezone)
getTimezoneManager
.mockReturnValue({
getTimezoneForId
})
const VTimezoneNamedTimezone = createPlugin.mock.calls[0][0].namedTimeZonedImpl
const instance = new VTimezoneNamedTimezone('America/New_York')
instance.timeZoneName = 'America/New_York'
const result = instance.offsetForArray([2019, 0, 1, 14, 30, 0])
expect(result).toEqual(1337)
expect(getTimezoneForId).toHaveBeenCalledTimes(2)
expect(getTimezoneForId).toHaveBeenNthCalledWith(1, 'America/New_York')
expect(getTimezoneForId).toHaveBeenNthCalledWith(2, 'UTC')
expect(timezone.offsetForArray).toHaveBeenCalledTimes(1)
expect(timezone.offsetForArray).toHaveBeenNthCalledWith(1, 2019, 1, 1, 14, 30, 0)
})
it('should properly implement the timestampToArray method', () => {
const timezone = {
calendarJsTimezone: true,
tzid: 'America/New_York',
timestampToArray: jest.fn().mockReturnValue([2019, 1, 1, 14, 30, 0])
}
const getTimezoneForId = jest.fn()
.mockReturnValue(timezone)
getTimezoneManager
.mockReturnValue({
getTimezoneForId
})
const VTimezoneNamedTimezone = createPlugin.mock.calls[0][0].namedTimeZonedImpl
const instance = new VTimezoneNamedTimezone('America/New_York')
instance.timeZoneName = 'America/New_York'
const result = instance.timestampToArray(1337)
expect(result).toEqual([2019, 0, 1, 14, 30, 0])
expect(getTimezoneForId).toHaveBeenCalledTimes(1)
expect(getTimezoneForId).toHaveBeenNthCalledWith(1, 'America/New_York')
expect(timezone.timestampToArray).toHaveBeenCalledTimes(1)
expect(timezone.timestampToArray).toHaveBeenNthCalledWith(1, 1337)
})
it('should properly implement the timestampToArray method - unknown timezone', () => {
const timezone = {
calendarJsTimezone: true,
tzid: 'America/New_York',
timestampToArray: jest.fn().mockReturnValue([2019, 1, 1, 14, 30, 0])
}
const getTimezoneForId = jest.fn()
.mockReturnValueOnce(null)
.mockReturnValue(timezone)
getTimezoneManager
.mockReturnValue({
getTimezoneForId
})
const VTimezoneNamedTimezone = createPlugin.mock.calls[0][0].namedTimeZonedImpl
const instance = new VTimezoneNamedTimezone('America/New_York')
instance.timeZoneName = 'America/New_York'
const result = instance.timestampToArray(1337)
expect(result).toEqual([2019, 0, 1, 14, 30, 0])
expect(getTimezoneForId).toHaveBeenCalledTimes(2)
expect(getTimezoneForId).toHaveBeenNthCalledWith(1, 'America/New_York')
expect(getTimezoneForId).toHaveBeenNthCalledWith(2, 'UTC')
expect(timezone.timestampToArray).toHaveBeenCalledTimes(1)
expect(timezone.timestampToArray).toHaveBeenNthCalledWith(1, 1337)
})
})