Files
raucao fd0d29760c WIP: Add Protocol Gateway settings section and tighten the dialog
Introduce a per-section content registry (contentFor) mirroring the integration form registry, and use it for a new Advanced > Protocol Gateway section that explains Sockethub and edits the server URL, with a live connection status.

The URL field loads the stored value via sockethub.loadUrl() so it never prefills the default over a saved URL, and save failures surface inline.

Also narrow the settings dialog (sm:max-w-4xl) and sidebar (sm:w-52) and shorten it (min(80vh,40rem)).
2026-11-06 14:31:40 +04:00

123 lines
3.9 KiB
Plaintext

import { module, test } from 'qunit';
import { setupRenderingTest } from 'dashtab/tests/helpers';
import { render, fillIn, triggerEvent } from '@ember/test-helpers';
import ProtocolGateway from 'dashtab/components/settings/global-settings/sections/protocol-gateway';
import { DEFAULT_SOCKETHUB_URL } from 'dashtab/config/sockethub';
function registerSockethub(owner, overrides = {}) {
const sockethub = {
url: overrides.url ?? null,
status: overrides.status ?? 'disconnected',
error: overrides.error ?? null,
saved: [],
loadUrl() {
this.url = overrides.storedUrl ?? this.url;
return Promise.resolve(this.url);
},
setUrl(url) {
this.saved.push(url);
if (overrides.reject) {
return Promise.reject(
new Error('Unable to reach that Sockethub server')
);
}
this.url = url;
return Promise.resolve();
},
};
owner.register('service:sockethub', sockethub, { instantiate: false });
return sockethub;
}
module(
'Integration | Component | settings/global-settings/sections/protocol-gateway',
function (hooks) {
setupRenderingTest(hooks);
test('explains Sockethub and links to the website', async function (assert) {
registerSockethub(this.owner, { url: DEFAULT_SOCKETHUB_URL });
await render(<template><ProtocolGateway /></template>);
assert.dom('a[href="https://sockethub.org"]').exists();
assert.dom('input#sockethub-url').hasValue(DEFAULT_SOCKETHUB_URL);
});
test('prefills a stored custom URL instead of the default', async function (assert) {
registerSockethub(this.owner, {
storedUrl: 'https://self.example.org',
});
await render(<template><ProtocolGateway /></template>);
assert.dom('input#sockethub-url').hasValue('https://self.example.org');
});
test('rejects an invalid URL without saving', async function (assert) {
const sockethub = registerSockethub(this.owner, {
url: DEFAULT_SOCKETHUB_URL,
});
await render(<template><ProtocolGateway /></template>);
await fillIn('input#sockethub-url', 'not a url');
await triggerEvent('form', 'submit');
assert.dom('[data-test-error]').exists();
assert.deepEqual(sockethub.saved, []);
});
test('saves the normalized origin and confirms', async function (assert) {
const sockethub = registerSockethub(this.owner, {
url: DEFAULT_SOCKETHUB_URL,
});
await render(<template><ProtocolGateway /></template>);
await fillIn('input#sockethub-url', 'https://host.example.org/path?q=1');
await triggerEvent('form', 'submit');
assert.deepEqual(sockethub.saved, ['https://host.example.org']);
assert.dom('[data-test-saved]').exists();
});
test('surfaces a save failure without reporting success', async function (assert) {
registerSockethub(this.owner, {
url: DEFAULT_SOCKETHUB_URL,
reject: true,
});
await render(<template><ProtocolGateway /></template>);
await fillIn('input#sockethub-url', 'https://host.example.org');
await triggerEvent('form', 'submit');
assert.dom('[data-test-error]').exists();
assert.dom('[data-test-saved]').doesNotExist();
});
test('shows a connected status', async function (assert) {
registerSockethub(this.owner, {
url: DEFAULT_SOCKETHUB_URL,
status: 'ready',
});
await render(<template><ProtocolGateway /></template>);
assert.dom('[data-test-status]').hasText('Connected');
});
test('shows the last error when the connection fails', async function (assert) {
registerSockethub(this.owner, {
url: DEFAULT_SOCKETHUB_URL,
status: 'error',
error: 'caldav:authentication-failed',
});
await render(<template><ProtocolGateway /></template>);
assert
.dom('[data-test-status]')
.hasText('Last error: caldav:authentication-failed');
});
}
);