mattermost-mobile/app/screens/channel/channel_base.test.js
Elias Nahum 30d4aa2a3e
Build Improvements (#4884)
* Use AppGroupId from Info.plists instead of hardcoded constant

* Update script, ci & Makefile

* Update Cocoapods to 1.9.3

* Split android builds using ABI filters

* Update Fastlane deps & build scripts

* Update CI to use latests scripts

* Display app version & build number in select server screen

* Make generate scripts compatible with node < 12

* Build scripts

* add build script to package.json

* Update to use bundler 2.1.4 and CI with Xcode 12

* Fix script name for build:ios-unsigned

* Fix RN iOS scripts

* Update CI pods-dependencies step

* Add pipefail to android executor

* Update Fastlane

* Fix type in postinstall script

* update android executor and set TERM

* Fix S3 bucket name variable

* Apply suggestions from code review

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>

* Fix master unit tests

* use requireActual in jest setup

* Jest setup to use react instead of React

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>
2020-10-15 22:09:36 -03:00

109 lines
3.8 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {Alert} from 'react-native';
import {shallow} from 'enzyme';
import EventEmitter from '@mm-redux/utils/event_emitter';
import {General} from '@mm-redux/constants';
import Preferences from '@mm-redux/constants/preferences';
import EphemeralStore from 'app/store/ephemeral_store';
import * as NavigationActions from 'app/actions/navigation';
import {emptyFunction} from '@utils/general';
import ChannelBase from './channel_base';
jest.mock('react-intl');
describe('ChannelBase', () => {
const channelBaseComponentId = 'component-0';
const componentIds = ['component-1', 'component-2', 'component-3'];
const baseProps = {
actions: {
getChannelStats: jest.fn(),
loadChannelsForTeam: jest.fn(),
markChannelViewedAndRead: jest.fn(),
recordLoadTime: jest.fn(),
selectDefaultTeam: jest.fn(),
selectInitialChannel: jest.fn(),
},
componentId: channelBaseComponentId,
theme: Preferences.THEMES.default,
};
const optionsForTheme = (theme) => {
return {
topBar: {
backButton: {
color: theme.sidebarHeaderTextColor,
},
background: {
color: theme.sidebarHeaderBg,
},
title: {
color: theme.sidebarHeaderTextColor,
},
leftButtonColor: theme.sidebarHeaderTextColor,
rightButtonColor: theme.sidebarHeaderTextColor,
},
layout: {
componentBackgroundColor: theme.centerChannelBg,
},
};
};
test('should call mergeNavigationOptions on all navigation components when theme changes', () => {
const mergeNavigationOptions = jest.spyOn(NavigationActions, 'mergeNavigationOptions');
EphemeralStore.addNavigationComponentId(channelBaseComponentId);
componentIds.forEach((componentId) => {
EphemeralStore.addNavigationComponentId(componentId);
});
const wrapper = shallow(
<ChannelBase {...baseProps}/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
expect(mergeNavigationOptions.mock.calls).toEqual([]);
mergeNavigationOptions.mockClear();
wrapper.setProps({theme: Preferences.THEMES.mattermostDark});
const newThemeOptions = optionsForTheme(Preferences.THEMES.mattermostDark);
expect(mergeNavigationOptions.mock.calls).toEqual([
[baseProps.componentId, newThemeOptions],
[componentIds[2], newThemeOptions],
[componentIds[1], newThemeOptions],
[componentIds[0], newThemeOptions],
]);
});
test('registerTypingAnimation should return a callback that removes the typing animation', () => {
const wrapper = shallow(
<ChannelBase {...baseProps}/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
const instance = wrapper.instance();
expect(instance.typingAnimations).toStrictEqual([]);
const removeAnimation = instance.registerTypingAnimation(emptyFunction);
expect(instance.typingAnimations).toStrictEqual([emptyFunction]);
removeAnimation();
expect(instance.typingAnimations).toStrictEqual([]);
});
test('should display an alert when the user is removed from the current channel', () => {
const alert = jest.spyOn(Alert, 'alert');
shallow(
<ChannelBase {...baseProps}/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
EventEmitter.emit(General.REMOVED_FROM_CHANNEL);
expect(alert).toHaveBeenCalled();
});
});