mattermost-mobile/app/screens/channel/channel_base.test.js
Elias Nahum 9f238d5ef4
Post List & post components refactored (#5409)
* Update transform to make Android's post list scroll smooth

* set start since metric when appStarted is false

* Refactor Formatted components

* Downgrade RNN to 7.13.0 & patch XCDYouTube to allow video playback

* Refactor Post list and all related components

* review suggestion rename hour12 to isMilitaryTime

* feedback review use aliases

* feedback review deconstruct actions in markdown_link

* feedback review simplify if/else statement in combined_used_activity

* Simplify if statement for consecutive posts

* Specify npm version to build iOS on CI

* Refactor network_indicator

* render Icon in file gallery with transparent background

* Increase timeout to scroll to bottom when posting a new message

* fix: scroll when tapping on the new messages bar

* fix: dismiss all modals

* fix navigation tests

* Handle dismissAllModals for iOS to prevent blank screens

* Prevent modal from dismissing when showing the thread screen in the stack

* Update app/components/image_viewport.tsx

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

* Update app/utils/post.ts

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

* Apply suggestions from code review

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

* fix: rename selector and prop

* Fix XCDYouTube patch

* Fix posting from a thread in the right channel

* do not render reply bar on the thread screen

* close previous permalink before showing a new one

* move XCDYouTube patch to ios/patches folder

* closePermalink directly instead of using an onClose prop

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>
Co-authored-by: Miguel Alatzar <this.migbot@gmail.com>
2021-06-03 11:12:15 -07:00

110 lines
3.9 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 * as NavigationActions from '@actions/navigation';
import {General, Preferences} from '@mm-redux/constants';
import EventEmitter from '@mm-redux/utils/event_emitter';
import EphemeralStore from '@store/ephemeral_store';
import {emptyFunction} from '@utils/general';
import {shallowWithIntl} from 'test/intl-test-helper';
import ChannelBase from './channel_base';
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(),
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 = shallowWithIntl(
<ChannelBase {...baseProps}/>,
);
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 = shallowWithIntl(
<ChannelBase {...baseProps}/>,
);
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');
shallowWithIntl(
<ChannelBase {...baseProps}/>,
);
EventEmitter.emit(General.REMOVED_FROM_CHANNEL);
expect(alert).toHaveBeenCalled();
});
test('should call selectDefault team when the current team is archived', () => {
const wrapper = shallowWithIntl(
<ChannelBase {...baseProps}/>,
);
wrapper.setProps({currentTeamId: '', currentChannelId: ''});
expect(baseProps.actions.selectDefaultTeam).toHaveBeenCalledTimes(1);
});
});