From 0b669dbb9d0e22e5a1082eb9f2423f48c4b6c632 Mon Sep 17 00:00:00 2001 From: Anemy Date: Tue, 9 Feb 2021 17:42:02 +0100 Subject: [PATCH] fix connection title on form connections --- lib/extended-model.js | 4 ++-- test/model.test.js | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/extended-model.js b/lib/extended-model.js index 97bbbad1..9b9eb70c 100644 --- a/lib/extended-model.js +++ b/lib/extended-model.js @@ -87,13 +87,13 @@ const ExtendedConnection = Connection.extend(storageMixin, { return this.hostname; } - if (this.hosts && this.hosts.length) { + if (this.hosts && this.hosts.length > 1) { return this.hosts.map( ({ host, port }) => `${host}:${port}` ).join(','); } - return this.hostname; + return `${this.hostname}:${this.port}`; } } }, diff --git a/test/model.test.js b/test/model.test.js index c9c13c2e..0923b530 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -22,8 +22,14 @@ describe('Connection', () => { it('returns hosts if the connection is not srv', () => { assert.strictEqual( - new Connection({ hosts: [{ host: 'example.com', port: 12345 }] }).title, - 'example.com:12345' + new Connection({ hosts: [{ + host: 'example.com', + port: 12345 + }, { + host: 'example123.com', + port: 123452 + }] }).title, + 'example.com:12345,example123.com:123452' ); }); @@ -37,15 +43,16 @@ describe('Connection', () => { ); }); - it('falls back to hostname if nothing else match', () => { + it('falls back to hostname:port if nothing else match', () => { assert.strictEqual( new Connection({ isSrvRecord: false, isFavorite: false, hosts: [], - hostname: 'somehost' + hostname: 'somehost', + port: 12345 }).title, - 'somehost' + 'somehost:12345' ); }); });