From dc830c56be555dcf5b841d4d0f41ea6a983a4a33 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Wed, 13 Nov 2019 13:38:20 -0500 Subject: [PATCH] MM-20149 Fix marking channels as read (#3549) * MM-20149 Fix marking channels as read * empty commit --- app/actions/views/channel.js | 2 +- app/actions/views/channel.test.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/actions/views/channel.js b/app/actions/views/channel.js index de59441e3..4d89dcd77 100644 --- a/app/actions/views/channel.js +++ b/app/actions/views/channel.js @@ -392,10 +392,10 @@ export function handleSelectChannel(channelId, fromPushNotification = false) { setChannelLoading(false), setLastChannelForTeam(currentTeamId, channelId), selectChannelWithMember(channelId, channel, member), - markChannelViewedAndRead(channelId, previousChannelId), ]; dispatch(batchActions(actions)); + dispatch(markChannelViewedAndRead(channelId, previousChannelId)); }; } diff --git a/app/actions/views/channel.test.js b/app/actions/views/channel.test.js index 350e02b40..de26b10c7 100644 --- a/app/actions/views/channel.test.js +++ b/app/actions/views/channel.test.js @@ -17,12 +17,15 @@ const { import postReducer from 'mattermost-redux/reducers/entities/posts'; +const MOCK_CHANNEL_MARK_AS_READ = 'MOCK_CHANNEL_MARK_AS_READ'; +const MOCK_CHANNEL_MARK_AS_VIEWED = 'MOCK_CHANNEL_MARK_AS_VIEWED'; + jest.mock('mattermost-redux/actions/channels', () => { const channelActions = require.requireActual('mattermost-redux/actions/channels'); return { ...channelActions, - markChannelAsRead: jest.fn().mockReturnValue({type: ''}), - markChannelAsViewed: jest.fn().mockReturnValue({type: ''}), + markChannelAsRead: jest.fn().mockReturnValue({type: 'MOCK_CHANNEL_MARK_AS_READ'}), + markChannelAsViewed: jest.fn().mockReturnValue({type: 'MOCK_CHANNEL_MARK_AS_VIEWED'}), }; }); @@ -251,8 +254,11 @@ describe('Actions.Views.Channel', () => { store = mockStore({...storeObj}); await store.dispatch(handleSelectChannel(channelId, fromPushNotification)); - const storeBatchActions = store.getActions().find(({type}) => type === 'BATCHING_REDUCER.BATCH'); + const storeActions = store.getActions(); + const storeBatchActions = storeActions.find(({type}) => type === 'BATCHING_REDUCER.BATCH'); const selectChannelWithMember = storeBatchActions.payload.find(({type}) => type === ViewTypes.SELECT_CHANNEL_WITH_MEMBER); + const viewedAction = storeActions.find(({type}) => type === MOCK_CHANNEL_MARK_AS_VIEWED); + const readAction = storeActions.find(({type}) => type === MOCK_CHANNEL_MARK_AS_READ); const expectedSelectChannelWithMember = { type: ViewTypes.SELECT_CHANNEL_WITH_MEMBER, @@ -268,5 +274,7 @@ describe('Actions.Views.Channel', () => { }; expect(selectChannelWithMember).toStrictEqual(expectedSelectChannelWithMember); + expect(viewedAction).not.toBe(null); + expect(readAction).not.toBe(null); }); });