mattermost-mobile/app/screens/select_team/select_team.test.js
Miguel Alatzar 2d81b497cf [MM-23520] Port mattermost-redux (#4088)
* Remove mattermost-redux

* Move mm-redux files into app/redux

* Add @redux path to tsconfig.json

* Fix imports

* Install missing dependencies

* Fix tsc errors

* Fix i18n_utils test

* Fix more imports

* Remove redux websocket

* Fix tests

* Rename @redux

* Apply changes from mattermost-redux PR 1103

* Remove mattermost-redux mention in template

* Add missing imports

* Rename app/redux/ to app/mm-redux/

* Remove test file

* Fix fetching Sidebar GM profiles

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2020-04-17 21:12:09 -07:00

136 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 {shallow} from 'enzyme';
import Preferences from '@mm-redux/constants/preferences';
import {RequestStatus} from '@mm-redux/constants';
import SelectTeam from './select_team.js';
jest.mock('app/utils/theme', () => {
const original = require.requireActual('app/utils/theme');
return {
...original,
changeOpacity: jest.fn(),
};
});
const getTeams = async () => {
return {
error: {},
};
};
describe('SelectTeam', () => {
const actions = {
getTeams,
handleTeamChange: jest.fn(),
addUserToTeam: jest.fn(),
joinTeam: jest.fn(),
logout: jest.fn(),
};
const baseProps = {
actions,
currentChannelId: 'someId',
currentUserIsGuest: false,
currentUserId: 'fakeid',
currentUrl: 'test',
userWithoutTeams: false,
teams: [],
theme: Preferences.THEMES.default,
teamsRequest: {
status: RequestStatus.FAILURE,
},
componentId: 'component-id',
isLandscape: false,
serverVersion: '5.18',
};
test('should match snapshot for fail of teams', async () => {
const wrapper = shallow(
<SelectTeam {...baseProps}/>,
);
expect(wrapper.state('loading')).toEqual(true);
await getTeams();
expect(wrapper.state('loading')).toEqual(false);
wrapper.update();
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should match snapshot for teams', async () => {
const props = {
...baseProps,
teams: [{
id: 'kemjcpu9bi877yegqjs18ndp4r',
invite_id: 'ojsnudhqzbfzpk6e4n6ip1hwae',
name: 'test',
}],
teamsRequest: {
status: RequestStatus.SUCCESS,
},
};
const wrapper = shallow(
<SelectTeam {...props}/>,
);
expect(wrapper.state('page')).toEqual(0);
await getTeams();
expect(wrapper.state('page')).toEqual(1);
wrapper.update();
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should match snapshot when user is a guest', async () => {
const props = {
...baseProps,
currentUserIsGuest: true,
teams: [{
id: 'kemjcpu9bi877yegqjs18ndp4r',
invite_id: 'ojsnudhqzbfzpk6e4n6ip1hwae',
name: 'test',
}],
teamsRequest: {
status: RequestStatus.SUCCESS,
},
};
const wrapper = shallow(
<SelectTeam {...props}/>,
);
await getTeams();
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should call joinTeam versions prior to 5.18', async () => {
const props = {
...baseProps,
serverVersion: '5.17',
};
const wrapper = shallow(
<SelectTeam {...props}/>,
);
wrapper.instance().onSelectTeam({id: 'test_id', invite_id: 'test_invite_id'});
expect(props.actions.joinTeam).toBeCalledWith('test_invite_id', 'test_id');
expect(props.actions.addUserToTeam).not.toBeCalled();
});
test('should call joinTeam versions posterior to 5.18', async () => {
const props = {
...baseProps,
serverVersion: '5.18',
};
const wrapper = shallow(
<SelectTeam {...props}/>,
);
wrapper.instance().onSelectTeam({id: 'test_id', invite_id: 'test_invite_id'});
expect(props.actions.joinTeam).not.toBeCalled();
expect(props.actions.addUserToTeam).toBeCalledWith('test_id', 'fakeid');
});
});