Ensure currentChannel set (#4289)

This commit is contained in:
Mattermost Build 2020-05-11 17:19:36 +02:00 committed by GitHub
parent 613ddc1250
commit a01bdd6fc4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View file

@ -53,7 +53,7 @@ export function mapStateToProps(state, ownProps) {
let canPost = true;
let useChannelMentions = true;
if (isMinimumServerVersion(state.entities.general.serverVersion, 5, 22)) {
if (currentChannel && isMinimumServerVersion(state.entities.general.serverVersion, 5, 22)) {
canPost = haveIChannelPermission(
state,
{

View file

@ -101,4 +101,25 @@ describe('mapStateToProps', () => {
default: true,
});
});
test('haveIChannelPermission is not called when isMinimumServerVersion is 5.22v but currentChannel is null', () => {
channelSelectors.getCurrentChannel = jest.fn().mockReturnValue(null);
const state = {...baseState};
state.entities.general.serverVersion = '5.22';
mapStateToProps(state, baseOwnProps);
expect(isMinimumServerVersion(state.entities.general.serverVersion, 5, 22)).toBe(true);
expect(roleSelectors.haveIChannelPermission).not.toHaveBeenCalledWith(state, {
channel: undefined,
team: undefined,
permission: Permissions.CREATE_POST,
});
expect(roleSelectors.haveIChannelPermission).not.toHaveBeenCalledWith(state, {
channel: undefined,
permission: Permissions.USE_CHANNEL_MENTIONS,
});
});
});