Add getMessageTab test

This commit is contained in:
Ken-Håvard Lieng 2017-06-23 02:43:36 +02:00
parent 54462b8a1b
commit 0dcfcbbafd
2 changed files with 20 additions and 2 deletions

View File

@ -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)
);
});
});

View File

@ -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;
}