From 0dcfcbbafda5496a981d2063c25766aeb9b0a27f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Fri, 23 Jun 2017 02:43:36 +0200 Subject: [PATCH] Add getMessageTab test --- .../state/__tests__/reducer-messages.test.js | 20 ++++++++++++++++++- client/src/js/state/messages.js | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/client/src/js/state/__tests__/reducer-messages.test.js b/client/src/js/state/__tests__/reducer-messages.test.js index 6192a5ec..bf81ae4a 100644 --- a/client/src/js/state/__tests__/reducer-messages.test.js +++ b/client/src/js/state/__tests__/reducer-messages.test.js @@ -1,5 +1,5 @@ import { Map, fromJS } from 'immutable'; -import reducer, { broadcast } from '../messages'; +import reducer, { broadcast, getMessageTab } from '../messages'; import * as actions from '../actions'; import appReducer from '../app'; @@ -176,3 +176,21 @@ describe('message reducer', () => { }); }); }); + +describe('getMessageTab()', () => { + it('returns the correct tab', () => { + const srv = 'chat.freenode.net'; + [ + ['#cake', '#cake'], + ['#apple.pie', '#apple.pie'], + ['bob', 'bob'], + [undefined, srv], + [null, srv], + ['*', srv], + [srv, srv], + ['beans.freenode.net', srv] + ].forEach(([target, expected]) => + expect(getMessageTab(srv, target)).toBe(expected) + ); + }); +}); diff --git a/client/src/js/state/messages.js b/client/src/js/state/messages.js index 3b6f27b0..c00ae8b0 100644 --- a/client/src/js/state/messages.js +++ b/client/src/js/state/messages.js @@ -117,7 +117,7 @@ function initMessage(message, tab, state) { return message; } -function getMessageTab(server, to) { +export function getMessageTab(server, to) { if (!to || to === '*' || (!isChannel(to) && to.indexOf('.') !== -1)) { return server; }