// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import * as Utils from 'utils/channel_utils.jsx'; describe('Channel Utils', () => { describe('findNextUnreadChannelId', () => { test('no channels are unread', () => { const curChannelId = '3'; const allChannelIds = ['1', '2', '3', '4', '5']; const unreadChannelIds = []; expect(Utils.findNextUnreadChannelId(curChannelId, allChannelIds, unreadChannelIds, 1)).toEqual(-1); }); test('only current channel is unread', () => { const curChannelId = '3'; const allChannelIds = ['1', '2', '3', '4', '5']; const unreadChannelIds = ['3']; expect(Utils.findNextUnreadChannelId(curChannelId, allChannelIds, unreadChannelIds, 1)).toEqual(-1); }); test('going forward to unread channels', () => { const curChannelId = '3'; const allChannelIds = ['1', '2', '3', '4', '5']; const unreadChannelIds = ['1', '4', '5']; expect(Utils.findNextUnreadChannelId(curChannelId, allChannelIds, unreadChannelIds, 1)).toEqual(3); }); test('going forward to unread channels with wrapping', () => { const curChannelId = '3'; const allChannelIds = ['1', '2', '3', '4', '5']; const unreadChannelIds = ['1', '2']; expect(Utils.findNextUnreadChannelId(curChannelId, allChannelIds, unreadChannelIds, 1)).toEqual(0); }); test('going backwards to unread channels', () => { const curChannelId = '3'; const allChannelIds = ['1', '2', '3', '4', '5']; const unreadChannelIds = ['1', '4', '5']; expect(Utils.findNextUnreadChannelId(curChannelId, allChannelIds, unreadChannelIds, -1)).toEqual(0); }); test('going backwards to unread channels with wrapping', () => { const curChannelId = '3'; const allChannelIds = ['1', '2', '3', '4', '5']; const unreadChannelIds = ['3', '4', '5']; expect(Utils.findNextUnreadChannelId(curChannelId, allChannelIds, unreadChannelIds, -1)).toEqual(4); }); }); });