diff --git a/app/components/post_draft/index.js b/app/components/post_draft/index.js index a32f9a5f3..12ec408f9 100644 --- a/app/components/post_draft/index.js +++ b/app/components/post_draft/index.js @@ -48,7 +48,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_draft/index.test.js b/app/components/post_draft/index.test.js index c6e6c9173..5e02f2446 100644 --- a/app/components/post_draft/index.test.js +++ b/app/components/post_draft/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