mattermost-mobile/app/screens/user_profile/user_profile.test.js
Anurag Shivarathri 6e23fbe7a7
MM-32921 shared channels (#5241)
* Unable to open previews from search, pinned and mentions

* Updated Compass Icons

* Added Icon to LHS and Channel Info

* Added Icons to Manage/View Members list

* Added Icon to shared users in posts

* Added icon to channel header, fixed header style

* Added Icons in autocomplete

* WIP: Add shared shannels to browse

* Adding Shared Channels string to i18n

* Added remote organization to remote user profile

* Updated snapshot for channel header

* Added browsing shared channels

* Removed the exmpty line

* Added snapshot when user is remote

* Reverted compass icons and added icons only needed for shared channels

* Fixed i18n swapped

* Copied compass-icons from webapp

* Fixed showing shared channels as deleted after browsing them

* Added new compass ttf to android & fixed icon style for browse channel listing

* Fixed search for shared channels

* user profile snapshot updated with testId

* User list row snapshot updated with testID

* Moved shared user check to util function

* Fixed required props warning for ChannelIcon component

* Update app/screens/user_profile/index.js

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

* Removed Request related redux

* Reverted client4

* Added rest calls

* Updated snapshot

* Reverted files

* Adding back shared channels stuff to channel icon & showing shared channels only when enabled in browse channels

* Fixed misc issues

* moved empty array outside the function to avoid re-render

* Removed renaming fields

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-05-24 16:07:47 +05:30

183 lines
5.2 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {shallow} from 'enzyme';
import Preferences from '@mm-redux/constants/preferences';
import * as NavigationActions from 'app/actions/navigation';
import UserProfile from './user_profile.js';
import {BotTag, GuestTag} from 'app/components/tag';
jest.mock('react-intl');
jest.mock('@utils/theme', () => {
const original = jest.requireActual('../../utils/theme');
return {
...original,
changeOpacity: jest.fn(),
};
});
describe('user_profile', () => {
const actions = {
setChannelDisplayName: jest.fn(),
makeDirectChannel: jest.fn(),
loadBot: jest.fn(),
getRemoteClusterInfo: jest.fn(),
};
const baseProps = {
actions,
config: {
ShowEmailAddress: true,
},
teammateNameDisplay: 'username',
teams: [],
theme: Preferences.THEMES.default,
enableTimezone: false,
militaryTime: false,
isMyUser: false,
componentId: 'component-id',
};
const user = {
email: 'test@test.com',
first_name: 'test',
id: '4hzdnk6mg7gepe7yze6m3domnc',
last_name: 'fake',
nickname: 'nick',
username: 'fred',
is_bot: false,
};
test('should match snapshot', () => {
const wrapper = shallow(
<UserProfile
{...baseProps}
user={user}
/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should contain bot tag', () => {
const botUser = {
email: 'test@test.com',
first_name: 'test',
id: '4hzdnk6mg7gepe7yze6m3domnc',
last_name: 'fake',
nickname: 'nick',
username: 'fred',
is_bot: true,
};
const wrapper = shallow(
<UserProfile
{...baseProps}
user={botUser}
/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
expect(wrapper.containsMatchingElement(
<BotTag
show={true}
theme={baseProps.theme}
/>,
)).toEqual(true);
});
test('should contain guest tag', () => {
const guestUser = {
email: 'test@test.com',
first_name: 'test',
id: '4hzdnk6mg7gepe7yze6m3domnc',
last_name: 'fake',
nickname: 'nick',
username: 'fred',
roles: 'system_guest',
};
const wrapper = shallow(
<UserProfile
{...baseProps}
user={guestUser}
/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
expect(wrapper.containsMatchingElement(
<GuestTag
show={true}
theme={baseProps.theme}
/>,
)).toEqual(true);
});
test('should push EditProfile', () => {
jest.spyOn(global, 'requestAnimationFrame').mockImplementation((cb) => cb());
const goToScreen = jest.spyOn(NavigationActions, 'goToScreen');
const wrapper = shallow(
<UserProfile
{...baseProps}
user={user}
/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
wrapper.instance().goToEditProfile();
expect(goToScreen).toHaveBeenCalledTimes(1);
});
test('should match snapshot when user is from remote', () => {
const remoteUser = {
...user,
remote_id: 'sr23g5h456',
};
const clusterInfo = {
display_name: 'Remote Organization',
};
const wrapper = shallow(
<UserProfile
{...baseProps}
remoteClusterInfo={clusterInfo}
user={remoteUser}
/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should call goToEditProfile', () => {
const goToScreen = jest.spyOn(NavigationActions, 'goToScreen');
const wrapper = shallow(
<UserProfile
{...baseProps}
user={user}
/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
const event = {buttonId: wrapper.instance().rightButton.id};
wrapper.instance().navigationButtonPressed(event);
expect(goToScreen).toHaveBeenCalledTimes(1);
});
test('should call close', () => {
const dismissModal = jest.spyOn(NavigationActions, 'dismissModal');
const wrapper = shallow(
<UserProfile
{...baseProps}
user={user}
/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
const close = jest.spyOn(wrapper.instance(), 'close');
const event = {buttonId: 'close-settings'};
wrapper.instance().navigationButtonPressed(event);
expect(close).toHaveBeenCalledTimes(1);
expect(dismissModal).toHaveBeenCalledTimes(1);
});
});