From 96752fe2c617233e745e19a0118d846e0825d572 Mon Sep 17 00:00:00 2001 From: Sudheer Date: Fri, 26 Oct 2018 20:42:50 +0530 Subject: [PATCH] MM-12810 Webapp redirecting to select_team page when base url is hit (#1945) * MM-12810 Webapp redirecting to select_team page when base url is hit * Remove user store dependency --- components/root/root.jsx | 5 +---- tests/components/root/root.test.jsx | 8 +++++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/components/root/root.jsx b/components/root/root.jsx index 3c0f88e8fca3..b7d659d71f51 100644 --- a/components/root/root.jsx +++ b/components/root/root.jsx @@ -18,7 +18,6 @@ import {trackLoadTime} from 'actions/diagnostics_actions.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; import BrowserStore from 'stores/browser_store.jsx'; import ErrorStore from 'stores/error_store.jsx'; -import UserStore from 'stores/user_store.jsx'; import {loadRecentlyUsedCustomEmojis} from 'actions/emoji_actions.jsx'; import * as I18n from 'i18n/i18n.jsx'; import {initializePlugins} from 'plugins'; @@ -189,7 +188,6 @@ export default class Root extends React.Component { const afterIntl = () => { initializePlugins(); - this.redirectIfNecessary(this.props); this.setState({configLoaded: true}); }; if (global.Intl) { @@ -221,8 +219,6 @@ export default class Root extends React.Component { this.props.history.push('/signup_user_complete'); } else if (props.showTermsOfService) { this.props.history.push('/terms_of_service'); - } else if (UserStore.getCurrentUser()) { - GlobalActions.redirectUserToDefaultTeam(); } } } @@ -233,6 +229,7 @@ export default class Root extends React.Component { componentDidMount() { this.props.actions.loadMeAndConfig().then(() => { + GlobalActions.redirectUserToDefaultTeam(); this.onConfigLoaded(); }); diff --git a/tests/components/root/root.test.jsx b/tests/components/root/root.test.jsx index 30e66d30bfca..19085df76212 100644 --- a/tests/components/root/root.test.jsx +++ b/tests/components/root/root.test.jsx @@ -5,6 +5,7 @@ import React from 'react'; import {shallow} from 'enzyme'; import Root from 'components/root/root'; +import * as GlobalActions from 'actions/global_actions.jsx'; jest.mock('fastclick', () => ({ attach: () => {}, // eslint-disable-line no-empty-function @@ -14,6 +15,10 @@ jest.mock('actions/diagnostics_actions', () => ({ trackLoadTime: () => {}, // eslint-disable-line no-empty-function })); +jest.mock('actions/global_actions', () => ({ + redirectUserToDefaultTeam: jest.fn(), +})); + describe('components/Root', () => { const baseProps = { diagnosticsEnabled: true, @@ -25,7 +30,7 @@ describe('components/Root', () => { }, }; - test('should load user, config, and license on mount', (done) => { + test('should load user, config, and license on mount and redirect to defaultTeam on success', (done) => { const props = { ...baseProps, actions: { @@ -38,6 +43,7 @@ describe('components/Root', () => { class MockedRoot extends Root { onConfigLoaded = jest.fn(() => { expect(this.onConfigLoaded).toHaveBeenCalledTimes(1); + expect(GlobalActions.redirectUserToDefaultTeam).toHaveBeenCalledTimes(1); done(); }); }