diff --git a/src/chat/__tests__/narrowsReducer-test.js b/src/chat/__tests__/narrowsReducer-test.js index 8990d8c714c..0ce484bcabe 100644 --- a/src/chat/__tests__/narrowsReducer-test.js +++ b/src/chat/__tests__/narrowsReducer-test.js @@ -32,114 +32,75 @@ describe('narrowsReducer', () => { describe('EVENT_NEW_MESSAGE', () => { test('if not caught up in narrow, do not add message in home narrow', () => { - const initialState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2] }); - const message = eg.streamMessage({ id: 3, flags: [] }); - const action = eg.mkActionEventNewMessage(message); - - const newState = narrowsReducer(initialState, action); - - const expectedState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2] }); - - expect(newState).toEqual(expectedState); + const prevState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2] }); + expect(narrowsReducer(prevState, eg.mkActionEventNewMessage(message))).toEqual( + Immutable.Map({ [HOME_NARROW_STR]: [1, 2] }), + ); }); test('appends message to state producing a copy of messages', () => { - const initialState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2] }); - const message = eg.streamMessage({ id: 3, flags: [] }); - const action = eg.mkActionEventNewMessage(message, { - caughtUp: { - [HOME_NARROW_STR]: { - older: false, - newer: true, - }, - }, - }); - - const expectedState = Immutable.Map({ - [HOME_NARROW_STR]: [1, 2, 3], - }); - - const newState = narrowsReducer(initialState, action); - - expect(newState).toEqual(expectedState); - expect(newState).not.toBe(initialState); + const prevState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2] }); + const newState = narrowsReducer( + prevState, + eg.mkActionEventNewMessage(message, { + caughtUp: { [HOME_NARROW_STR]: { older: false, newer: true } }, + }), + ); + expect(newState).toEqual(Immutable.Map({ [HOME_NARROW_STR]: [1, 2, 3] })); + expect(newState).not.toBe(prevState); }); test('if new message key does not exist do not create it', () => { - const initialState = Immutable.Map({ [topicNarrowStr]: [1, 2] }); - const message = eg.streamMessage({ id: 3, flags: [], stream: eg.makeStream() }); - const action = eg.mkActionEventNewMessage(message); - - const newState = narrowsReducer(initialState, action); - - const expectedState = Immutable.Map({ - [topicNarrowStr]: [1, 2], - }); - expect(newState).toEqual(expectedState); + const prevState = Immutable.Map({ [topicNarrowStr]: [1, 2] }); + expect(narrowsReducer(prevState, eg.mkActionEventNewMessage(message))).toEqual( + Immutable.Map({ [topicNarrowStr]: [1, 2] }), + ); }); }); test('if new message is private or group add it to the "allPrivate" narrow', () => { - const initialState = Immutable.Map({ [ALL_PRIVATE_NARROW_STR]: [] }); const message = eg.pmMessage({ id: 1, recipients: [eg.selfUser, eg.otherUser, eg.thirdUser], flags: [], }); - const action = eg.mkActionEventNewMessage(message, { - caughtUp: { - [ALL_PRIVATE_NARROW_STR]: { older: true, newer: true }, - }, - }); - const expectedState = Immutable.Map({ - [ALL_PRIVATE_NARROW_STR]: [1], - }); - - const actualState = narrowsReducer(initialState, action); - expect(actualState).toEqual(expectedState); + const prevState = Immutable.Map({ [ALL_PRIVATE_NARROW_STR]: [] }); + expect( + narrowsReducer( + prevState, + eg.mkActionEventNewMessage(message, { + caughtUp: { [ALL_PRIVATE_NARROW_STR]: { older: true, newer: true } }, + }), + ), + ).toEqual(Immutable.Map({ [ALL_PRIVATE_NARROW_STR]: [1] })); }); test('message sent to topic is stored correctly', () => { - const initialState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2], [topicNarrowStr]: [2] }); - const message = eg.streamMessage({ id: 3, flags: [] }); - const action = eg.mkActionEventNewMessage(message, { - caughtUp: { - [HOME_NARROW_STR]: { - older: false, - newer: false, - }, - [topicNarrowStr]: { - older: false, - newer: true, - }, - }, - }); - const expectedState = Immutable.Map({ - [HOME_NARROW_STR]: [1, 2], - [topicNarrowStr]: [2, message.id], - }); - - const newState = narrowsReducer(initialState, action); - - expect(newState).toEqual(expectedState); + const prevState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2], [topicNarrowStr]: [2] }); + expect( + narrowsReducer( + prevState, + eg.mkActionEventNewMessage(message, { + caughtUp: { + [HOME_NARROW_STR]: { older: false, newer: false }, + [topicNarrowStr]: { older: false, newer: true }, + }, + }), + ), + ).toEqual(Immutable.Map({ [HOME_NARROW_STR]: [1, 2], [topicNarrowStr]: [2, message.id] })); }); test('message sent to self is stored correctly', () => { const narrowWithSelfStr = keyFromNarrow(pm1to1NarrowFromUser(eg.selfUser)); - const initialState = Immutable.Map({ - [HOME_NARROW_STR]: [], - [narrowWithSelfStr]: [], - }); - const message = eg.pmMessage({ id: 1, sender: eg.selfUser, @@ -147,26 +108,26 @@ describe('narrowsReducer', () => { flags: [], }); - const action = eg.mkActionEventNewMessage(message, { - caughtUp: { - [HOME_NARROW_STR]: { older: false, newer: true }, - [narrowWithSelfStr]: { older: false, newer: true }, - }, - }); - - const expectedState = Immutable.Map({ - [HOME_NARROW_STR]: [message.id], - [narrowWithSelfStr]: [message.id], - }); - - const newState = narrowsReducer(initialState, action); - - expect(newState).toEqual(expectedState); - expect(newState).not.toBe(initialState); + const prevState = Immutable.Map({ [HOME_NARROW_STR]: [], [narrowWithSelfStr]: [] }); + const newState = narrowsReducer( + prevState, + eg.mkActionEventNewMessage(message, { + caughtUp: { + [HOME_NARROW_STR]: { older: false, newer: true }, + [narrowWithSelfStr]: { older: false, newer: true }, + }, + }), + ); + expect(newState).toEqual( + Immutable.Map({ [HOME_NARROW_STR]: [message.id], [narrowWithSelfStr]: [message.id] }), + ); + expect(newState).not.toBe(prevState); }); test('appends stream message to all cached narrows that match and are caught up', () => { - const initialState = Immutable.Map({ + const message = eg.streamMessage({ id: 5, flags: [] }); + + const prevState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2], [ALL_PRIVATE_NARROW_STR]: [1, 2], [streamNarrowStr]: [2, 3], @@ -174,63 +135,44 @@ describe('narrowsReducer', () => { [privateNarrowStr]: [2, 4], [groupNarrowStr]: [2, 4], }); - - const message = eg.streamMessage({ id: 5, flags: [] }); - - const action = eg.mkActionEventNewMessage(message, { - caughtUp: { - [HOME_NARROW_STR]: { older: false, newer: true }, - [streamNarrowStr]: { older: false, newer: true }, - [topicNarrowStr]: { older: false, newer: true }, - }, - }); - - const expectedState = Immutable.Map({ - [HOME_NARROW_STR]: [1, 2, message.id], - [ALL_PRIVATE_NARROW_STR]: [1, 2], - [streamNarrowStr]: [2, 3, message.id], - [topicNarrowStr]: [2, 3, message.id], - [privateNarrowStr]: [2, 4], - [groupNarrowStr]: [2, 4], - }); - - const newState = narrowsReducer(initialState, action); - - expect(newState).toEqual(expectedState); - expect(newState).not.toBe(initialState); + const newState = narrowsReducer( + prevState, + eg.mkActionEventNewMessage(message, { + caughtUp: { + [HOME_NARROW_STR]: { older: false, newer: true }, + [streamNarrowStr]: { older: false, newer: true }, + [topicNarrowStr]: { older: false, newer: true }, + }, + }), + ); + expect(newState).toEqual( + Immutable.Map({ + [HOME_NARROW_STR]: [1, 2, message.id], + [ALL_PRIVATE_NARROW_STR]: [1, 2], + [streamNarrowStr]: [2, 3, message.id], + [topicNarrowStr]: [2, 3, message.id], + [privateNarrowStr]: [2, 4], + [groupNarrowStr]: [2, 4], + }), + ); + expect(newState).not.toBe(prevState); }); test('does not append stream message to not cached narrows', () => { - const initialState = Immutable.Map({ [HOME_NARROW_STR]: [1] }); - const message = eg.streamMessage({ id: 3, flags: [] }); - const action = eg.mkActionEventNewMessage(message, { - caughtUp: { - [HOME_NARROW_STR]: { older: false, newer: true }, - }, - }); - - const expectedState = Immutable.Map({ - [HOME_NARROW_STR]: [1, message.id], - }); - - const newState = narrowsReducer(initialState, action); - - expect(newState).toEqual(expectedState); - expect(newState).not.toBe(initialState); + const prevState = Immutable.Map({ [HOME_NARROW_STR]: [1] }); + const newState = narrowsReducer( + prevState, + eg.mkActionEventNewMessage(message, { + caughtUp: { [HOME_NARROW_STR]: { older: false, newer: true } }, + }), + ); + expect(newState).toEqual(Immutable.Map({ [HOME_NARROW_STR]: [1, message.id] })); + expect(newState).not.toBe(prevState); }); test('appends private message to multiple cached narrows', () => { - const initialState = Immutable.Map({ - [HOME_NARROW_STR]: [1, 2], - [ALL_PRIVATE_NARROW_STR]: [1, 2], - [streamNarrowStr]: [2, 3], - [topicNarrowStr]: [2, 3], - [privateNarrowStr]: [2, 4], - [groupNarrowStr]: [2, 4], - }); - const message = eg.pmMessage({ id: 5, flags: [], @@ -238,78 +180,68 @@ describe('narrowsReducer', () => { recipients: [eg.selfUser, eg.otherUser], }); - const action = eg.mkActionEventNewMessage(message, { - caughtUp: initialState.map(_ => ({ older: false, newer: true })).toObject(), - }); - - const expectedState = Immutable.Map({ - [HOME_NARROW_STR]: [1, 2, message.id], - [ALL_PRIVATE_NARROW_STR]: [1, 2, message.id], + const prevState = Immutable.Map({ + [HOME_NARROW_STR]: [1, 2], + [ALL_PRIVATE_NARROW_STR]: [1, 2], [streamNarrowStr]: [2, 3], [topicNarrowStr]: [2, 3], - [privateNarrowStr]: [2, 4, message.id], + [privateNarrowStr]: [2, 4], [groupNarrowStr]: [2, 4], }); - - const newState = narrowsReducer(initialState, action); - - expect(newState).toEqual(expectedState); - expect(newState).not.toBe(initialState); + const newState = narrowsReducer( + prevState, + eg.mkActionEventNewMessage(message, { + caughtUp: prevState.map(_ => ({ older: false, newer: true })).toObject(), + }), + ); + expect(newState).toEqual( + Immutable.Map({ + [HOME_NARROW_STR]: [1, 2, message.id], + [ALL_PRIVATE_NARROW_STR]: [1, 2, message.id], + [streamNarrowStr]: [2, 3], + [topicNarrowStr]: [2, 3], + [privateNarrowStr]: [2, 4, message.id], + [groupNarrowStr]: [2, 4], + }), + ); + expect(newState).not.toBe(prevState); }); describe('EVENT_MESSAGE_DELETE', () => { test('if a message does not exist no changes are made', () => { - const initialState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2], [privateNarrowStr]: [] }); - - const action = deepFreeze({ - type: EVENT_MESSAGE_DELETE, - messageIds: [3], - }); - - const newState = narrowsReducer(initialState, action); - - expect(newState).toBe(initialState); + const prevState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2], [privateNarrowStr]: [] }); + expect( + narrowsReducer(prevState, deepFreeze({ type: EVENT_MESSAGE_DELETE, messageIds: [3] })), + ).toBe(prevState); }); test('if a message exists in one or more narrows delete it from there', () => { - const initialState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2, 3], [privateNarrowStr]: [2] }); - const action = deepFreeze({ - type: EVENT_MESSAGE_DELETE, - messageIds: [2], - }); - const expectedState = Immutable.Map({ [HOME_NARROW_STR]: [1, 3], [privateNarrowStr]: [] }); - - const newState = narrowsReducer(initialState, action); - - expect(newState).toEqual(expectedState); + const prevState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2, 3], [privateNarrowStr]: [2] }); + expect( + narrowsReducer(prevState, deepFreeze({ type: EVENT_MESSAGE_DELETE, messageIds: [2] })), + ).toEqual(Immutable.Map({ [HOME_NARROW_STR]: [1, 3], [privateNarrowStr]: [] })); }); test('if multiple messages indicated, delete the ones that exist', () => { - const initialState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2, 3], [privateNarrowStr]: [2] }); - const action = deepFreeze({ - type: EVENT_MESSAGE_DELETE, - messageIds: [2, 3, 4], - }); - const expectedState = Immutable.Map({ [HOME_NARROW_STR]: [1], [privateNarrowStr]: [] }); - - const newState = narrowsReducer(initialState, action); - - expect(newState).toEqual(expectedState); + const prevState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2, 3], [privateNarrowStr]: [2] }); + expect( + narrowsReducer( + prevState, + deepFreeze({ type: EVENT_MESSAGE_DELETE, messageIds: [2, 3, 4] }), + ), + ).toEqual(Immutable.Map({ [HOME_NARROW_STR]: [1], [privateNarrowStr]: [] })); }); }); describe('MESSAGE_FETCH_START', () => { test('if fetching for a search narrow, ignore', () => { - const initialState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2] }); - - const action = deepFreeze({ - ...eg.action.message_fetch_start, - narrow: SEARCH_NARROW('some query'), - }); - - const newState = narrowsReducer(initialState, action); - - expect(newState).toEqual(initialState); + const prevState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2] }); + expect( + narrowsReducer( + prevState, + deepFreeze({ ...eg.action.message_fetch_start, narrow: SEARCH_NARROW('some query') }), + ), + ).toEqual(prevState); }); }); @@ -319,56 +251,35 @@ describe('narrowsReducer', () => { // MESSAGE_FETCH_START applies the identity function to the // state (i.e., it doesn't do anything to it). Reversing that // effect is also done with the identity function. - const initialState = Immutable.Map({ - [HOME_NARROW_STR]: { - older: true, - newer: true, - }, - }); - - const messageFetchStartAction = deepFreeze({ - ...eg.action.message_fetch_start, - narrow: HOME_NARROW, - }); - - const state1 = narrowsReducer(initialState, messageFetchStartAction); - - const messageFetchErrorAction = deepFreeze({ - type: MESSAGE_FETCH_ERROR, - narrow: HOME_NARROW, - error: new Error(), - }); - - const finalState = narrowsReducer(state1, messageFetchErrorAction); - - expect(finalState).toEqual(initialState); + expect( + [ + deepFreeze({ ...eg.action.message_fetch_start, narrow: HOME_NARROW }), + deepFreeze({ type: MESSAGE_FETCH_ERROR, narrow: HOME_NARROW, error: new Error() }), + ].reduce(narrowsReducer, eg.baseReduxState.narrows), + ).toEqual(eg.baseReduxState.narrows); }); }); describe('MESSAGE_FETCH_COMPLETE', () => { test('if no messages returned still create the key in state', () => { - const initialState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2, 3] }); - - const action = { - ...eg.action.message_fetch_complete, - narrow: pm1to1NarrowFromUser(eg.otherUser), - messages: [], - }; - - const expectedState = Immutable.Map({ - [HOME_NARROW_STR]: [1, 2, 3], - [keyFromNarrow(pm1to1NarrowFromUser(eg.otherUser))]: [], - }); - - const newState = narrowsReducer(initialState, action); - - expect(newState).toEqual(expectedState); + const prevState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2, 3] }); + expect( + narrowsReducer(prevState, { + ...eg.action.message_fetch_complete, + narrow: pm1to1NarrowFromUser(eg.otherUser), + messages: [], + }), + ).toEqual( + Immutable.Map({ + [HOME_NARROW_STR]: [1, 2, 3], + [keyFromNarrow(pm1to1NarrowFromUser(eg.otherUser))]: [], + }), + ); }); test('no duplicate messages', () => { - const initialState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2, 3] }); - - const action = { + const prevState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2, 3] }); + const newState = narrowsReducer(prevState, { ...eg.action.message_fetch_complete, narrow: HOME_NARROW, anchor: 2, @@ -377,22 +288,14 @@ describe('narrowsReducer', () => { eg.streamMessage({ id: 3 }), eg.streamMessage({ id: 4 }), ], - }; - - const expectedState = Immutable.Map({ - [HOME_NARROW_STR]: [1, 2, 3, 4], }); - - const newState = narrowsReducer(initialState, action); - - expect(newState).toEqual(expectedState); - expect(newState).not.toBe(initialState); + expect(newState).toEqual(Immutable.Map({ [HOME_NARROW_STR]: [1, 2, 3, 4] })); + expect(newState).not.toBe(prevState); }); test('added messages are sorted by id', () => { - const initialState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2] }); - - const action = { + const prevState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2] }); + const newState = narrowsReducer(prevState, { ...eg.action.message_fetch_complete, narrow: HOME_NARROW, anchor: 2, @@ -400,70 +303,48 @@ describe('narrowsReducer', () => { eg.streamMessage({ id: 3, timestamp: 2 }), eg.streamMessage({ id: 4, timestamp: 1 }), ], - }; - - const expectedState = Immutable.Map({ - [HOME_NARROW_STR]: [1, 2, 3, 4], }); - - const newState = narrowsReducer(initialState, action); - - expect(newState).toEqual(expectedState); - expect(newState).not.toBe(initialState); + expect(newState).toEqual(Immutable.Map({ [HOME_NARROW_STR]: [1, 2, 3, 4] })); + expect(newState).not.toBe(prevState); }); test('when anchor is FIRST_UNREAD_ANCHOR previous messages are replaced', () => { - const initialState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2] }); - - const action = { - ...eg.action.message_fetch_complete, - narrow: HOME_NARROW, - anchor: FIRST_UNREAD_ANCHOR, - messages: [ - eg.streamMessage({ id: 3, timestamp: 2 }), - eg.streamMessage({ id: 4, timestamp: 1 }), - ], - }; - - const expectedState = Immutable.Map({ - [HOME_NARROW_STR]: [3, 4], - }); - - const newState = narrowsReducer(initialState, action); - - expect(newState).toEqual(expectedState); + const prevState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2] }); + expect( + narrowsReducer(prevState, { + ...eg.action.message_fetch_complete, + narrow: HOME_NARROW, + anchor: FIRST_UNREAD_ANCHOR, + messages: [ + eg.streamMessage({ id: 3, timestamp: 2 }), + eg.streamMessage({ id: 4, timestamp: 1 }), + ], + }), + ).toEqual(Immutable.Map({ [HOME_NARROW_STR]: [3, 4] })); }); test('when anchor is LAST_MESSAGE_ANCHOR previous messages are replaced', () => { - const initialState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2] }); - - const action = { - ...eg.action.message_fetch_complete, - narrow: HOME_NARROW, - anchor: LAST_MESSAGE_ANCHOR, - messages: [ - eg.streamMessage({ id: 3, timestamp: 2 }), - eg.streamMessage({ id: 4, timestamp: 1 }), - ], - }; - - const expectedState = Immutable.Map({ - [HOME_NARROW_STR]: [3, 4], - }); - - const newState = narrowsReducer(initialState, action); - - expect(newState).toEqual(expectedState); + const prevState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2] }); + expect( + narrowsReducer(prevState, { + ...eg.action.message_fetch_complete, + anchor: LAST_MESSAGE_ANCHOR, + messages: [ + eg.streamMessage({ id: 3, timestamp: 2 }), + eg.streamMessage({ id: 4, timestamp: 1 }), + ], + }), + ).toEqual(Immutable.Map({ [HOME_NARROW_STR]: [3, 4] })); }); test('if fetched messages are from a search narrow, ignore them', () => { - const initialState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2] }); - - const action = { ...eg.action.message_fetch_complete, narrow: SEARCH_NARROW('some query') }; - - const newState = narrowsReducer(initialState, action); - - expect(newState).toEqual(initialState); + const prevState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2] }); + expect( + narrowsReducer(prevState, { + ...eg.action.message_fetch_complete, + narrow: SEARCH_NARROW('some query'), + }), + ).toEqual(prevState); }); }); @@ -544,64 +425,60 @@ describe('narrowsReducer', () => { ]); test('Do nothing if the is:starred narrow has not been fetched', () => { - const initialState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2] }); - - const action = deepFreeze({ - type: EVENT_UPDATE_MESSAGE_FLAGS, - id: 1, - allMessages, - all: false, - flag: 'starred', - op: 'add', - messages: [4, 2], - }); - - const newState = narrowsReducer(initialState, action); - - expect(newState).toEqual(initialState); + const prevState = Immutable.Map({ [HOME_NARROW_STR]: [1, 2] }); + expect( + narrowsReducer( + prevState, + deepFreeze({ + type: EVENT_UPDATE_MESSAGE_FLAGS, + id: 1, + allMessages, + all: false, + flag: 'starred', + op: 'add', + messages: [4, 2], + }), + ), + ).toEqual(prevState); }); test("Do nothing if action.flag is not 'starred'", () => { - const initialState = Immutable.Map({ [STARRED_NARROW_STR]: [1, 2] }); - - const action = deepFreeze({ - type: EVENT_UPDATE_MESSAGE_FLAGS, - id: 1, - all: false, - allMessages, - op: 'add', - messages: [1], - flag: 'read', - }); - - const newState = narrowsReducer(initialState, action); - - expect(newState).toEqual(initialState); + const prevState = Immutable.Map({ [STARRED_NARROW_STR]: [1, 2] }); + expect( + narrowsReducer( + prevState, + deepFreeze({ + type: EVENT_UPDATE_MESSAGE_FLAGS, + id: 1, + all: false, + allMessages, + op: 'add', + messages: [1], + flag: 'read', + }), + ), + ).toEqual(prevState); }); test( 'Adds, while maintaining chronological order, ' + 'newly starred messages to the is:starred narrow', () => { - const initialState = Immutable.Map({ [STARRED_NARROW_STR]: [1, 3, 5] }); - - const action = deepFreeze({ - type: EVENT_UPDATE_MESSAGE_FLAGS, - id: 1, - allMessages, - all: false, - flag: 'starred', - op: 'add', - messages: [4, 2], - }); - - const expectedState = Immutable.Map({ - [STARRED_NARROW_STR]: [1, 2, 3, 4, 5], - }); - - const newState = narrowsReducer(initialState, action); - - expect(newState).toEqual(expectedState); + const prevState = Immutable.Map({ [STARRED_NARROW_STR]: [1, 3, 5] }); + expect( + narrowsReducer( + prevState, + deepFreeze({ + type: EVENT_UPDATE_MESSAGE_FLAGS, + id: 1, + allMessages, + all: false, + flag: 'starred', + op: 'add', + messages: [4, 2], + }), + ), + ).toEqual(Immutable.Map({ [STARRED_NARROW_STR]: [1, 2, 3, 4, 5] })); }, ); @@ -609,25 +486,21 @@ describe('narrowsReducer', () => { 'Removes, while maintaining chronological order, ' + 'newly unstarred messages from the is:starred narrow', () => { - const initialState = Immutable.Map({ [STARRED_NARROW_STR]: [1, 2, 3, 4, 5] }); - - const action = deepFreeze({ - type: EVENT_UPDATE_MESSAGE_FLAGS, - id: 1, - allMessages, - all: false, - flag: 'starred', - op: 'remove', - messages: [4, 2], - }); - - const expectedState = Immutable.Map({ - [STARRED_NARROW_STR]: [1, 3, 5], - }); - - const newState = narrowsReducer(initialState, action); - - expect(newState).toEqual(expectedState); + const prevState = Immutable.Map({ [STARRED_NARROW_STR]: [1, 2, 3, 4, 5] }); + expect( + narrowsReducer( + prevState, + deepFreeze({ + type: EVENT_UPDATE_MESSAGE_FLAGS, + id: 1, + allMessages, + all: false, + flag: 'starred', + op: 'remove', + messages: [4, 2], + }), + ), + ).toEqual(Immutable.Map({ [STARRED_NARROW_STR]: [1, 3, 5] })); }, ); });