Refactor integration lists into uniform rows with shared avatars
This commit is contained in:
1 parent
abfbabb416
commit
ccb2162bca
9 files changed
+384
-225
No files matched your search
@@ -4,6 +4,7 @@ import { fn } from '@ember/helper';
|
||||
import { on } from '@ember/modifier';
|
||||
import { service } from '@ember/service';
|
||||
import { formFor } from '../../../config/integration-forms';
|
||||
import Avatar from './avatar.gjs';
|
||||
|
||||
export default class SettingsIntegrationsAddList extends Component {
|
||||
@service modal;
|
||||
@@ -57,25 +58,7 @@ export default class SettingsIntegrationsAddList extends Component {
|
||||
'cursor-default'
|
||||
}}"
|
||||
>
|
||||
<div
|
||||
class="flex size-10 flex-none items-center justify-center rounded-lg
|
||||
{{integration.colorClass}}"
|
||||
>
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill={{if integration.iconFill "currentColor" "none"}}
|
||||
stroke={{if integration.iconFill "none" "currentColor"}}
|
||||
stroke-width="1.5"
|
||||
data-slot="icon"
|
||||
class="size-6 text-white"
|
||||
>
|
||||
<path
|
||||
d={{integration.iconPath}}
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<Avatar @integration={{integration}} />
|
||||
<div class="ml-4 flex-auto text-left">
|
||||
<p
|
||||
class="text-sm font-medium
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
import Component from '@glimmer/component';
|
||||
import setStyle from '../../../modifiers/set-style';
|
||||
import { safeColor } from '../../../utils/safe-color';
|
||||
|
||||
// Renders an integration's avatar from the most specific source available:
|
||||
// a resolved site icon, then a bundled image icon, then the brand color and
|
||||
// glyph from the registry.
|
||||
export default class SettingsIntegrationsAvatar extends Component {
|
||||
get integration() {
|
||||
return this.args.integration;
|
||||
}
|
||||
|
||||
get siteIcon() {
|
||||
return this.integration?.icon;
|
||||
}
|
||||
|
||||
get imageClass() {
|
||||
return this.siteIcon?.maskable
|
||||
? 'size-full object-cover'
|
||||
: 'size-7 rounded-md object-contain';
|
||||
}
|
||||
|
||||
get themeColor() {
|
||||
return safeColor(this.siteIcon?.themeColor);
|
||||
}
|
||||
|
||||
<template>
|
||||
{{#if this.siteIcon}}
|
||||
<span
|
||||
class="flex size-10 flex-none items-center justify-center overflow-hidden rounded-lg bg-gray-100 ring-1 ring-gray-200"
|
||||
{{setStyle "background-color" this.themeColor}}
|
||||
>
|
||||
<img
|
||||
src={{this.siteIcon.dataUrl}}
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class={{this.imageClass}}
|
||||
/>
|
||||
</span>
|
||||
{{else if @integration.iconUrl}}
|
||||
<img
|
||||
src={{@integration.iconUrl}}
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="size-10 flex-none rounded-lg object-cover ring-1 ring-gray-200"
|
||||
/>
|
||||
{{else}}
|
||||
<span
|
||||
class="flex size-10 flex-none items-center justify-center rounded-lg
|
||||
{{@integration.colorClass}}"
|
||||
>
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill={{if @integration.iconFill "currentColor" "none"}}
|
||||
stroke={{if @integration.iconFill "none" "currentColor"}}
|
||||
stroke-width="1.5"
|
||||
data-slot="icon"
|
||||
class="size-6 text-white"
|
||||
>
|
||||
<path
|
||||
d={{@integration.iconPath}}
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
</span>
|
||||
{{/if}}
|
||||
</template>
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { fn } from '@ember/helper';
|
||||
import { on } from '@ember/modifier';
|
||||
import { service } from '@ember/service';
|
||||
import { formFor } from '../../../config/integration-forms';
|
||||
import Avatar from './avatar.gjs';
|
||||
|
||||
export default class SettingsIntegrationsManageList extends Component {
|
||||
@service authorization;
|
||||
@@ -12,32 +13,13 @@ export default class SettingsIntegrationsManageList extends Component {
|
||||
@service sites;
|
||||
@service modal;
|
||||
|
||||
get items() {
|
||||
return this.integrations.active.map((integration) => ({
|
||||
...integration,
|
||||
// Single-instance integrations are not grouped: their actions live on
|
||||
// the main row instead of a nested entry.
|
||||
single:
|
||||
!integration.supportsMultiple && integration.instances.length > 0
|
||||
? integration.instances[0]
|
||||
: null,
|
||||
}));
|
||||
get rows() {
|
||||
return this.integrations.rows;
|
||||
}
|
||||
|
||||
@action
|
||||
add(integration) {
|
||||
const component = formFor(integration.id);
|
||||
|
||||
if (!component) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.modal.replace({ component, props: { mode: 'add' }, size: 'md' });
|
||||
}
|
||||
|
||||
@action
|
||||
edit(instance) {
|
||||
const component = formFor(instance.type);
|
||||
edit(row) {
|
||||
const component = formFor(row.type);
|
||||
|
||||
if (!component) {
|
||||
return;
|
||||
@@ -45,17 +27,17 @@ export default class SettingsIntegrationsManageList extends Component {
|
||||
|
||||
this.modal.replace({
|
||||
component,
|
||||
props: { mode: 'edit', integration: instance },
|
||||
props: { mode: 'edit', integration: row },
|
||||
size: 'md',
|
||||
});
|
||||
}
|
||||
|
||||
@action
|
||||
async reconnect(instance) {
|
||||
async reconnect(row) {
|
||||
try {
|
||||
const { transport, integration } = await this.authorization.start(
|
||||
'discourse',
|
||||
instance.url
|
||||
row.type,
|
||||
row.url
|
||||
);
|
||||
|
||||
if (transport === 'extension') {
|
||||
@@ -63,13 +45,13 @@ export default class SettingsIntegrationsManageList extends Component {
|
||||
this.integrationResult.show({ success: true, integration });
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error reconnecting Discourse integration:', err);
|
||||
console.error(`Error reconnecting ${row.type} integration:`, err);
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
async remove(instance) {
|
||||
await this.integrations.remove(instance);
|
||||
async remove(row) {
|
||||
await this.integrations.remove(row);
|
||||
}
|
||||
|
||||
<template>
|
||||
@@ -84,136 +66,53 @@ export default class SettingsIntegrationsManageList extends Component {
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{{#if this.items.length}}
|
||||
{{#if this.rows.length}}
|
||||
<div class="mt-4 min-h-72 max-h-[80vh] overflow-y-auto">
|
||||
{{#each this.items as |integration|}}
|
||||
<section
|
||||
data-integration={{integration.id}}
|
||||
class="border-b border-gray-100 py-3 last:border-b-0"
|
||||
{{#each this.rows as |row|}}
|
||||
<div
|
||||
data-instance={{row.id}}
|
||||
data-integration={{row.type}}
|
||||
class="flex items-center gap-3 border-b border-gray-100 py-3 last:border-b-0"
|
||||
>
|
||||
<div class="flex items-center gap-3">
|
||||
<div
|
||||
class="flex size-10 flex-none items-center justify-center rounded-lg
|
||||
{{integration.colorClass}}"
|
||||
>
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill={{if integration.iconFill "currentColor" "none"}}
|
||||
stroke={{if integration.iconFill "none" "currentColor"}}
|
||||
stroke-width="1.5"
|
||||
data-slot="icon"
|
||||
class="size-6 text-white"
|
||||
>
|
||||
<path
|
||||
d={{integration.iconPath}}
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="flex-auto text-left">
|
||||
<p class="text-sm font-medium text-gray-700">
|
||||
{{integration.label}}
|
||||
</p>
|
||||
<p class="text-sm text-gray-500">
|
||||
{{integration.description}}
|
||||
</p>
|
||||
{{#if integration.single.error}}
|
||||
<p class="text-sm text-red-600">
|
||||
{{integration.single.error}}
|
||||
</p>
|
||||
{{/if}}
|
||||
</div>
|
||||
<Avatar @integration={{row}} />
|
||||
|
||||
{{#if integration.single}}
|
||||
{{#if integration.hasSettings}}
|
||||
<button
|
||||
type="button"
|
||||
data-test-settings
|
||||
{{on "click" (fn this.edit integration.single)}}
|
||||
class="rounded-md px-2.5 py-1.5 text-sm font-semibold text-gray-700 ring-1 ring-inset ring-gray-300 hover:bg-gray-100"
|
||||
>
|
||||
Settings
|
||||
</button>
|
||||
{{/if}}
|
||||
{{#if integration.single.canReconnect}}
|
||||
<button
|
||||
type="button"
|
||||
data-test-reconnect
|
||||
{{on "click" (fn this.reconnect integration.single)}}
|
||||
class="rounded-md px-2.5 py-1.5 text-sm font-semibold text-gray-700 ring-1 ring-inset ring-gray-300 hover:bg-gray-100"
|
||||
>
|
||||
Reconnect
|
||||
</button>
|
||||
{{/if}}
|
||||
<button
|
||||
type="button"
|
||||
data-test-remove
|
||||
{{on "click" (fn this.remove integration.single)}}
|
||||
class="rounded-md px-2.5 py-1.5 text-sm font-semibold text-red-600 ring-1 ring-inset ring-red-200 hover:bg-red-50"
|
||||
>
|
||||
Remove
|
||||
</button>
|
||||
{{else}}
|
||||
{{#if integration.supportsMultiple}}
|
||||
<button
|
||||
type="button"
|
||||
data-test-add
|
||||
{{on "click" (fn this.add integration)}}
|
||||
class="rounded-md px-2.5 py-1.5 text-sm font-semibold text-indigo-600 ring-1 ring-inset ring-indigo-200 hover:bg-indigo-50"
|
||||
>
|
||||
Add another
|
||||
</button>
|
||||
{{/if}}
|
||||
<div class="flex-auto text-left">
|
||||
<p class="text-sm font-medium text-gray-700">{{row.label}}</p>
|
||||
<p class="text-sm text-gray-500">{{row.byline}}</p>
|
||||
{{#if row.error}}
|
||||
<p class="text-sm text-red-600">{{row.error}}</p>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
{{#unless integration.single}}
|
||||
{{#each integration.instances as |instance|}}
|
||||
<div
|
||||
data-instance={{instance.id}}
|
||||
class="mt-2 ml-13 flex items-center gap-2 rounded-xl bg-gray-50 p-3"
|
||||
>
|
||||
<div class="flex-auto text-left">
|
||||
<p class="text-sm font-medium text-gray-700">
|
||||
{{instance.label}}
|
||||
</p>
|
||||
{{#if instance.error}}
|
||||
<p class="text-sm text-red-600">{{instance.error}}</p>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{#if integration.hasSettings}}
|
||||
<button
|
||||
type="button"
|
||||
data-test-settings
|
||||
{{on "click" (fn this.edit instance)}}
|
||||
class="rounded-md px-2.5 py-1.5 text-sm font-semibold text-gray-700 ring-1 ring-inset ring-gray-300 hover:bg-gray-100"
|
||||
>
|
||||
Settings
|
||||
</button>
|
||||
{{/if}}
|
||||
{{#if instance.canReconnect}}
|
||||
<button
|
||||
type="button"
|
||||
data-test-reconnect
|
||||
{{on "click" (fn this.reconnect instance)}}
|
||||
class="rounded-md px-2.5 py-1.5 text-sm font-semibold text-gray-700 ring-1 ring-inset ring-gray-300 hover:bg-gray-100"
|
||||
>
|
||||
Reconnect
|
||||
</button>
|
||||
{{/if}}
|
||||
<button
|
||||
type="button"
|
||||
data-test-remove
|
||||
{{on "click" (fn this.remove instance)}}
|
||||
class="rounded-md px-2.5 py-1.5 text-sm font-semibold text-red-600 ring-1 ring-inset ring-red-200 hover:bg-red-50"
|
||||
>
|
||||
Remove
|
||||
</button>
|
||||
</div>
|
||||
{{/each}}
|
||||
{{/unless}}
|
||||
</section>
|
||||
{{#if row.hasSettings}}
|
||||
<button
|
||||
type="button"
|
||||
data-test-settings
|
||||
{{on "click" (fn this.edit row)}}
|
||||
class="rounded-md px-2.5 py-1.5 text-sm font-semibold text-gray-700 ring-1 ring-inset ring-gray-300 hover:bg-gray-100"
|
||||
>
|
||||
Settings
|
||||
</button>
|
||||
{{/if}}
|
||||
{{#if row.canReconnect}}
|
||||
<button
|
||||
type="button"
|
||||
data-test-reconnect
|
||||
{{on "click" (fn this.reconnect row)}}
|
||||
class="rounded-md px-2.5 py-1.5 text-sm font-semibold text-gray-700 ring-1 ring-inset ring-gray-300 hover:bg-gray-100"
|
||||
>
|
||||
Reconnect
|
||||
</button>
|
||||
{{/if}}
|
||||
<button
|
||||
type="button"
|
||||
data-test-remove
|
||||
{{on "click" (fn this.remove row)}}
|
||||
class="rounded-md px-2.5 py-1.5 text-sm font-semibold text-red-600 ring-1 ring-inset ring-red-200 hover:bg-red-50"
|
||||
>
|
||||
Remove
|
||||
</button>
|
||||
</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
{{else}}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import Component from '@glimmer/component';
|
||||
import setStyle from '../../modifiers/set-style';
|
||||
|
||||
const SAFE_COLOR =
|
||||
/^(#[0-9a-f]{3,8}|rgba?\([\d\s.,%]+\)|hsla?\([\d\s.,%]+\)|[a-z]+)$/i;
|
||||
import { safeColor } from '../../utils/safe-color';
|
||||
|
||||
export default class SiteLinksItemComponent extends Component {
|
||||
get label() {
|
||||
@@ -36,15 +34,8 @@ export default class SiteLinksItemComponent extends Component {
|
||||
: 'size-7 rounded-md object-contain';
|
||||
}
|
||||
|
||||
// The theme color comes from the remote site, so only pass through values
|
||||
// that look like plain CSS colors.
|
||||
get tileColor() {
|
||||
const color = this.icon?.themeColor;
|
||||
if (typeof color !== 'string') {
|
||||
return undefined;
|
||||
}
|
||||
const trimmed = color.trim();
|
||||
return SAFE_COLOR.test(trimmed) ? trimmed : undefined;
|
||||
return safeColor(this.icon?.themeColor);
|
||||
}
|
||||
|
||||
get tooltip() {
|
||||
|
||||
@@ -17,6 +17,7 @@ const ADAPTERS = {
|
||||
type: 'discourse',
|
||||
label: site.label,
|
||||
url: site.url,
|
||||
icon: site.icon,
|
||||
status: 'active',
|
||||
error: state.error,
|
||||
errorType: state.errorType,
|
||||
@@ -56,6 +57,8 @@ export default class IntegrationsService extends Service {
|
||||
@service bitcoin;
|
||||
@service notifications;
|
||||
|
||||
// Registry metadata enriched with each type's live instances. Used by the Add
|
||||
// screen to decide what can still be connected.
|
||||
get all() {
|
||||
return INTEGRATIONS.map((integration) => ({
|
||||
...integration,
|
||||
@@ -63,8 +66,27 @@ export default class IntegrationsService extends Service {
|
||||
}));
|
||||
}
|
||||
|
||||
get active() {
|
||||
return this.all.filter((integration) => integration.instances.length > 0);
|
||||
// Flat, per-instance rows for the Manage screen: one row per connected item,
|
||||
// regardless of whether the integration supports multiple instances. Each row
|
||||
// carries the registry metadata (label, avatar, actions) alongside its live
|
||||
// state, so the component can render every row the same way. Integrations
|
||||
// with settings are sorted to the top; the stable sort keeps registry order
|
||||
// within each group.
|
||||
get rows() {
|
||||
return INTEGRATIONS.flatMap((integration) =>
|
||||
this.instancesFor(integration.id).map((instance) => ({
|
||||
...instance,
|
||||
type: integration.id,
|
||||
label: integration.label,
|
||||
byline: instance.url || integration.description,
|
||||
colorClass: integration.colorClass,
|
||||
iconPath: integration.iconPath,
|
||||
iconFill: integration.iconFill,
|
||||
iconUrl: integration.iconUrl,
|
||||
hasSettings: integration.hasSettings,
|
||||
reconnectable: integration.reconnectable,
|
||||
}))
|
||||
).sort((a, b) => Number(b.hasSettings) - Number(a.hasSettings));
|
||||
}
|
||||
|
||||
integrationFor(type) {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
const SAFE_COLOR =
|
||||
/^(#[0-9a-f]{3,8}|rgba?\([\d\s.,%]+\)|hsla?\([\d\s.,%]+\)|[a-z]+)$/i;
|
||||
|
||||
// Site icons come from remote sites, so only pass through values that look
|
||||
// like plain CSS colors before handing them to a style modifier.
|
||||
export function safeColor(value) {
|
||||
if (typeof value !== 'string') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const trimmed = value.trim();
|
||||
return SAFE_COLOR.test(trimmed) ? trimmed : undefined;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'dashtab/tests/helpers';
|
||||
import { render } from '@ember/test-helpers';
|
||||
import Avatar from 'dashtab/components/settings/integrations/avatar';
|
||||
|
||||
module(
|
||||
'Integration | Component | settings/integrations/avatar',
|
||||
function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders a resolved maskable site icon full-bleed', async function (assert) {
|
||||
this.integration = {
|
||||
icon: { dataUrl: 'data:image/png;base64,abc', maskable: true },
|
||||
};
|
||||
|
||||
await render(
|
||||
<template><Avatar @integration={{this.integration}} /></template>
|
||||
);
|
||||
|
||||
assert
|
||||
.dom('img')
|
||||
.exists()
|
||||
.hasAttribute('src', 'data:image/png;base64,abc');
|
||||
assert.dom('img').hasClass('object-cover');
|
||||
assert.dom('svg').doesNotExist();
|
||||
});
|
||||
|
||||
test('it renders a non-maskable site icon inset', async function (assert) {
|
||||
this.integration = {
|
||||
icon: { dataUrl: 'data:image/png;base64,abc', maskable: false },
|
||||
};
|
||||
|
||||
await render(
|
||||
<template><Avatar @integration={{this.integration}} /></template>
|
||||
);
|
||||
|
||||
assert.dom('img').hasAttribute('src', 'data:image/png;base64,abc');
|
||||
assert.dom('img').hasClass('object-contain');
|
||||
});
|
||||
|
||||
test('it renders a bundled image icon', async function (assert) {
|
||||
this.integration = { iconUrl: '/img/feedbin.png' };
|
||||
|
||||
await render(
|
||||
<template><Avatar @integration={{this.integration}} /></template>
|
||||
);
|
||||
|
||||
assert.dom('img').hasAttribute('src', '/img/feedbin.png');
|
||||
assert.dom('svg').doesNotExist();
|
||||
});
|
||||
|
||||
test('it falls back to the brand color and glyph', async function (assert) {
|
||||
this.integration = {
|
||||
colorClass: 'bg-indigo-500',
|
||||
iconPath: 'M0 0h24v24H0z',
|
||||
iconFill: false,
|
||||
};
|
||||
|
||||
await render(
|
||||
<template><Avatar @integration={{this.integration}} /></template>
|
||||
);
|
||||
|
||||
assert.dom('img').doesNotExist();
|
||||
assert.dom('svg').exists();
|
||||
assert.dom('svg path').hasAttribute('d', 'M0 0h24v24H0z');
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -9,6 +9,10 @@ class FakeSitesService {
|
||||
removed = [];
|
||||
reloaded = 0;
|
||||
|
||||
integrationFor(id) {
|
||||
return this.records?.[id];
|
||||
}
|
||||
|
||||
async removeSource(id) {
|
||||
this.removed.push(id);
|
||||
this.all = this.all.filter((site) => site.id !== id);
|
||||
@@ -112,13 +116,13 @@ module(
|
||||
|
||||
await render(<template><List /></template>);
|
||||
|
||||
assert.dom('[data-integration]').doesNotExist();
|
||||
assert.dom('[data-instance]').doesNotExist();
|
||||
assert
|
||||
.dom()
|
||||
.containsText("You don't have any integrations connected yet");
|
||||
});
|
||||
|
||||
test('it only lists active integrations', async function (assert) {
|
||||
test('it lists one row per connected integration', async function (assert) {
|
||||
const sites = new FakeSitesService();
|
||||
sites.all = [
|
||||
{
|
||||
@@ -136,11 +140,101 @@ module(
|
||||
|
||||
await render(<template><List /></template>);
|
||||
|
||||
assert.dom('[data-integration="discourse"]').exists();
|
||||
assert.dom('[data-integration="bitcoin"]').exists();
|
||||
assert.dom('[data-instance="discourse-abc"]').exists();
|
||||
assert.dom('[data-instance="bitcoin"]').exists();
|
||||
assert.dom('[data-integration="gitea"]').doesNotExist();
|
||||
});
|
||||
|
||||
test('it lists integrations with settings above discourse sites', async function (assert) {
|
||||
const sites = new FakeSitesService();
|
||||
sites.all = [
|
||||
{
|
||||
id: 'discourse-abc',
|
||||
type: 'discourse',
|
||||
label: 'forum.example.com',
|
||||
url: 'https://forum.example.com',
|
||||
},
|
||||
];
|
||||
|
||||
const bitcoin = new FakeBitcoinService();
|
||||
bitcoin.enabled = true;
|
||||
|
||||
register(this.owner, { sites, bitcoin });
|
||||
|
||||
await render(<template><List /></template>);
|
||||
|
||||
const ids = [...document.querySelectorAll('[data-instance]')].map(
|
||||
(el) => el.dataset.instance
|
||||
);
|
||||
assert.deepEqual(ids, ['bitcoin', 'discourse-abc']);
|
||||
});
|
||||
|
||||
test('it renders each discourse instance as its own row', async function (assert) {
|
||||
const sites = new FakeSitesService();
|
||||
sites.all = [
|
||||
{
|
||||
id: 'discourse-abc',
|
||||
type: 'discourse',
|
||||
label: 'a.example.com',
|
||||
url: 'https://a.example.com',
|
||||
},
|
||||
{
|
||||
id: 'discourse-def',
|
||||
type: 'discourse',
|
||||
label: 'b.example.com',
|
||||
url: 'https://b.example.com',
|
||||
},
|
||||
];
|
||||
|
||||
register(this.owner, { sites });
|
||||
|
||||
await render(<template><List /></template>);
|
||||
|
||||
assert.dom('[data-instance]').exists({ count: 2 });
|
||||
assert.dom('[data-instance="discourse-abc"]').exists();
|
||||
assert.dom('[data-instance="discourse-def"]').exists();
|
||||
});
|
||||
|
||||
test('discourse rows show the integration name and the URL as byline', async function (assert) {
|
||||
const sites = new FakeSitesService();
|
||||
sites.all = [
|
||||
{
|
||||
id: 'discourse-abc',
|
||||
type: 'discourse',
|
||||
label: 'forum.example.com',
|
||||
url: 'https://forum.example.com',
|
||||
},
|
||||
];
|
||||
|
||||
register(this.owner, { sites });
|
||||
|
||||
await render(<template><List /></template>);
|
||||
|
||||
assert.dom('[data-instance="discourse-abc"]').containsText('Discourse');
|
||||
assert
|
||||
.dom('[data-instance="discourse-abc"]')
|
||||
.containsText('https://forum.example.com');
|
||||
assert
|
||||
.dom('[data-instance="discourse-abc"] [data-test-settings]')
|
||||
.doesNotExist();
|
||||
});
|
||||
|
||||
test('feature integrations keep their description as byline', async function (assert) {
|
||||
const bitcoin = new FakeBitcoinService();
|
||||
bitcoin.enabled = true;
|
||||
|
||||
register(this.owner, { bitcoin });
|
||||
|
||||
await render(<template><List /></template>);
|
||||
|
||||
assert
|
||||
.dom('[data-instance="bitcoin"]')
|
||||
.containsText('Bitcoin Price Ticker');
|
||||
assert
|
||||
.dom('[data-instance="bitcoin"]')
|
||||
.containsText('Live BTC price on your dashboard');
|
||||
});
|
||||
|
||||
test('it only offers reconnect when auth is broken', async function (assert) {
|
||||
const sites = new FakeSitesService();
|
||||
sites.all = [
|
||||
@@ -214,7 +308,7 @@ module(
|
||||
assert.strictEqual(integrationResult.shown.length, 1);
|
||||
});
|
||||
|
||||
test('removing a discourse instance removes the source', async function (assert) {
|
||||
test('removing an instance removes the source', async function (assert) {
|
||||
const sites = new FakeSitesService();
|
||||
sites.all = [
|
||||
{
|
||||
@@ -233,32 +327,7 @@ module(
|
||||
assert.deepEqual(sites.removed, ['discourse-abc']);
|
||||
});
|
||||
|
||||
test('a multi-instance integration keeps its grouping', async function (assert) {
|
||||
const sites = new FakeSitesService();
|
||||
sites.all = [
|
||||
{
|
||||
id: 'discourse-abc',
|
||||
type: 'discourse',
|
||||
label: 'forum.example.com',
|
||||
url: 'https://forum.example.com',
|
||||
},
|
||||
];
|
||||
|
||||
const { modal } = register(this.owner, { sites });
|
||||
|
||||
await render(<template><List /></template>);
|
||||
|
||||
assert.dom('[data-instance="discourse-abc"]').exists();
|
||||
assert
|
||||
.dom('[data-integration="discourse"] [data-test-add]')
|
||||
.containsText('Add another');
|
||||
|
||||
await click('[data-integration="discourse"] [data-test-add]');
|
||||
|
||||
assert.strictEqual(modal.replaced.props.mode, 'add');
|
||||
});
|
||||
|
||||
test('a single-instance integration is not grouped', async function (assert) {
|
||||
test('editing a feature integration opens its form', async function (assert) {
|
||||
const bitcoin = new FakeBitcoinService();
|
||||
bitcoin.enabled = true;
|
||||
bitcoin.interval = 60000;
|
||||
@@ -268,20 +337,18 @@ module(
|
||||
|
||||
await render(<template><List /></template>);
|
||||
|
||||
assert.dom('[data-instance="bitcoin"]').doesNotExist();
|
||||
assert.dom('[data-integration="bitcoin"] [data-test-settings]').exists();
|
||||
assert.dom('[data-instance="bitcoin"] [data-test-settings]').exists();
|
||||
assert
|
||||
.dom('[data-integration="bitcoin"] [data-test-reconnect]')
|
||||
.dom('[data-instance="bitcoin"] [data-test-reconnect]')
|
||||
.doesNotExist();
|
||||
assert.dom('[data-integration="bitcoin"] [data-test-add]').doesNotExist();
|
||||
|
||||
await click('[data-integration="bitcoin"] [data-test-settings]');
|
||||
await click('[data-instance="bitcoin"] [data-test-settings]');
|
||||
|
||||
assert.strictEqual(modal.replaced.props.mode, 'edit');
|
||||
assert.strictEqual(modal.replaced.props.integration.interval, 60000);
|
||||
assert.strictEqual(modal.replaced.props.integration.provider, 'binance');
|
||||
|
||||
await click('[data-integration="bitcoin"] [data-test-remove]');
|
||||
await click('[data-instance="bitcoin"] [data-test-remove]');
|
||||
|
||||
assert.true(bitcoin.disabled);
|
||||
});
|
||||
|
||||
@@ -88,12 +88,59 @@ module('Unit | Service | integrations', function (hooks) {
|
||||
assert.strictEqual(gitea.instances.length, 0);
|
||||
});
|
||||
|
||||
test('active only includes integrations with instances', function (assert) {
|
||||
test('rows is empty when nothing is connected', function (assert) {
|
||||
register(this.owner);
|
||||
|
||||
const service = this.owner.lookup('service:integrations');
|
||||
|
||||
assert.deepEqual(service.active, []);
|
||||
assert.deepEqual(service.rows, []);
|
||||
});
|
||||
|
||||
test('rows flattens every connected instance with a label, byline and avatar', function (assert) {
|
||||
const sites = new FakeSitesService();
|
||||
sites.all = [
|
||||
{
|
||||
id: 'discourse-a',
|
||||
type: 'discourse',
|
||||
label: 'a.example.com',
|
||||
url: 'https://a.example.com',
|
||||
icon: { dataUrl: 'data:image/png;base64,a', maskable: true },
|
||||
},
|
||||
{
|
||||
id: 'discourse-b',
|
||||
type: 'discourse',
|
||||
label: 'b.example.com',
|
||||
url: 'https://b.example.com',
|
||||
},
|
||||
];
|
||||
|
||||
const bitcoin = new FakeBitcoinService();
|
||||
bitcoin.enabled = true;
|
||||
|
||||
register(this.owner, { sites, bitcoin });
|
||||
|
||||
const service = this.owner.lookup('service:integrations');
|
||||
const rows = service.rows;
|
||||
|
||||
assert.strictEqual(rows.length, 3);
|
||||
// Rows with settings sort first; Discourse (no settings) comes last. The
|
||||
// stable sort keeps registry order within each group.
|
||||
assert.deepEqual(
|
||||
rows.map((row) => row.id),
|
||||
['bitcoin', 'discourse-a', 'discourse-b']
|
||||
);
|
||||
|
||||
const discourseRow = rows.find((row) => row.id === 'discourse-a');
|
||||
assert.strictEqual(discourseRow.label, 'Discourse');
|
||||
assert.strictEqual(discourseRow.byline, 'https://a.example.com');
|
||||
assert.deepEqual(discourseRow.icon, {
|
||||
dataUrl: 'data:image/png;base64,a',
|
||||
maskable: true,
|
||||
});
|
||||
|
||||
const bitcoinRow = rows.find((row) => row.type === 'bitcoin');
|
||||
assert.strictEqual(bitcoinRow.label, 'Bitcoin Price Ticker');
|
||||
assert.strictEqual(bitcoinRow.byline, 'Live BTC price on your dashboard');
|
||||
});
|
||||
|
||||
test('remove delegates to each integration adapter', async function (assert) {
|
||||
|
||||
Reference in new issue
Block a user