Add a 'days with events' preference (default 3, range 1-7) that drives the upcoming events widget, and extend the fetch window to 8 days so the largest window can populate. Add a Calendar settings pane (moved under Integrations) that lists the connected CalDAV/ICS sources in a two-column grid with add/edit/remove, and remove calendars from Manage Integrations. Turn the modal service into a stack so add/edit forms open on top of the settings dialog, with one dialog per level, per-entry title ids, and a softened stacked backdrop. Move CALENDAR_ACTOR into its own config module to break the calendar/caldav/ics import cycle.
280 lines
7.6 KiB
JavaScript
280 lines
7.6 KiB
JavaScript
import { module, test } from 'qunit';
|
|
import {
|
|
CALENDAR_TYPES,
|
|
CALENDAR_VISIBLE_DAYS,
|
|
classifyCalendarError,
|
|
fetchWindow,
|
|
groupEvents,
|
|
normalizeEvent,
|
|
normalizeVisibleDays,
|
|
parseEventDate,
|
|
} from 'dashtab/config/calendar';
|
|
|
|
module('Unit | Config | calendar', function () {
|
|
test('fetchWindow reaches the midnight after the largest visible window', function (assert) {
|
|
const now = new Date(2026, 9, 27, 15, 30);
|
|
const { startTime, endTime } = fetchWindow(now);
|
|
|
|
assert.strictEqual(startTime, now.toISOString());
|
|
|
|
const end = new Date(endTime);
|
|
// Oct 27 + CALENDAR_FETCH_DAYS (8) = Nov 4 local midnight, one day past the
|
|
// largest visible window (today + 7) so its last day can always populate.
|
|
assert.strictEqual(end.getFullYear(), 2026);
|
|
assert.strictEqual(end.getMonth(), 10);
|
|
assert.strictEqual(end.getDate(), 4);
|
|
assert.strictEqual(end.getHours(), 0);
|
|
});
|
|
|
|
test('normalizeVisibleDays clamps to the supported range', function (assert) {
|
|
assert.strictEqual(normalizeVisibleDays(5), 5);
|
|
assert.strictEqual(normalizeVisibleDays('5'), 5);
|
|
assert.strictEqual(normalizeVisibleDays(0), CALENDAR_VISIBLE_DAYS);
|
|
assert.strictEqual(normalizeVisibleDays(99), CALENDAR_VISIBLE_DAYS);
|
|
assert.strictEqual(normalizeVisibleDays('nope'), CALENDAR_VISIBLE_DAYS);
|
|
assert.strictEqual(normalizeVisibleDays(null), CALENDAR_VISIBLE_DAYS);
|
|
});
|
|
|
|
test('CALENDAR_TYPES lists the calendar integration ids', function (assert) {
|
|
assert.deepEqual(CALENDAR_TYPES, ['calendar-caldav', 'calendar-ics']);
|
|
});
|
|
|
|
test('parseEventDate reads date-only values as local dates', function (assert) {
|
|
const date = parseEventDate('2026-08-03', true);
|
|
|
|
assert.strictEqual(date.getFullYear(), 2026);
|
|
assert.strictEqual(date.getMonth(), 7);
|
|
assert.strictEqual(date.getDate(), 3);
|
|
assert.strictEqual(date.getHours(), 0);
|
|
|
|
assert.strictEqual(parseEventDate(null), null);
|
|
});
|
|
|
|
test('parseEventDate reads timed values as instants', function (assert) {
|
|
const value = '2026-08-03T13:00:00Z';
|
|
assert.strictEqual(
|
|
parseEventDate(value).getTime(),
|
|
new Date(value).getTime()
|
|
);
|
|
});
|
|
|
|
test('normalizeEvent keeps events and drops tasks, recurrences and untimed items', function (assert) {
|
|
assert.strictEqual(
|
|
normalizeEvent({ type: 'task', name: 'x', startTime: '2026-08-03' }),
|
|
null
|
|
);
|
|
assert.strictEqual(
|
|
normalizeEvent({
|
|
type: 'event',
|
|
name: 'x',
|
|
startTime: '2026-08-03',
|
|
recurrence: { frequency: 'weekly' },
|
|
}),
|
|
null
|
|
);
|
|
assert.strictEqual(normalizeEvent({ type: 'event', name: 'x' }), null);
|
|
|
|
assert.deepEqual(
|
|
normalizeEvent({
|
|
type: 'event',
|
|
id: 'e1',
|
|
name: 'Standup',
|
|
startTime: '2026-08-03T09:00:00Z',
|
|
endTime: '2026-08-03T09:15:00Z',
|
|
location: 'Room 1',
|
|
}),
|
|
{
|
|
id: 'e1',
|
|
name: 'Standup',
|
|
startTime: '2026-08-03T09:00:00Z',
|
|
endTime: '2026-08-03T09:15:00Z',
|
|
allDay: false,
|
|
location: 'Room 1',
|
|
}
|
|
);
|
|
});
|
|
|
|
test('groupEvents splits today from the next days that have events', function (assert) {
|
|
const now = new Date(2026, 9, 27, 15, 0);
|
|
const events = [
|
|
{
|
|
id: 'past',
|
|
startTime: '2026-10-27T10:00:00',
|
|
endTime: '2026-10-27T11:00:00',
|
|
},
|
|
{
|
|
id: 'today',
|
|
startTime: '2026-10-27T16:00:00',
|
|
endTime: '2026-10-27T17:00:00',
|
|
},
|
|
{ id: 'day1', startTime: '2026-10-28T09:00:00' },
|
|
{ id: 'day2', startTime: '2026-10-29T09:00:00' },
|
|
{ id: 'day3', startTime: '2026-10-30T09:00:00' },
|
|
];
|
|
|
|
const grouped = groupEvents(events, now, 3);
|
|
|
|
assert.deepEqual(
|
|
grouped.today.map((event) => event.id),
|
|
['today']
|
|
);
|
|
assert.deepEqual(
|
|
grouped.days.map((day) => day.key),
|
|
['2026-10-28', '2026-10-29']
|
|
);
|
|
assert.deepEqual(
|
|
grouped.days.map((day) => day.events.map((event) => event.id)),
|
|
[['day1'], ['day2']]
|
|
);
|
|
});
|
|
|
|
test('groupEvents shows all-day events as today', function (assert) {
|
|
const now = new Date(2026, 9, 27, 15, 0);
|
|
const grouped = groupEvents(
|
|
[{ id: 'holiday', startTime: '2026-10-27', allDay: true }],
|
|
now,
|
|
3
|
|
);
|
|
|
|
assert.deepEqual(
|
|
grouped.today.map((event) => event.id),
|
|
['holiday']
|
|
);
|
|
});
|
|
|
|
test('groupEvents repeats a multi-day all-day event on every day it covers', function (assert) {
|
|
const now = new Date(2026, 9, 27, 15, 0);
|
|
const grouped = groupEvents(
|
|
[
|
|
{
|
|
id: 'trip',
|
|
startTime: '2026-10-27',
|
|
endTime: '2026-10-30',
|
|
allDay: true,
|
|
},
|
|
],
|
|
now,
|
|
3
|
|
);
|
|
|
|
assert.deepEqual(
|
|
grouped.today.map((event) => event.id),
|
|
['trip']
|
|
);
|
|
assert.deepEqual(
|
|
grouped.days.map((day) => day.key),
|
|
['2026-10-28', '2026-10-29']
|
|
);
|
|
assert.deepEqual(
|
|
grouped.days.map((day) => day.events.map((event) => event.id)),
|
|
[['trip'], ['trip']]
|
|
);
|
|
});
|
|
|
|
test('groupEvents shows the next three days when today is empty', function (assert) {
|
|
const now = new Date(2026, 9, 27, 15, 0);
|
|
const grouped = groupEvents(
|
|
[
|
|
{
|
|
id: 'conf',
|
|
startTime: '2026-10-28',
|
|
endTime: '2026-10-31',
|
|
allDay: true,
|
|
},
|
|
],
|
|
now,
|
|
3
|
|
);
|
|
|
|
assert.deepEqual(grouped.today, []);
|
|
assert.deepEqual(
|
|
grouped.days.map((day) => day.key),
|
|
['2026-10-28', '2026-10-29', '2026-10-30']
|
|
);
|
|
assert.deepEqual(
|
|
grouped.days.map((day) => day.events.map((event) => event.id)),
|
|
[['conf'], ['conf'], ['conf']]
|
|
);
|
|
});
|
|
|
|
test('groupEvents caps the future days at the visible limit', function (assert) {
|
|
const now = new Date(2026, 9, 27, 15, 0);
|
|
const grouped = groupEvents(
|
|
[
|
|
{
|
|
id: 'sprint',
|
|
startTime: '2026-10-28',
|
|
endTime: '2026-11-03',
|
|
allDay: true,
|
|
},
|
|
],
|
|
now,
|
|
3
|
|
);
|
|
|
|
assert.deepEqual(grouped.today, []);
|
|
assert.deepEqual(
|
|
grouped.days.map((day) => day.key),
|
|
['2026-10-28', '2026-10-29', '2026-10-30']
|
|
);
|
|
assert.deepEqual(
|
|
grouped.days.map((day) => day.events.map((event) => event.id)),
|
|
[['sprint'], ['sprint'], ['sprint']]
|
|
);
|
|
});
|
|
|
|
test('groupEvents shows an ongoing all-day event as today but skips past days', function (assert) {
|
|
const now = new Date(2026, 9, 27, 15, 0);
|
|
const grouped = groupEvents(
|
|
[
|
|
{
|
|
id: 'retreat',
|
|
startTime: '2026-10-25',
|
|
endTime: '2026-10-29',
|
|
allDay: true,
|
|
},
|
|
],
|
|
now,
|
|
3
|
|
);
|
|
|
|
assert.deepEqual(
|
|
grouped.today.map((event) => event.id),
|
|
['retreat']
|
|
);
|
|
assert.deepEqual(
|
|
grouped.days.map((day) => day.key),
|
|
['2026-10-28']
|
|
);
|
|
assert.deepEqual(
|
|
grouped.days.map((day) => day.events.map((event) => event.id)),
|
|
[['retreat']]
|
|
);
|
|
});
|
|
|
|
test('classifyCalendarError maps platform and connection failures', function (assert) {
|
|
assert.strictEqual(
|
|
classifyCalendarError({ name: 'SockethubConnectionError' }),
|
|
'Unable to reach the Sockethub server'
|
|
);
|
|
assert.strictEqual(
|
|
classifyCalendarError({
|
|
name: 'SockethubPlatformError',
|
|
message: 'caldav:authentication-failed',
|
|
}),
|
|
'Invalid username or password'
|
|
);
|
|
assert.strictEqual(
|
|
classifyCalendarError({
|
|
name: 'SockethubPlatformError',
|
|
message: 'caldav:feed-failed',
|
|
}),
|
|
'Unable to read that calendar link'
|
|
);
|
|
assert.strictEqual(
|
|
classifyCalendarError(new Error('boom')),
|
|
'Unable to load calendar events'
|
|
);
|
|
});
|
|
});
|