mattermost-mobile/app/screens/select_team/select_team.test.js
Miguel Alatzar c72ea6a281
[MM 13161] Mobile: Add paging to Select Teams screen (#2468)
* Use updated getJoinableTeams function from mattermost-redux

* Use onEndReached for infinite scrolling of paginated teams

* Add onRefresh

* Update Settings screen to expect joinableTeams as array

* Fix linter issues

* Test that page is updated after getTeams() call

* Revert package-lock.json changes

* Update mattermost-redux dependency

* Update mattermost-redux dependency

* Only call getTeams if more can be loaded and only after a previous
call has completed

* Update snapshot due to  prop

* Update CustomList to support refreshing as well as option to not
render the separator

* Use CustomList in SelectTeam
2019-02-20 09:12:36 -08:00

82 lines
2.1 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 'mattermost-redux/constants/preferences';
import {RequestStatus} from 'mattermost-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(),
joinTeam: jest.fn(),
logout: jest.fn(),
};
const baseProps = {
actions,
currentChannelId: 'someId',
currentUrl: 'test',
navigator: {
setOnNavigatorEvent: jest.fn(),
},
userWithoutTeams: false,
teams: [],
theme: Preferences.THEMES.default,
teamsRequest: {
status: RequestStatus.FAILURE,
},
};
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();
});
});