mattermost-mobile/app/components/sidebars/main/main_sidebar.test.js
Shaz Amjad 64223efafe
MM-28474: Custom Sidebar Categories (#5460)
* Further cleanup and fixes

Tests clean-up

Tests fixed?

Plays nicely with threads

Tests fixed

Fixes ESR and show experimental flags

Failing test fixed

DM Fix

WIP: Bottom bar UX

Fixes for unreads

Failing test

Always show current channel

Create a channel in a category!

* Unreads on top

* Various fixes

* Improves category collapsing

* Passes correct ID through

* Tests cleanup

* Redo unreads and unread-button

* Reverts to just using ids

* More unreads back to using ids

* Uses appropriate selectors for pref updates

* Unreads sorted by recency

* Fixes test for recency

* Fixes re-rendering bug

* Code review updates, websocket event debounced
2021-09-20 14:11:57 -04:00

80 lines
2.3 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {DeviceTypes} from '@constants';
import Preferences from '@mm-redux/constants/preferences';
import {shallowWithIntl} from '@test/intl-test-helper';
import MainSidebar from './main_sidebar.ios';
describe('MainSidebar', () => {
const baseProps = {
actions: {
getTeams: jest.fn(),
makeDirectChannel: jest.fn(),
setChannelDisplayName: jest.fn(),
setChannelLoading: jest.fn(),
joinChannel: jest.fn(),
setCategoryCollapsed: jest.fn(),
},
blurPostTextBox: jest.fn(),
currentTeamId: 'current-team-id',
currentUserId: 'current-user-id',
deviceWidth: 10,
isLandscape: false,
teamsCount: 2,
theme: Preferences.THEMES.denim,
};
const loadShallow = (props) => {
return shallowWithIntl(
<MainSidebar {...(props || baseProps)}/>,
);
};
test('should match, full snapshot', () => {
const wrapper = loadShallow();
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should not set the permanentSidebar state if not Tablet', () => {
const wrapper = loadShallow();
wrapper.instance().handlePermanentSidebar();
expect(wrapper.state('permanentSidebar')).toBeFalsy();
});
test('should set the permanentSidebar state if Tablet', async () => {
const wrapper = loadShallow();
DeviceTypes.IS_TABLET = true;
await wrapper.instance().handlePermanentSidebar();
expect(wrapper.state('permanentSidebar')).toBeDefined();
// Reset to false for subsequent tests
DeviceTypes.IS_TABLET = false;
});
test('should re-render when the theme changes', () => {
const theme = Preferences.THEMES.denim;
const newTheme = Preferences.THEMES.sapphire;
const props = {
...baseProps,
theme,
};
const wrapper = loadShallow(props);
const instance = wrapper.instance();
instance.render = jest.fn();
expect(instance.render).toHaveBeenCalledTimes(0);
wrapper.setProps({theme: newTheme});
expect(instance.render).toHaveBeenCalledTimes(1);
});
});