Commit ee4c80e4 authored by Joram Wilander's avatar Joram Wilander Committed by JoramWilander
Browse files

Fix redirect after leaving a channel (#2081)

parent a00999dd
......@@ -78,6 +78,9 @@ export function leaveChannel(channelId) {
dispatch(unfavoriteChannel(channelId));
}
const teamUrl = getCurrentRelativeTeamUrl(state);
browserHistory.push(teamUrl + '/channels/' + Constants.DEFAULT_CHANNEL);
const {error} = await dispatch(leaveChannelRedux(channelId));
if (error) {
return {error};
......
......@@ -4,6 +4,8 @@
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import {leaveChannel} from 'mattermost-redux/actions/channels';
import {browserHistory} from 'utils/browser_history';
import * as Actions from 'actions/views/channel';
import {openDirectChannelToUserId} from 'actions/channel_actions.jsx';
......@@ -22,6 +24,12 @@ jest.mock('actions/channel_actions.jsx', () => ({
}),
}));
jest.mock('mattermost-redux/actions/channels', () => ({
leaveChannel: jest.fn(() => {
return {type: ''};
}),
}));
describe('channel view actions', () => {
const channel1 = {id: 'channelid1', name: 'channel1', display_name: 'Channel 1', type: 'O'};
const gmChannel = {id: 'gmchannelid', name: 'gmchannel', display_name: 'GM Channel 1', type: 'G'};
......@@ -74,4 +82,12 @@ describe('channel view actions', () => {
expect(browserHistory.push).toHaveBeenCalledWith(`/${team1.name}/channels/${gmChannel.name}`);
});
});
describe('leaveChannel', () => {
test('leave a channel successfully', async () => {
await store.dispatch(Actions.leaveChannel('channelid'));
expect(browserHistory.push).toHaveBeenCalledWith(`/${team1.name}/channels/town-square`);
expect(leaveChannel).toHaveBeenCalledWith('channelid');
});
});
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment