mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-59276 Don't update channel stats state unnecessarily (#27805)
This commit is contained in:
parent
bb78de5b7f
commit
3f4b8e8137
@ -114,6 +114,94 @@ describe('channels', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('RECEIVED_CHANNEL_STATS', () => {
|
||||
test("should store a channel's stats", () => {
|
||||
const state = deepFreeze(channelsReducer({}, {}));
|
||||
const nextState = channelsReducer(state, {
|
||||
type: ChannelTypes.RECEIVED_CHANNEL_STATS,
|
||||
data: {
|
||||
channel_id: 'channel1',
|
||||
member_count: 2,
|
||||
guest_count: 3,
|
||||
pinnedpost_count: 4,
|
||||
files_count: 5,
|
||||
},
|
||||
});
|
||||
|
||||
expect(state).not.toBe(nextState);
|
||||
expect(nextState.stats).toEqual({
|
||||
channel1: {
|
||||
channel_id: 'channel1',
|
||||
member_count: 2,
|
||||
guest_count: 3,
|
||||
pinnedpost_count: 4,
|
||||
files_count: 5,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("should update a channel's stats", () => {
|
||||
const state = deepFreeze(channelsReducer({
|
||||
stats: {
|
||||
channel1: {
|
||||
channel_id: 'channel1',
|
||||
member_count: 1,
|
||||
guest_count: 1,
|
||||
pinnedpost_count: 1,
|
||||
files_count: 1,
|
||||
},
|
||||
},
|
||||
}, {}));
|
||||
const nextState = channelsReducer(state, {
|
||||
type: ChannelTypes.RECEIVED_CHANNEL_STATS,
|
||||
data: {
|
||||
channel_id: 'channel1',
|
||||
member_count: 2,
|
||||
guest_count: 3,
|
||||
pinnedpost_count: 4,
|
||||
files_count: 5,
|
||||
},
|
||||
});
|
||||
|
||||
expect(state).not.toBe(nextState);
|
||||
expect(nextState.stats).toEqual({
|
||||
channel1: {
|
||||
channel_id: 'channel1',
|
||||
member_count: 2,
|
||||
guest_count: 3,
|
||||
pinnedpost_count: 4,
|
||||
files_count: 5,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("should return the same object when a channel's stats are unchanged", () => {
|
||||
const state = deepFreeze(channelsReducer({
|
||||
stats: {
|
||||
channel1: {
|
||||
channel_id: 'channel1',
|
||||
member_count: 2,
|
||||
guest_count: 3,
|
||||
pinnedpost_count: 4,
|
||||
files_count: 5,
|
||||
},
|
||||
},
|
||||
}, {}));
|
||||
const nextState = channelsReducer(state, {
|
||||
type: ChannelTypes.RECEIVED_CHANNEL_STATS,
|
||||
data: {
|
||||
channel_id: 'channel1',
|
||||
member_count: 2,
|
||||
guest_count: 3,
|
||||
pinnedpost_count: 4,
|
||||
files_count: 5,
|
||||
},
|
||||
});
|
||||
|
||||
expect(state).toBe(nextState);
|
||||
});
|
||||
});
|
||||
|
||||
describe('INCREMENT_FILE_COUNT', () => {
|
||||
test('should change channel file count stats', () => {
|
||||
const state = deepFreeze(channelsReducer({
|
||||
|
@ -583,11 +583,16 @@ function membersInChannel(state: RelationOneToOne<Channel, Record<string, Channe
|
||||
function stats(state: RelationOneToOne<Channel, ChannelStats> = {}, action: AnyAction) {
|
||||
switch (action.type) {
|
||||
case ChannelTypes.RECEIVED_CHANNEL_STATS: {
|
||||
const nextState = {...state};
|
||||
const stat = action.data;
|
||||
nextState[stat.channel_id] = stat;
|
||||
const stat: ChannelStats = action.data;
|
||||
|
||||
return nextState;
|
||||
if (isEqual(state[stat.channel_id], stat)) {
|
||||
return state;
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
[stat.channel_id]: stat,
|
||||
};
|
||||
}
|
||||
case ChannelTypes.ADD_CHANNEL_MEMBER_SUCCESS: {
|
||||
const nextState = {...state};
|
||||
|
Loading…
Reference in New Issue
Block a user