Strip scheme from integration bylines
This commit is contained in:
1 parent
11be348a37
commit
1a3bc001a2
5 files changed
+37
-4
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import Service, { service } from '@ember/service';
|
||||
import { INTEGRATIONS, integrationFor } from '../config/integrations';
|
||||
import { displayUrl } from '../utils/display-url';
|
||||
|
||||
// Bridges the static integration registry with the live instance state owned by
|
||||
// the `sites` (auth-based) and `bitcoin` services, so the Add/Manage screens can
|
||||
@@ -168,7 +169,7 @@ export default class IntegrationsService extends Service {
|
||||
...instance,
|
||||
type: integration.id,
|
||||
label: integration.label,
|
||||
byline: instance.url || integration.description,
|
||||
byline: displayUrl(instance.url) || integration.description,
|
||||
colorClass: integration.colorClass,
|
||||
iconPath: integration.iconPath,
|
||||
iconFill: integration.iconFill,
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// Instance URLs are shown as bylines, where the scheme is visual noise. Keep
|
||||
// the stored URL intact for network calls and strip it only for display.
|
||||
export function displayUrl(url) {
|
||||
return typeof url === 'string' ? url.replace(/^https?:\/\//, '') : '';
|
||||
}
|
||||
@@ -200,7 +200,7 @@ module(
|
||||
assert.dom('[data-instance="discourse-def"]').exists();
|
||||
});
|
||||
|
||||
test('discourse rows show the integration name and the URL as byline', async function (assert) {
|
||||
test('discourse rows show the integration name and the host as byline', async function (assert) {
|
||||
const sites = new FakeSitesService();
|
||||
sites.all = [
|
||||
{
|
||||
@@ -218,7 +218,7 @@ module(
|
||||
assert.dom('[data-instance="discourse-abc"]').containsText('Discourse');
|
||||
assert
|
||||
.dom('[data-instance="discourse-abc"]')
|
||||
.containsText('https://forum.example.com');
|
||||
.containsText('forum.example.com');
|
||||
assert
|
||||
.dom('[data-instance="discourse-abc"] [data-test-settings]')
|
||||
.doesNotExist();
|
||||
|
||||
@@ -147,7 +147,7 @@ module('Unit | Service | integrations', function (hooks) {
|
||||
|
||||
const discourseRow = rows.find((row) => row.id === 'discourse-a');
|
||||
assert.strictEqual(discourseRow.label, 'Discourse');
|
||||
assert.strictEqual(discourseRow.byline, 'https://a.example.com');
|
||||
assert.strictEqual(discourseRow.byline, 'a.example.com');
|
||||
assert.deepEqual(discourseRow.icon, {
|
||||
dataUrl: 'data:image/png;base64,a',
|
||||
maskable: true,
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { displayUrl } from 'dashtab/utils/display-url';
|
||||
|
||||
module('Unit | Utility | display-url', function () {
|
||||
test('strips the https scheme', function (assert) {
|
||||
assert.strictEqual(
|
||||
displayUrl('https://forum.example.com'),
|
||||
'forum.example.com'
|
||||
);
|
||||
});
|
||||
|
||||
test('strips the http scheme', function (assert) {
|
||||
assert.strictEqual(
|
||||
displayUrl('http://forum.example.com'),
|
||||
'forum.example.com'
|
||||
);
|
||||
});
|
||||
|
||||
test('leaves a scheme-less value untouched', function (assert) {
|
||||
assert.strictEqual(displayUrl('forum.example.com'), 'forum.example.com');
|
||||
});
|
||||
|
||||
test('returns an empty string for missing values', function (assert) {
|
||||
assert.strictEqual(displayUrl(undefined), '');
|
||||
assert.strictEqual(displayUrl(null), '');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user