* 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>
139 lines
3.5 KiB
JavaScript
139 lines
3.5 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 {IntlProvider} from 'react-intl';
|
|
|
|
import Preferences from '@mm-redux/constants/preferences';
|
|
|
|
import SelectorScreen from './selector_screen.js';
|
|
|
|
jest.mock('rn-fetch-blob', () => ({
|
|
fs: {
|
|
dirs: {
|
|
DocumentDir: () => jest.fn(),
|
|
CacheDir: () => jest.fn(),
|
|
},
|
|
},
|
|
}));
|
|
|
|
jest.mock('rn-fetch-blob/fs', () => ({
|
|
dirs: {
|
|
DocumentDir: () => jest.fn(),
|
|
CacheDir: () => jest.fn(),
|
|
},
|
|
}));
|
|
|
|
const user1 = {id: 'id', username: 'username'};
|
|
const user2 = {id: 'id2', username: 'username2'};
|
|
|
|
const getProfiles = async () => {
|
|
return {
|
|
data: [user1, user2],
|
|
error: {},
|
|
};
|
|
};
|
|
|
|
const searchProfiles = async () => {
|
|
return {
|
|
data: [user2],
|
|
error: {},
|
|
};
|
|
};
|
|
|
|
const channel1 = {id: 'id', name: 'name', display_name: 'display_name'};
|
|
const channel2 = {id: 'id2', name: 'name2', display_name: 'display_name2'};
|
|
|
|
const getChannels = async () => {
|
|
return {
|
|
data: [channel1, channel2],
|
|
error: {},
|
|
};
|
|
};
|
|
|
|
const searchChannels = async () => {
|
|
return {
|
|
data: [channel2],
|
|
error: {},
|
|
};
|
|
};
|
|
|
|
const intlProvider = new IntlProvider({locale: 'en'}, {});
|
|
const {intl} = intlProvider.getChildContext();
|
|
|
|
describe('SelectorScreen', () => {
|
|
const actions = {
|
|
getProfiles,
|
|
getChannels,
|
|
searchProfiles,
|
|
searchChannels,
|
|
};
|
|
|
|
const baseProps = {
|
|
actions,
|
|
currentTeamId: 'someId',
|
|
onSelect: jest.fn(),
|
|
data: [{text: 'text', value: 'value'}],
|
|
dataSource: null,
|
|
theme: Preferences.THEMES.default,
|
|
isLandscape: false,
|
|
};
|
|
|
|
test('should match snapshot for explicit options', async () => {
|
|
const wrapper = shallow(
|
|
<SelectorScreen {...baseProps}/>,
|
|
{context: {intl}},
|
|
);
|
|
expect(wrapper.getElement()).toMatchSnapshot();
|
|
});
|
|
|
|
test('should match snapshot for users', async () => {
|
|
const props = {
|
|
...baseProps,
|
|
dataSource: 'users',
|
|
data: [user1, user2],
|
|
};
|
|
|
|
const wrapper = shallow(
|
|
<SelectorScreen {...props}/>,
|
|
{context: {intl}},
|
|
);
|
|
expect(wrapper.getElement()).toMatchSnapshot();
|
|
wrapper.setState({isLoading: false});
|
|
wrapper.update();
|
|
expect(wrapper.getElement()).toMatchSnapshot();
|
|
});
|
|
|
|
test('should match snapshot for channels', async () => {
|
|
const props = {
|
|
...baseProps,
|
|
dataSource: 'channels',
|
|
data: [channel1, channel2],
|
|
};
|
|
|
|
const wrapper = shallow(
|
|
<SelectorScreen {...props}/>,
|
|
{context: {intl}},
|
|
);
|
|
expect(wrapper.getElement()).toMatchSnapshot();
|
|
wrapper.setState({isLoading: false});
|
|
wrapper.update();
|
|
expect(wrapper.getElement()).toMatchSnapshot();
|
|
});
|
|
|
|
test('should match snapshot for searching', async () => {
|
|
const props = {
|
|
...baseProps,
|
|
dataSource: 'channels',
|
|
data: [channel1, channel2],
|
|
};
|
|
|
|
const wrapper = shallow(
|
|
<SelectorScreen {...props}/>,
|
|
{context: {intl}},
|
|
);
|
|
wrapper.setState({isLoading: false, searching: true, term: 'name2'});
|
|
wrapper.update();
|
|
expect(wrapper.getElement()).toMatchSnapshot();
|
|
});
|
|
});
|