Files
raucao 4c9d6093c0 Skip the Sockethub server step in calendar setup when already configured
Track whether a Sockethub URL has been stored and start the ICS and CalDAV add flows past the server step for returning users, while keeping it for first-timers. Back navigation stops before the removed step, and the step's helper text now links Sockethub to its website.
2026-11-07 13:38:33 +04:00

135 lines
4.1 KiB
Plaintext

import { module, test } from 'qunit';
import { setupRenderingTest } from 'dashtab/tests/helpers';
import { render, fillIn, triggerEvent } from '@ember/test-helpers';
import CalendarIcsForm from 'dashtab/components/settings/integrations/calendar-ics-form';
function registerServices(owner, overrides = {}) {
const calendar = overrides.calendar ?? {
verifyFeed: async () => ({ name: 'Calendar' }),
configureIcs: async () => {},
};
const sockethub = overrides.sockethub ?? {
url: 'https://sh.example.org',
hasStoredUrl: false,
loadUrl: async () => 'https://sh.example.org',
async setUrl(url) {
this.url = url;
this.hasStoredUrl = true;
},
};
owner.register('service:calendar', calendar, { instantiate: false });
owner.register('service:sockethub', sockethub, { instantiate: false });
}
module(
'Integration | Component | settings/integrations/calendar-ics-form',
function (hooks) {
setupRenderingTest(hooks);
test('walks through server and feed, then saves', async function (assert) {
const verified = [];
const configured = [];
let closed = false;
registerServices(this.owner, {
calendar: {
verifyFeed: async (url) => {
verified.push(url);
return { name: 'Holidays' };
},
configureIcs: async (config, key) => configured.push({ config, key }),
},
});
const closeDialog = () => {
closed = true;
};
await render(
<template><CalendarIcsForm @close={{closeDialog}} /></template>
);
assert.dom().containsText('Add ICS / WebCal Calendar');
assert.dom('#ics-server-url').hasValue('https://sh.example.org');
assert.dom('a[href="https://sockethub.org"]').exists();
await triggerEvent('form', 'submit');
assert.dom('#ics-feed-url').exists();
assert.dom('[data-test-back]').exists();
await fillIn('#ics-feed-url', 'https://example.org/h.ics');
await triggerEvent('form', 'submit');
assert.deepEqual(verified, ['https://example.org/h.ics']);
assert.strictEqual(configured.length, 1);
assert.strictEqual(configured[0].config.name, 'Holidays');
assert.strictEqual(configured[0].config.url, 'https://example.org/h.ics');
assert.true(closed);
});
test('validates the feed link', async function (assert) {
const verified = [];
registerServices(this.owner, {
calendar: {
verifyFeed: async (...args) => verified.push(args),
configureIcs: async () => {},
},
});
const noop = () => {};
await render(<template><CalendarIcsForm @close={{noop}} /></template>);
await triggerEvent('form', 'submit');
await fillIn('#ics-feed-url', 'not a link');
await triggerEvent('form', 'submit');
assert.dom().containsText('Please enter a valid .ics or webcal:// link');
assert.strictEqual(verified.length, 0);
});
test('skips the server step when a Sockethub URL is stored', async function (assert) {
registerServices(this.owner, {
sockethub: {
url: 'https://sh.example.org',
hasStoredUrl: true,
loadUrl: async () => 'https://sh.example.org',
setUrl: async () => {},
},
});
const noop = () => {};
await render(<template><CalendarIcsForm @close={{noop}} /></template>);
assert.dom('#ics-server-url').doesNotExist();
assert.dom('#ics-feed-url').exists();
assert.dom('[data-test-back]').doesNotExist();
});
test('edit opens on the feed step prefilled', async function (assert) {
registerServices(this.owner);
this.props = {
mode: 'edit',
integration: {
id: 'calendar-ics-example.org',
url: 'https://example.org/h.ics',
label: 'Holidays',
},
};
const noop = () => {};
await render(
<template>
<CalendarIcsForm @props={{this.props}} @close={{noop}} />
</template>
);
assert.dom().containsText('Edit ICS / WebCal Calendar');
assert.dom('#ics-feed-url').hasValue('https://example.org/h.ics');
});
}
);