From b46996a8417486ee61140af34be184bbc1460e90 Mon Sep 17 00:00:00 2001 From: ami9000 <20244930+ami9000@users.noreply.github.com> Date: Wed, 26 Feb 2020 15:40:53 -0800 Subject: [PATCH] MM-22375: Remove mark as unread post option in archived channels (#3922) * Remove mark as unread post option for archived channels and revise tests * revised tests --- app/screens/post_options/index.js | 6 +++- app/screens/post_options/index.test.js | 46 ++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/app/screens/post_options/index.js b/app/screens/post_options/index.js index 177ccd746..ae02d589b 100644 --- a/app/screens/post_options/index.js +++ b/app/screens/post_options/index.js @@ -45,8 +45,8 @@ export function makeMapStateToProps() { const reactions = getReactionsForPostSelector(state, post.id); const channelIsArchived = channel.delete_at !== 0; const {serverVersion} = state.entities.general; - const canMarkAsUnread = isMinimumServerVersion(serverVersion, 5, 18); + let canMarkAsUnread = true; let canAddReaction = true; let canReply = true; let canCopyPermalink = true; @@ -107,6 +107,10 @@ export function makeMapStateToProps() { canAddReaction = false; } + if (!isMinimumServerVersion(serverVersion, 5, 18) || channelIsArchived) { + canMarkAsUnread = false; + } + return { ...getDimensions(state), canAddReaction, diff --git a/app/screens/post_options/index.test.js b/app/screens/post_options/index.test.js index 13b312e39..d3e1772bd 100644 --- a/app/screens/post_options/index.test.js +++ b/app/screens/post_options/index.test.js @@ -9,6 +9,9 @@ import * as commonSelectors from 'mattermost-redux/selectors/entities/common'; import * as teamSelectors from 'mattermost-redux/selectors/entities/teams'; import * as deviceSelectors from 'app/selectors/device'; import * as preferencesSelectors from 'mattermost-redux/selectors/entities/preferences'; +import {isMinimumServerVersion} from 'mattermost-redux/utils/helpers'; + +jest.mock('mattermost-redux/utils/post_utils'); channelSelectors.getChannel = jest.fn(); channelSelectors.getCurrentChannelId = jest.fn(); @@ -69,13 +72,27 @@ describe('makeMapStateToProps', () => { expect(props.canFlag).toBe(true); }); - test('canMarkAsUnread is true when isMinimumServerVersion is 5.18v', () => { + test('canMarkAsUnread is true when isMinimumServerVersion is 5.18v and channel not archived', () => { + channelSelectors.getChannel = jest.fn().mockReturnValueOnce({ + delete_at: 0, + }); const mapStateToProps = makeMapStateToProps(); const props = mapStateToProps(baseState, baseOwnProps); + expect(isMinimumServerVersion(baseState.entities.general.serverVersion, 5, 18)).toBe(true); expect(props.canMarkAsUnread).toBe(true); }); - test('canMarkAsUnread is false when isMinimumServerVersion is not 5.18v', () => { + test('canMarkAsUnread is false when isMinimumServerVersion is 5.18v and channel is archived', () => { + channelSelectors.getChannel = jest.fn().mockReturnValueOnce({ + delete_at: 1, + }); + const mapStateToProps = makeMapStateToProps(); + const props = mapStateToProps(baseState, baseOwnProps); + expect(isMinimumServerVersion(baseState.entities.general.serverVersion, 5, 18)).toBe(true); + expect(props.canMarkAsUnread).toBe(false); + }); + + test('canMarkAsUnread is false when isMinimumServerVersion is not 5.18v and channel is not archived', () => { const state = { entities: { ...baseState.entities, @@ -85,8 +102,33 @@ describe('makeMapStateToProps', () => { }, }; + channelSelectors.getChannel = jest.fn().mockReturnValueOnce({ + delete_at: 0, + }); + const mapStateToProps = makeMapStateToProps(); const props = mapStateToProps(state, baseOwnProps); + expect(isMinimumServerVersion(state.entities.general.serverVersion, 5, 18)).toBe(false); + expect(props.canMarkAsUnread).toBe(false); + }); + + test('canMarkAsUnread is false when isMinimumServerVersion is not 5.18v and channel is archived', () => { + const state = { + entities: { + ...baseState.entities, + general: { + serverVersion: '5.17', + }, + }, + }; + + channelSelectors.getChannel = jest.fn().mockReturnValueOnce({ + delete_at: 1, + }); + + const mapStateToProps = makeMapStateToProps(); + const props = mapStateToProps(state, baseOwnProps); + expect(isMinimumServerVersion(state.entities.general.serverVersion, 5, 18)).toBe(false); expect(props.canMarkAsUnread).toBe(false); }); });