Skip to content

Commit

Permalink
unreads tests [nfc]: Enable flow.
Browse files Browse the repository at this point in the history
  • Loading branch information
WesleyAC committed May 21, 2021
1 parent faaaac2 commit fd93443
Showing 1 changed file with 32 additions and 40 deletions.
72 changes: 32 additions & 40 deletions src/unread/__tests__/unreadMentionsReducer-test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/* @flow strict-local */
import deepFreeze from 'deep-freeze';
import Immutable from 'immutable';

import unreadMentionsReducer from '../unreadMentionsReducer';
import {
REALM_INIT,
ACCOUNT_SWITCH,
EVENT_NEW_MESSAGE,
EVENT_UPDATE_MESSAGE_FLAGS,
} from '../../actionConstants';
import { ACCOUNT_SWITCH, EVENT_UPDATE_MESSAGE_FLAGS } from '../../actionConstants';
import { NULL_ARRAY } from '../../nullObjects';
import * as eg from '../../__tests__/lib/exampleData';
import { mkMessageAction } from './unread-testlib';

describe('unreadMentionsReducer', () => {
describe('ACCOUNT_SWITCH', () => {
Expand All @@ -16,6 +15,7 @@ describe('unreadMentionsReducer', () => {

const action = deepFreeze({
type: ACCOUNT_SWITCH,
index: 0,
});

const expectedState = [];
Expand All @@ -30,17 +30,19 @@ describe('unreadMentionsReducer', () => {
test('received data from "unread_msgs.mentioned" key replaces the current state ', () => {
const initialState = deepFreeze([]);

const action = deepFreeze({
type: REALM_INIT,
const action = {
...eg.action.realm_init,
data: {
...eg.action.realm_init.data,
unread_msgs: {
streams: [{}, {}],
huddles: [{}, {}, {}],
pms: [{}, {}, {}],
...eg.action.realm_init.data.unread_msgs,
streams: [],
huddles: [],
pms: [],
mentions: [1, 2, 3],
},
},
});
};

const expectedState = [1, 2, 3];

Expand All @@ -54,13 +56,7 @@ describe('unreadMentionsReducer', () => {
test('if message does not contain "mentioned" flag, do not mutate state', () => {
const initialState = deepFreeze([]);

const action = deepFreeze({
type: EVENT_NEW_MESSAGE,
message: {
id: 2,
flags: [],
},
});
const action = mkMessageAction(eg.streamMessage({ flags: [] }));

const actualState = unreadMentionsReducer(initialState, action);

Expand All @@ -70,13 +66,7 @@ describe('unreadMentionsReducer', () => {
test('if message has "read" flag, do not mutate state', () => {
const initialState = deepFreeze([]);

const action = deepFreeze({
type: EVENT_NEW_MESSAGE,
message: {
id: 2,
flags: ['mentioned', 'read'],
},
});
const action = mkMessageAction(eg.streamMessage({ flags: ['mentioned', 'read'] }));

const actualState = unreadMentionsReducer(initialState, action);

Expand All @@ -86,13 +76,7 @@ describe('unreadMentionsReducer', () => {
test('if message id already exists, do not mutate state', () => {
const initialState = deepFreeze([1, 2]);

const action = deepFreeze({
type: EVENT_NEW_MESSAGE,
message: {
id: 2,
flags: ['mentioned'],
},
});
const action = mkMessageAction(eg.streamMessage({ id: 2, flags: ['mentioned', 'read'] }));

const actualState = unreadMentionsReducer(initialState, action);

Expand All @@ -102,13 +86,7 @@ describe('unreadMentionsReducer', () => {
test('if "mentioned" flag is set and message id does not exist, append to state', () => {
const initialState = deepFreeze([1, 2]);

const action = deepFreeze({
type: EVENT_NEW_MESSAGE,
message: {
id: 3,
flags: ['mentioned'],
},
});
const action = mkMessageAction(eg.streamMessage({ id: 3, flags: ['mentioned'] }));

const expectedState = [1, 2, 3];

Expand All @@ -124,6 +102,9 @@ describe('unreadMentionsReducer', () => {

const action = {
type: EVENT_UPDATE_MESSAGE_FLAGS,
id: 0,
all: false,
allMessages: Immutable.Map(),
messages: [1, 2, 3],
flag: 'star',
op: 'add',
Expand All @@ -139,6 +120,9 @@ describe('unreadMentionsReducer', () => {

const action = deepFreeze({
type: EVENT_UPDATE_MESSAGE_FLAGS,
id: 0,
all: false,
allMessages: Immutable.Map(),
messages: [2],
flag: 'read',
op: 'add',
Expand All @@ -154,6 +138,9 @@ describe('unreadMentionsReducer', () => {

const action = deepFreeze({
type: EVENT_UPDATE_MESSAGE_FLAGS,
id: 0,
all: false,
allMessages: Immutable.Map(),
messages: [2, 3],
flag: 'read',
op: 'add',
Expand All @@ -171,6 +158,9 @@ describe('unreadMentionsReducer', () => {

const action = deepFreeze({
type: EVENT_UPDATE_MESSAGE_FLAGS,
id: 0,
all: false,
allMessages: Immutable.Map(),
messages: [1, 2],
flag: 'read',
op: 'remove',
Expand All @@ -186,6 +176,8 @@ describe('unreadMentionsReducer', () => {

const action = deepFreeze({
type: EVENT_UPDATE_MESSAGE_FLAGS,
id: 0,
allMessages: Immutable.Map(),
messages: [],
flag: 'read',
op: 'add',
Expand Down

0 comments on commit fd93443

Please sign in to comment.