Skip to content

Commit

Permalink
MM-20149 Fix marking channels as read (#3550)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattermost-build authored and enahum committed Nov 13, 2019
1 parent ac7921c commit e63179c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/actions/views/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};
}

Expand Down
14 changes: 11 additions & 3 deletions app/actions/views/channel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'}),
};
});

Expand Down Expand Up @@ -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,
Expand All @@ -268,5 +274,7 @@ describe('Actions.Views.Channel', () => {

};
expect(selectChannelWithMember).toStrictEqual(expectedSelectChannelWithMember);
expect(viewedAction).not.toBe(null);
expect(readAction).not.toBe(null);
});
});

0 comments on commit e63179c

Please sign in to comment.