mattermost-redux
Version:
Common code (API client, Redux stores, logic, utility functions) for building a Mattermost client
107 lines (96 loc) • 3.13 kB
JavaScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {TeamTypes, ThreadTypes} from 'action_types';
import deepFreeze from 'utils/deep_freeze';
import threadsReducer from './threads';
describe('threads', () => {
test('RECEIVED_THREADS should update the state', () => {
const state = deepFreeze({
threadsInTeam: {},
threads: {},
counts: {},
});
const nextState = threadsReducer(state, {
type: ThreadTypes.RECEIVED_THREADS,
data: {
team_id: 'a',
threads: [
{id: 't1'},
],
total: 3,
unread_mentions_per_channel: {},
total_unread_threads: 0,
total_unread_mentions: 1,
},
});
expect(nextState).not.toBe(state);
expect(nextState.threads.t1).toEqual({
id: 't1',
});
expect(nextState.counts.a).toEqual({
total: 3,
total_unread_threads: 0,
unread_mentions_per_channel: {},
total_unread_mentions: 1,
});
expect(nextState.threadsInTeam.a).toContain('t1');
});
test('RECEIVED_PER_CHANNEL_MENTION_COUNTS should update the state', () => {
const state = deepFreeze({
threadsInTeam: {},
threads: {},
counts: {
a: {
total: 3,
total_unread_threads: 0,
total_unread_mentions: 2,
},
},
});
const nextState = threadsReducer(state, {
type: ThreadTypes.RECEIVED_PER_CHANNEL_MENTION_COUNTS,
data: {
team_id: 'a',
counts: {a: 2},
},
});
expect(nextState).not.toBe(state);
expect(nextState.counts.a).toEqual({
total: 3,
total_unread_threads: 0,
unread_mentions_per_channel: {a: 2},
total_unread_mentions: 2,
});
});
test('LEAVE_TEAM should clean the state', () => {
const state = deepFreeze({
threadsInTeam: {},
threads: {},
counts: {},
});
let nextState = threadsReducer(state, {
type: ThreadTypes.RECEIVED_THREADS,
data: {
team_id: 'a',
threads: [
{id: 't1'},
],
total: 3,
unread_mentions_per_channel: {},
total_unread_threads: 0,
total_unread_mentions: 1,
},
});
expect(nextState).not.toBe(state);
// leave team
nextState = threadsReducer(state, {
type: TeamTypes.LEAVE_TEAM,
data: {
id: 'a',
},
});
expect(nextState.threads.t1).toBe(undefined);
expect(nextState.counts.a).toBe(undefined);
expect(nextState.threadsInTeam.a).toBe(undefined);
});
});