Increase test coverage for new Show tasks feature

Signed-off-by: Georg Ehrke <developer@georgehrke.com>
This commit is contained in:
Georg Ehrke 2020-04-16 20:18:10 +02:00
parent a2f7beec80
commit 8785e4fbb0
No known key found for this signature in database
GPG Key ID: 9D98FD9380A1CB43
9 changed files with 698 additions and 9 deletions

View File

@ -19,7 +19,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { getPrefixedRoute } from '../utils/router'
import {
getPrefixedRoute,
isPublicOrEmbeddedRoute,
} from '../utils/router'
import { generateUrl } from '@nextcloud/router'
import { translate as t } from '@nextcloud/l10n'
import { showInfo } from '@nextcloud/dialogs'
@ -42,7 +45,7 @@ export default function(store, router, route, window) {
break
case 'VTODO':
handleToDoClick(event, store, window)
handleToDoClick(event, store, route, window)
break
}
}
@ -87,11 +90,14 @@ function handleEventClick(event, store, router, route, window) {
*
* @param {EventDef} event FullCalendar event
* @param {Object} store The Vuex store
* @param {Object} route The current Vue route
* @param {Window} window The window object
*/
function handleToDoClick(event, store, window) {
function handleToDoClick(event, store, route, window) {
if (!store.state.settings.tasksEnabled) {
showInfo(t('calendar', 'Please ask your administrator to enable the Tasks App.'))
if (!isPublicOrEmbeddedRoute(route.name)) {
showInfo(t('calendar', 'Please ask your administrator to enable the Tasks App.'))
}
return
}

View File

@ -49,7 +49,7 @@ export default function({ event, el }) {
} else {
taskIcon.classList.add('icon-event-task--light')
}
if (event.extendedProps.percent && event.extendedProps.percent === 100) {
if (event.extendedProps.percent === 100) {
if (event.extendedProps.darkText) {
taskIcon.classList.add('icon-event-task--checked--dark')
} else {

View File

@ -64,7 +64,7 @@ export function eventSourceFunction(calendarObjects, calendar, start, end, timez
}
// For now, we only display
if (object.name === 'VTODO' && object.dueTime === null) {
if (object.name === 'VTODO' && object.endDate === null) {
continue
}
@ -135,7 +135,7 @@ export function eventSourceFunction(calendarObjects, calendar, start, end, timez
calendarId: calendar.id,
darkText: isLight(hexToRGB(calendar.color)),
objectType: object.name,
percent: object.percent,
percent: object.percent || null,
davUrl: calendarObject.dav.url,
},
}

View File

@ -51,3 +51,13 @@ export function getPrefixedRoute(currentRouteName, toRouteName) {
return toRouteName
}
/**
* Checks whether a routeName represents a public / embedded route
*
* @param {String} routeName Name of the route
* @returns {Boolean}
*/
export function isPublicOrEmbeddedRoute(routeName) {
return routeName.startsWith('Embed') || routeName.startsWith('Public')
}

View File

@ -20,13 +20,27 @@
*
*/
import eventClick from "../../../../src/fullcalendar/eventClick.js";
import { getPrefixedRoute } from "../../../../src/utils/router.js";
import {
getPrefixedRoute,
isPublicOrEmbeddedRoute,
} from '../../../../src/utils/router.js'
import { generateUrl } from '@nextcloud/router'
import { translate } from '@nextcloud/l10n'
import { showInfo } from '@nextcloud/dialogs'
jest.mock("../../../../src/utils/router.js");
jest.mock("@nextcloud/router");
jest.mock("@nextcloud/l10n");
jest.mock("@nextcloud/dialogs");
describe('fullcalendar/eventClick test suite', () => {
beforeEach(() => {
getPrefixedRoute.mockClear()
isPublicOrEmbeddedRoute.mockClear()
generateUrl.mockClear()
translate.mockClear()
showInfo.mockClear()
})
it('should open the Popover on big screens', () => {
@ -45,6 +59,7 @@ describe('fullcalendar/eventClick test suite', () => {
extendedProps: {
objectId: 'object123',
recurrenceId: 'recurrence456',
objectType: 'VEVENT',
}
}})
@ -79,6 +94,7 @@ describe('fullcalendar/eventClick test suite', () => {
extendedProps: {
objectId: 'object123',
recurrenceId: 'recurrence456',
objectType: 'VEVENT',
}
}})
@ -113,6 +129,7 @@ describe('fullcalendar/eventClick test suite', () => {
extendedProps: {
objectId: 'object123',
recurrenceId: 'recurrence456',
objectType: 'VEVENT',
}
}})
@ -147,6 +164,7 @@ describe('fullcalendar/eventClick test suite', () => {
extendedProps: {
objectId: 'object123',
recurrenceId: 'recurrence456',
objectType: 'VEVENT',
}
}})
@ -181,6 +199,7 @@ describe('fullcalendar/eventClick test suite', () => {
extendedProps: {
objectId: 'object123',
recurrenceId: 'recurrence456',
objectType: 'VEVENT',
}
}})
@ -222,6 +241,7 @@ describe('fullcalendar/eventClick test suite', () => {
extendedProps: {
objectId: 'object123',
recurrenceId: 'recurrence456',
objectType: 'VEVENT',
}
}})
@ -255,6 +275,7 @@ describe('fullcalendar/eventClick test suite', () => {
extendedProps: {
objectId: 'object123',
recurrenceId: 'recurrence456',
objectType: 'VEVENT',
}
}})
@ -265,4 +286,130 @@ describe('fullcalendar/eventClick test suite', () => {
expect(router.push.mock.calls.length).toEqual(0)
})
it('should forward to the task app if enabled', () => {
const store = { state: { settings: { tasksEnabled: true } } }
const router = { push: jest.fn() }
const route = {
name: 'EditSidebarView',
params: {
object: 'object123',
otherParam: '456',
recurrenceId: 'recurrence456',
}
}
const window = {
innerWidth: 1920,
location: {
protocol: 'http:',
host: 'nextcloud.testing',
}
}
generateUrl
.mockReturnValueOnce('/generated-url')
const eventClickFunction = eventClick(store, router, route, window)
eventClickFunction({ event: {
extendedProps: {
davUrl: '/remote.php/dav/calendars/admin/reminders/EAFB112A-4556-404A-B807-B1E040D0F7A0.ics',
object: 'object123',
recurrenceId: 'recurrence456',
objectType: 'VTODO',
}
}})
expect(generateUrl).toHaveBeenCalledTimes(1)
expect(generateUrl).toHaveBeenNthCalledWith(1, 'apps/tasks/#/calendars/reminders/tasks/EAFB112A-4556-404A-B807-B1E040D0F7A0.ics')
expect(window.location).toEqual('http://nextcloud.testing/generated-url')
})
it('should do nothing when tasks is disabled and route is public', () => {
const store = { state: { settings: { tasksEnabled: false } } }
const router = { push: jest.fn() }
const route = {
name: 'EditSidebarView',
params: {
object: 'object123',
otherParam: '456',
recurrenceId: 'recurrence456',
}
}
const window = {
innerWidth: 1920,
location: {
protocol: 'http:',
host: 'nextcloud.testing',
}
}
const oldLocation = window.location
isPublicOrEmbeddedRoute
.mockReturnValueOnce(true)
const eventClickFunction = eventClick(store, router, route, window)
eventClickFunction({ event: {
extendedProps: {
davUrl: '/remote.php/dav/calendars/admin/reminders/EAFB112A-4556-404A-B807-B1E040D0F7A0.ics',
object: 'object123',
recurrenceId: 'recurrence456',
objectType: 'VTODO',
}
}})
expect(isPublicOrEmbeddedRoute).toHaveBeenCalledTimes(1)
expect(isPublicOrEmbeddedRoute).toHaveBeenNthCalledWith(1, 'EditSidebarView')
expect(generateUrl).toHaveBeenCalledTimes(0)
expect(window.location).toEqual(oldLocation)
})
it('should show a hint to enable tasks app, when disabled but not public', () => {
const store = { state: { settings: { tasksEnabled: false } } }
const router = { push: jest.fn() }
const route = {
name: 'EditSidebarView',
params: {
object: 'object123',
otherParam: '456',
recurrenceId: 'recurrence456',
}
}
const window = {
innerWidth: 1920,
location: {
protocol: 'http:',
host: 'nextcloud.testing',
}
}
const oldLocation = window.location
isPublicOrEmbeddedRoute
.mockReturnValueOnce(false)
translate
.mockReturnValue('translated hint')
const eventClickFunction = eventClick(store, router, route, window)
eventClickFunction({ event: {
extendedProps: {
davUrl: '/remote.php/dav/calendars/admin/reminders/EAFB112A-4556-404A-B807-B1E040D0F7A0.ics',
object: 'object123',
recurrenceId: 'recurrence456',
objectType: 'VTODO',
}
}})
expect(translate).toHaveBeenCalledTimes(1)
expect(translate).toHaveBeenNthCalledWith(1, 'calendar', 'Please ask your administrator to enable the Tasks App.')
expect(showInfo).toHaveBeenCalledTimes(1)
expect(showInfo).toHaveBeenNthCalledWith(1, 'translated hint')
expect(isPublicOrEmbeddedRoute).toHaveBeenCalledTimes(1)
expect(isPublicOrEmbeddedRoute).toHaveBeenNthCalledWith(1, 'EditSidebarView')
expect(generateUrl).toHaveBeenCalledTimes(0)
expect(window.location).toEqual(oldLocation)
})
})

View File

@ -54,4 +54,196 @@ describe('fullcalendar/eventRender test suite', () => {
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

@ -63,6 +63,7 @@ describe('fullcalendar/eventSourceFunction test suite', () => {
const event31End = new Date(2020, 6, 10, 10, 0, 0, 0);
const eventComponentSet1 = [{
name: 'VEVENT',
id: '1-1',
// To title on purpose
isAllDay: jest.fn().mockReturnValue(false),
@ -80,6 +81,7 @@ describe('fullcalendar/eventSourceFunction test suite', () => {
},
hasComponent: jest.fn().mockReturnValue(false),
}, {
name: 'VEVENT',
id: '1-2',
status: 'CANCELLED',
isAllDay: jest.fn().mockReturnValue(false),
@ -98,6 +100,7 @@ describe('fullcalendar/eventSourceFunction test suite', () => {
hasComponent: jest.fn().mockReturnValue(false),
title: 'Untitled\nmultiline\nevent',
}, {
name: 'VEVENT',
id: '1-3',
status: 'TENTATIVE',
isAllDay: jest.fn().mockReturnValue(false),
@ -116,6 +119,7 @@ describe('fullcalendar/eventSourceFunction test suite', () => {
hasComponent: jest.fn().mockReturnValue(true),
}]
const eventComponentSet2 = [{
name: 'VEVENT',
id: '2-1',
status: 'CONFIRMED',
isAllDay: jest.fn().mockReturnValue(true),
@ -134,6 +138,7 @@ describe('fullcalendar/eventSourceFunction test suite', () => {
hasComponent: jest.fn().mockReturnValue(false),
}]
const eventComponentSet4 = [{
name: 'VEVENT',
id: '3-1',
status: 'CONFIRMED',
isAllDay: jest.fn().mockReturnValue(false),
@ -163,15 +168,27 @@ describe('fullcalendar/eventSourceFunction test suite', () => {
const calendarObjects = [{
calendarObject: true,
dav: {
url: 'url1',
},
id: '1',
}, {
calendarObject: true,
dav: {
url: 'url2',
},
id: '2',
}, {
calendarObject: true,
dav: {
url: 'url3',
},
id: '3',
}, {
calendarObject: true,
dav: {
url: 'url4',
},
id: '4',
}]
const start = new Date(Date.UTC(2019, 0, 1, 0, 0, 0, 0))
@ -199,6 +216,9 @@ describe('fullcalendar/eventSourceFunction test suite', () => {
calendarName: 'Calendar displayname',
calendarOrder: 1337,
darkText: false,
davUrl: 'url1',
objectType: 'VEVENT',
percent: null,
}
},
{
@ -216,6 +236,9 @@ describe('fullcalendar/eventSourceFunction test suite', () => {
calendarName: 'Calendar displayname',
calendarOrder: 1337,
darkText: false,
davUrl: 'url1',
objectType: 'VEVENT',
percent: null,
}
},
{
@ -233,6 +256,9 @@ describe('fullcalendar/eventSourceFunction test suite', () => {
calendarName: 'Calendar displayname',
calendarOrder: 1337,
darkText: false,
davUrl: 'url1',
objectType: 'VEVENT',
percent: null,
}
},
{
@ -250,6 +276,9 @@ describe('fullcalendar/eventSourceFunction test suite', () => {
calendarName: 'Calendar displayname',
calendarOrder: 1337,
darkText: false,
davUrl: 'url2',
objectType: 'VEVENT',
percent: null,
}
},
{
@ -267,6 +296,9 @@ describe('fullcalendar/eventSourceFunction test suite', () => {
calendarName: 'Calendar displayname',
calendarOrder: 1337,
darkText: false,
davUrl: 'url4',
objectType: 'VEVENT',
percent: null,
},
backgroundColor: '#ff0000',
borderColor: '#ff0000',
@ -390,4 +422,295 @@ describe('fullcalendar/eventSourceFunction test suite', () => {
expect(event31End.getSeconds()).toEqual(1)
})
it('should provide fc-events for tasks', () => {
translate
.mockImplementation((app, str) => str)
getHexForColorName
.mockImplementation(() => '#ff0000')
generateTextColorForHex
.mockImplementation(() => '#eeeeee')
isLight
.mockImplementation(() => false)
const event1Start = new Date(2020, 1, 1, 10, 0, 0, 0);
const event1End = new Date(2020, 1, 1, 15, 0, 0, 0);
const event2Start = new Date(2020, 1, 2, 10, 0, 0, 0);
const event2End = new Date(2020, 1, 2, 15, 0, 0, 0);
const event3Start = new Date(2020, 1, 3, 10, 0, 0, 0);
const event3End = new Date(2020, 1, 3, 15, 0, 0, 0);
const event4Start = new Date(2020, 5, 5, 0, 0, 0, 0);
const event4End = new Date(2020, 5, 6, 0, 0, 0, 0);
const event5Start = new Date(2020, 6, 10, 10, 0, 0, 0);
const event5End = new Date(2020, 6, 10, 10, 0, 0, 0);
const eventComponentSet = [{
name: 'VTODO',
id: '1',
// To title on purpose
isAllDay: jest.fn().mockReturnValue(false),
getReferenceRecurrenceId: jest.fn().mockReturnValue({ unixTime: 123 }),
canModifyAllDay: jest.fn().mockReturnValue(false),
startDate: {
getInTimezone: jest.fn().mockReturnValue({
jsDate: event1Start
})
},
endDate: {
getInTimezone: jest.fn().mockReturnValue({
jsDate: event1End
})
},
hasComponent: jest.fn().mockReturnValue(false),
percent: null,
}, {
name: 'VTODO',
id: '2',
// To title on purpose
isAllDay: jest.fn().mockReturnValue(false),
getReferenceRecurrenceId: jest.fn().mockReturnValue({ unixTime: 123 }),
canModifyAllDay: jest.fn().mockReturnValue(false),
startDate: {
getInTimezone: jest.fn().mockReturnValue({
jsDate: event2Start
})
},
endDate: {
getInTimezone: jest.fn().mockReturnValue({
jsDate: event2End
})
},
hasComponent: jest.fn().mockReturnValue(false),
percent: null,
}, {
name: 'VTODO',
id: '3',
// To title on purpose
isAllDay: jest.fn().mockReturnValue(false),
getReferenceRecurrenceId: jest.fn().mockReturnValue({ unixTime: 123 }),
canModifyAllDay: jest.fn().mockReturnValue(false),
startDate: {
getInTimezone: jest.fn().mockReturnValue({
jsDate: event3Start
})
},
endDate: {
getInTimezone: jest.fn().mockReturnValue({
jsDate: event3End
})
},
hasComponent: jest.fn().mockReturnValue(false),
percent: 99,
}, {
name: 'VTODO',
id: '4',
// To title on purpose
isAllDay: jest.fn().mockReturnValue(false),
getReferenceRecurrenceId: jest.fn().mockReturnValue({ unixTime: 123 }),
canModifyAllDay: jest.fn().mockReturnValue(false),
startDate: {
getInTimezone: jest.fn().mockReturnValue({
jsDate: event4Start
})
},
endDate: {
getInTimezone: jest.fn().mockReturnValue({
jsDate: event4End
})
},
hasComponent: jest.fn().mockReturnValue(false),
title: 'This task has a title',
percent: null,
}, {
name: 'VTODO',
id: '5',
// To title on purpose
isAllDay: jest.fn().mockReturnValue(false),
getReferenceRecurrenceId: jest.fn().mockReturnValue({ unixTime: 123 }),
canModifyAllDay: jest.fn().mockReturnValue(false),
startDate: {
getInTimezone: jest.fn().mockReturnValue({
jsDate: event5Start
})
},
endDate: {
getInTimezone: jest.fn().mockReturnValue({
jsDate: event5End
})
},
hasComponent: jest.fn().mockReturnValue(false),
title: 'This task has a title and percent',
percent: 99,
}, {
name: 'VTODO',
id: '6',
// To title on purpose
isAllDay: jest.fn().mockReturnValue(false),
getReferenceRecurrenceId: jest.fn().mockReturnValue({ unixTime: 123 }),
canModifyAllDay: jest.fn().mockReturnValue(false),
hasComponent: jest.fn().mockReturnValue(false),
title: 'Task without Due',
startDate: null,
endDate: null,
percent: null,
}]
getAllObjectsInTimeRange
.mockReturnValueOnce(eventComponentSet)
const calendarObjects = [{
calendarObject: true,
dav: {
url: 'url1',
},
id: '1',
}]
const start = new Date(Date.UTC(2019, 0, 1, 0, 0, 0, 0))
const end = new Date(Date.UTC(2020, 0, 31, 59, 59, 59, 999))
const timezone = { calendarJsTimezone: true, tzid: 'America/New_York' }
const result = eventSourceFunction(calendarObjects, {
order: 1337,
displayName: 'Calendar displayname',
id: 'Calendar id 456',
}, start, end, timezone)
expect(result).toEqual([{
allDay: false,
classNames: [
'fc-event-nc-task',
],
end: event1End,
extendedProps: {
calendarId: 'Calendar id 456',
calendarName: 'Calendar displayname',
calendarOrder: 1337,
canModifyAllDay: false,
darkText: false,
davUrl: 'url1',
objectId: '1',
objectType: 'VTODO',
percent: null,
recurrenceId: 123,
},
id: '1###1',
start: event1End,
title: 'Untitled task',
}, {
allDay: false,
classNames: [
'fc-event-nc-task',
],
end: event2End,
extendedProps: {
calendarId: 'Calendar id 456',
calendarName: 'Calendar displayname',
calendarOrder: 1337,
canModifyAllDay: false,
darkText: false,
davUrl: 'url1',
objectId: '1',
objectType: 'VTODO',
percent: null,
recurrenceId: 123,
},
id: '1###2',
start: event2End,
title: 'Untitled task',
}, {
allDay: false,
classNames: [
'fc-event-nc-task',
],
end: event3End,
extendedProps: {
calendarId: 'Calendar id 456',
calendarName: 'Calendar displayname',
calendarOrder: 1337,
canModifyAllDay: false,
darkText: false,
davUrl: 'url1',
objectId: '1',
objectType: 'VTODO',
percent: 99,
recurrenceId: 123,
},
id: '1###3',
start: event3End,
title: 'Untitled task (99%)',
}, {
allDay: false,
classNames: [
'fc-event-nc-task',
],
end: event4End,
extendedProps: {
calendarId: 'Calendar id 456',
calendarName: 'Calendar displayname',
calendarOrder: 1337,
canModifyAllDay: false,
darkText: false,
davUrl: 'url1',
objectId: '1',
objectType: 'VTODO',
percent: null,
recurrenceId: 123,
},
id: '1###4',
start: event4End,
title: 'This task has a title',
}, {
allDay: false,
classNames: [
'fc-event-nc-task',
],
end: event5End,
extendedProps: {
calendarId: 'Calendar id 456',
calendarName: 'Calendar displayname',
calendarOrder: 1337,
canModifyAllDay: false,
darkText: false,
davUrl: 'url1',
objectId: '1',
objectType: 'VTODO',
percent: 99,
recurrenceId: 123,
},
id: '1###5',
start: event5End,
title: 'This task has a title and percent (99%)',
}])
expect(eventComponentSet[0].startDate.getInTimezone).toHaveBeenCalledTimes(0)
expect(eventComponentSet[0].endDate.getInTimezone).toHaveBeenCalledTimes(2)
expect(eventComponentSet[0].endDate.getInTimezone).toHaveBeenNthCalledWith(1, timezone)
expect(eventComponentSet[0].endDate.getInTimezone).toHaveBeenNthCalledWith(2, timezone)
expect(eventComponentSet[1].startDate.getInTimezone).toHaveBeenCalledTimes(0)
expect(eventComponentSet[1].endDate.getInTimezone).toHaveBeenCalledTimes(2)
expect(eventComponentSet[1].endDate.getInTimezone).toHaveBeenNthCalledWith(1, timezone)
expect(eventComponentSet[1].endDate.getInTimezone).toHaveBeenNthCalledWith(2, timezone)
expect(eventComponentSet[2].startDate.getInTimezone).toHaveBeenCalledTimes(0)
expect(eventComponentSet[2].endDate.getInTimezone).toHaveBeenCalledTimes(2)
expect(eventComponentSet[2].endDate.getInTimezone).toHaveBeenNthCalledWith(1, timezone)
expect(eventComponentSet[2].endDate.getInTimezone).toHaveBeenNthCalledWith(2, timezone)
expect(eventComponentSet[3].startDate.getInTimezone).toHaveBeenCalledTimes(0)
expect(eventComponentSet[3].endDate.getInTimezone).toHaveBeenCalledTimes(2)
expect(eventComponentSet[3].endDate.getInTimezone).toHaveBeenNthCalledWith(1, timezone)
expect(eventComponentSet[3].endDate.getInTimezone).toHaveBeenNthCalledWith(2, timezone)
expect(eventComponentSet[4].startDate.getInTimezone).toHaveBeenCalledTimes(0)
expect(eventComponentSet[4].endDate.getInTimezone).toHaveBeenCalledTimes(2)
expect(eventComponentSet[4].endDate.getInTimezone).toHaveBeenNthCalledWith(1, timezone)
expect(eventComponentSet[4].endDate.getInTimezone).toHaveBeenNthCalledWith(2, timezone)
expect(translate).toHaveBeenCalledTimes(3)
expect(translate).toHaveBeenNthCalledWith(1, 'calendar', 'Untitled task')
expect(translate).toHaveBeenNthCalledWith(2, 'calendar', 'Untitled task')
expect(translate).toHaveBeenNthCalledWith(3, 'calendar', 'Untitled task')
expect(getAllObjectsInTimeRange).toHaveBeenCalledTimes(1)
expect(getAllObjectsInTimeRange).toHaveBeenNthCalledWith(1, calendarObjects[0], start, end)
expect(getHexForColorName).toHaveBeenCalledTimes(0)
expect(generateTextColorForHex).toHaveBeenCalledTimes(0)
})
})

View File

@ -21,7 +21,7 @@
*/
import {
getInitialView,
getPrefixedRoute
getPrefixedRoute, isPublicOrEmbeddedRoute
} from '../../../../src/utils/router.js'
import { loadState } from '@nextcloud/initial-state'
@ -52,4 +52,15 @@ describe('utils/router test suite', () => {
expect(getPrefixedRoute('CalendarView', 'EditPopoverView')).toEqual('EditPopoverView')
expect(getPrefixedRoute('EditPopoverView', 'CalendarView')).toEqual('CalendarView')
})
it('should check whether a route is public or embedded', () => {
expect(isPublicOrEmbeddedRoute('PublicCalendarView')).toEqual(true)
expect(isPublicOrEmbeddedRoute('PublicEditPopoverView')).toEqual(true)
expect(isPublicOrEmbeddedRoute('EmbedCalendarView')).toEqual(true)
expect(isPublicOrEmbeddedRoute('EmbedEditPopoverView')).toEqual(true)
expect(isPublicOrEmbeddedRoute('CalendarView')).toEqual(false)
expect(isPublicOrEmbeddedRoute('EditPopoverView')).toEqual(false)
})
})