Skip to content

Commit

Permalink
model tests: Cover RESET_ACCOUNT_DATA for all reducers that use it
Browse files Browse the repository at this point in the history
In zulip#5606, I updated all the existing tests for ACCOUNT_SWITCH, etc.,
to test RESET_ACCOUNT_DATA instead, naturally.

…But that didn't give complete coverage of the RESET_ACCOUNT_DATA
action, because some tests weren't testing for ACCOUNT_SWITCH, etc.,
in the first place. So, add the coverage now.
  • Loading branch information
chrisbobbe committed Dec 14, 2022
1 parent bf5e32a commit 101569f
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/alertWords/__tests__/alertWordsReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ import { EVENT_ALERT_WORDS } from '../../actionConstants';
import * as eg from '../../__tests__/lib/exampleData';

describe('alertWordsReducer', () => {
describe('RESET_ACCOUNT_DATA', () => {
expect(
[
eg.mkActionRegisterComplete({ alert_words: ['word', '@mobile-core', 'alert'] }),
eg.action.reset_account_data,
].reduce(alertWordsReducer, eg.baseReduxState.alertWords),
).toEqual(eg.baseReduxState.alertWords);
});

describe('REGISTER_COMPLETE', () => {
test('when `alert_words` data is provided init state with it', () => {
const prevState = deepFreeze([]);
Expand Down
9 changes: 9 additions & 0 deletions src/caughtup/__tests__/caughtUpReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ import {
import { objectFromEntries } from '../../jsBackport';

describe('caughtUpReducer', () => {
test('RESET_ACCOUNT_DATA', () => {
expect(
[
{ ...eg.action.message_fetch_complete, foundNewest: true, foundOldest: true },
eg.action.reset_account_data,
].reduce(caughtUpReducer, eg.baseReduxState.caughtUp),
).toEqual(eg.baseReduxState.caughtUp);
});

describe('MESSAGE_FETCH_START', () => {
test('when fetch starts caught up does not change', () => {
const prevState = deepFreeze({ [HOME_NARROW_STR]: { older: true, newer: true } });
Expand Down
9 changes: 9 additions & 0 deletions src/chat/__tests__/fetchingReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ import { MESSAGE_FETCH_START, MESSAGE_FETCH_ERROR } from '../../actionConstants'
import { DEFAULT_FETCHING } from '../fetchingSelectors';

describe('fetchingReducer', () => {
test('RESET_ACCOUNT_DATA', () => {
expect(
[
{ type: MESSAGE_FETCH_START, narrow: HOME_NARROW, numBefore: 10, numAfter: 10 },
eg.action.reset_account_data,
].reduce(fetchingReducer, eg.baseReduxState.fetching),
).toEqual(eg.baseReduxState.fetching);
});

describe('MESSAGE_FETCH_START', () => {
test('if messages are fetched before or after the corresponding flag is set', () => {
const initialState = deepFreeze({
Expand Down
9 changes: 9 additions & 0 deletions src/chat/__tests__/narrowsReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ describe('narrowsReducer', () => {
const egTopic = eg.streamMessage().subject;
const topicNarrowStr = keyFromNarrow(topicNarrow(eg.stream.stream_id, egTopic));

test('RESET_ACCOUNT_DATA', () => {
expect(
[
{ ...eg.action.message_fetch_complete, messages: [eg.streamMessage()] },
eg.action.reset_account_data,
].reduce(narrowsReducer, eg.baseReduxState.narrows),
).toEqual(eg.baseReduxState.narrows);
});

describe('EVENT_NEW_MESSAGE', () => {
test('if not caught up in narrow, do not add message in home narrow', () => {
const message = eg.streamMessage({ id: 3, flags: [] });
Expand Down
9 changes: 9 additions & 0 deletions src/drafts/__tests__/draftsReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ describe('draftsReducer', () => {
const testNarrow = topicNarrow(eg.stream.stream_id, 'denmark2');
const testNarrowStr = keyFromNarrow(testNarrow);

describe('RESET_ACCOUNT_DATA', () => {
expect(
[
{ type: DRAFT_UPDATE, content: 'Hello', narrow: testNarrow },
eg.action.reset_account_data,
].reduce(draftsReducer, eg.baseReduxState.drafts),
).toEqual(eg.baseReduxState.drafts);
});

describe('DRAFT_UPDATE', () => {
test('add a new draft key drafts', () => {
const prevState = NULL_OBJECT;
Expand Down
10 changes: 10 additions & 0 deletions src/message/__tests__/messagesReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ import { makeUserId } from '../../api/idTypes';
import { randString } from '../../utils/misc';

describe('messagesReducer', () => {
test('RESET_ACCOUNT_DATA', () => {
expect(
messagesReducer(
eg.makeMessagesState([eg.streamMessage()]),
eg.action.reset_account_data,
eg.baseReduxState,
),
).toEqual(eg.baseReduxState.messages);
});

describe('EVENT_NEW_MESSAGE', () => {
test('appends message to state, if any narrow is caught up to newest', () => {
const message1 = eg.streamMessage();
Expand Down
9 changes: 9 additions & 0 deletions src/outbox/__tests__/outboxReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ import { MESSAGE_SEND_START } from '../../actionConstants';
import * as eg from '../../__tests__/lib/exampleData';

describe('outboxReducer', () => {
describe('RESET_ACCOUNT_DATA', () => {
expect(
[
{ type: MESSAGE_SEND_START, outbox: eg.streamOutbox({}) },
eg.action.reset_account_data,
].reduce(outboxReducer, eg.baseReduxState.outbox),
).toEqual(eg.baseReduxState.outbox);
});

describe('REGISTER_COMPLETE', () => {
test('filters out isSent', () => {
const message1 = eg.streamOutbox({ content: 'New one' });
Expand Down
4 changes: 4 additions & 0 deletions src/pm-conversations/__tests__/pmConversationsModel-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ describe('reducer', () => {
const someKey = keyOfExactUsers([eg.makeUser().user_id]);
const someState = { map: Immutable.Map([[someKey, 123]]), sorted: Immutable.List([someKey]) };

test('RESET_ACCOUNT_DATA', () => {
expect(reducer(someState, eg.action.reset_account_data)).toEqual(initialState);
});

describe('REGISTER_COMPLETE', () => {
test('no data (old server)', () => {
/* eslint-disable-next-line no-unused-vars */
Expand Down
9 changes: 9 additions & 0 deletions src/typing/__tests__/typingReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ describe('typingReducer', () => {
: { ...base, op: 'stop', type: EVENT_TYPING_STOP };
};

test('RESET_ACCOUNT_DATA', () => {
expect(
[
egTypingAction({ op: 'start', sender: user1, recipients: [user1, user2], time: 123456789 }),
eg.action.reset_account_data,
].reduce(typingReducer, eg.baseReduxState.typing),
).toEqual(eg.baseReduxState.typing);
});

describe('EVENT_TYPING_START', () => {
test('adds sender as currently typing user', () => {
const prevState = NULL_OBJECT;
Expand Down

0 comments on commit 101569f

Please sign in to comment.