Files
raucao 11f8d3f049 WIP: Add calendar settings and a nested modal stack
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.
2026-11-06 15:48:08 +04:00

120 lines
3.4 KiB
Plaintext

import { module, test } from 'qunit';
import { setupRenderingTest } from 'dashtab/tests/helpers';
import { render, click } from '@ember/test-helpers';
import CalendarList from 'dashtab/components/settings/global-settings/sections/calendar-list';
class FakeIntegrations {
constructor(rows = []) {
this.rows = rows;
this.removed = [];
}
async remove(instance) {
this.removed.push(instance);
}
}
class FakeModal {
opened = null;
open(descriptor) {
this.opened = descriptor;
}
}
const CALENDAR_ICON_PATH =
'M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 0 1 2.25-2.25h13.5A2.25 2.25 0 0 1 21 7.5v11.25m-18 0A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75m-18 0v-7.5A2.25 2.25 0 0 1 5.25 9h13.5A2.25 2.25 0 0 1 21 11.25v7.5';
const ROWS = [
{
id: 'caldav-1',
type: 'calendar-caldav',
label: 'CalDAV',
byline: 'cal.example.com',
hasSettings: true,
colorClass: 'bg-rose-500',
iconPath: CALENDAR_ICON_PATH,
},
{
id: 'ics-1',
type: 'calendar-ics',
label: 'ICS / WebCal',
byline: 'example.org',
hasSettings: true,
colorClass: 'bg-rose-500',
iconPath: CALENDAR_ICON_PATH,
},
{
id: 'discourse-1',
type: 'discourse',
label: 'Discourse',
byline: 'forum.example.com',
hasSettings: false,
},
];
function register(owner, { rows = ROWS } = {}) {
const integrations = new FakeIntegrations(rows);
const modal = new FakeModal();
owner.register('service:integrations', integrations, { instantiate: false });
owner.register('service:modal', modal, { instantiate: false });
return { integrations, modal };
}
module(
'Integration | Component | settings/global-settings/sections/calendar-list',
function (hooks) {
setupRenderingTest(hooks);
test('it lists only the calendar sources', async function (assert) {
register(this.owner);
await render(<template><CalendarList /></template>);
assert.dom('[data-instance="caldav-1"]').exists();
assert.dom('[data-instance="ics-1"]').exists();
assert.dom('[data-instance="discourse-1"]').doesNotExist();
});
test('editing a calendar opens its form', async function (assert) {
const { modal } = register(this.owner);
await render(<template><CalendarList /></template>);
await click('[data-instance="caldav-1"] [data-test-settings]');
assert.ok(modal.opened.component);
assert.strictEqual(modal.opened.props.mode, 'edit');
assert.strictEqual(modal.opened.props.integration.id, 'caldav-1');
});
test('removing a calendar removes the source', async function (assert) {
const { integrations } = register(this.owner);
await render(<template><CalendarList /></template>);
await click('[data-instance="ics-1"] [data-test-remove]');
assert.deepEqual(
integrations.removed.map((row) => row.id),
['ics-1']
);
});
test('adding a calendar opens the matching form', async function (assert) {
const { modal } = register(this.owner, { rows: [] });
await render(<template><CalendarList /></template>);
await click('[data-add="calendar-caldav"]');
assert.ok(modal.opened.component);
assert.strictEqual(modal.opened.props.mode, 'add');
await click('[data-add="calendar-ics"]');
assert.ok(modal.opened.component);
assert.strictEqual(modal.opened.props.mode, 'add');
});
}
);