From a01bdd6fc4fd8f391c52b63ad379f71e8f27fae7 Mon Sep 17 00:00:00 2001 From: Mattermost Build Date: Mon, 11 May 2020 17:19:36 +0200 Subject: [PATCH] Ensure currentChannel set (#4289) --- app/components/post_textbox/index.js | 2 +- app/components/post_textbox/index.test.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/components/post_textbox/index.js b/app/components/post_textbox/index.js index 7a9e8b24e..75f6068bc 100644 --- a/app/components/post_textbox/index.js +++ b/app/components/post_textbox/index.js @@ -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, { diff --git a/app/components/post_textbox/index.test.js b/app/components/post_textbox/index.test.js index ae6b0f0d8..3e9a6f453 100644 --- a/app/components/post_textbox/index.test.js +++ b/app/components/post_textbox/index.test.js @@ -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, + }); + }); }); \ No newline at end of file