Skip to content

Commit a50be3c

Browse files
committed
model tests: Cover RESET_ACCOUNT_DATA for all reducers that use it
In #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.
1 parent 08053da commit a50be3c

File tree

9 files changed

+82
-0
lines changed

9 files changed

+82
-0
lines changed

src/alertWords/__tests__/alertWordsReducer-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ import { EVENT_ALERT_WORDS } from '../../actionConstants';
77
import * as eg from '../../__tests__/lib/exampleData';
88

99
describe('alertWordsReducer', () => {
10+
describe('RESET_ACCOUNT_DATA', () => {
11+
const initialState = eg.baseReduxState.alertWords;
12+
const action1 = eg.mkActionRegisterComplete({ alert_words: ['word', '@mobile-core', 'alert'] });
13+
const prevState = alertWordsReducer(initialState, action1);
14+
expect(prevState).not.toEqual(initialState);
15+
16+
expect(alertWordsReducer(prevState, eg.action.reset_account_data)).toEqual(initialState);
17+
});
18+
1019
describe('REGISTER_COMPLETE', () => {
1120
test('when `alert_words` data is provided init state with it', () => {
1221
const prevState = deepFreeze([]);

src/caughtup/__tests__/caughtUpReducer-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ import {
1616
import { objectFromEntries } from '../../jsBackport';
1717

1818
describe('caughtUpReducer', () => {
19+
describe('RESET_ACCOUNT_DATA', () => {
20+
const initialState = eg.baseReduxState.caughtUp;
21+
const action1 = { ...eg.action.message_fetch_complete, foundNewest: true, foundOldest: true };
22+
const prevState = caughtUpReducer(initialState, action1);
23+
expect(prevState).not.toEqual(initialState);
24+
25+
expect(caughtUpReducer(prevState, eg.action.reset_account_data)).toEqual(initialState);
26+
});
27+
1928
describe('MESSAGE_FETCH_START', () => {
2029
test('when fetch starts caught up does not change', () => {
2130
const prevState = deepFreeze({ [HOME_NARROW_STR]: { older: true, newer: true } });

src/chat/__tests__/fetchingReducer-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ import { MESSAGE_FETCH_START, MESSAGE_FETCH_ERROR } from '../../actionConstants'
1414
import { DEFAULT_FETCHING } from '../fetchingSelectors';
1515

1616
describe('fetchingReducer', () => {
17+
describe('RESET_ACCOUNT_DATA', () => {
18+
const initialState = eg.baseReduxState.fetching;
19+
const action1 = { type: MESSAGE_FETCH_START, narrow: HOME_NARROW, numBefore: 10, numAfter: 10 };
20+
const prevState = fetchingReducer(initialState, action1);
21+
expect(prevState).not.toEqual(initialState);
22+
23+
expect(fetchingReducer(prevState, eg.action.reset_account_data)).toEqual(initialState);
24+
});
25+
1726
describe('MESSAGE_FETCH_START', () => {
1827
test('if messages are fetched before or after the corresponding flag is set', () => {
1928
const initialState = deepFreeze({

src/chat/__tests__/narrowsReducer-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ describe('narrowsReducer', () => {
3030
const egTopic = eg.streamMessage().subject;
3131
const topicNarrowStr = keyFromNarrow(topicNarrow(eg.stream.stream_id, egTopic));
3232

33+
describe('RESET_ACCOUNT_DATA', () => {
34+
const initialState = eg.baseReduxState.narrows;
35+
const action1 = { ...eg.action.message_fetch_complete, messages: [eg.streamMessage()] };
36+
const prevState = narrowsReducer(initialState, action1);
37+
expect(prevState).not.toEqual(initialState);
38+
39+
expect(narrowsReducer(prevState, eg.action.reset_account_data)).toEqual(initialState);
40+
});
41+
3342
describe('EVENT_NEW_MESSAGE', () => {
3443
test('if not caught up in narrow, do not add message in home narrow', () => {
3544
const message = eg.streamMessage({ id: 3, flags: [] });

src/drafts/__tests__/draftsReducer-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ describe('draftsReducer', () => {
1111
const testNarrow = topicNarrow(eg.stream.stream_id, 'denmark2');
1212
const testNarrowStr = keyFromNarrow(testNarrow);
1313

14+
describe('RESET_ACCOUNT_DATA', () => {
15+
const initialState = eg.baseReduxState.drafts;
16+
const action1 = { type: DRAFT_UPDATE, content: 'Hello', narrow: testNarrow };
17+
const prevState = draftsReducer(initialState, action1);
18+
expect(prevState).not.toEqual(initialState);
19+
20+
expect(draftsReducer(prevState, eg.action.reset_account_data)).toEqual(initialState);
21+
});
22+
1423
describe('DRAFT_UPDATE', () => {
1524
test('add a new draft key drafts', () => {
1625
const prevState = NULL_OBJECT;

src/message/__tests__/messagesReducer-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ import { makeUserId } from '../../api/idTypes';
1717
import { randString } from '../../utils/misc';
1818

1919
describe('messagesReducer', () => {
20+
test('RESET_ACCOUNT_DATA', () => {
21+
expect(
22+
messagesReducer(
23+
eg.makeMessagesState([eg.streamMessage()]),
24+
eg.action.reset_account_data,
25+
eg.baseReduxState,
26+
),
27+
).toEqual(eg.baseReduxState.messages);
28+
});
29+
2030
describe('EVENT_NEW_MESSAGE', () => {
2131
test('appends message to state, if any narrow is caught up to newest', () => {
2232
const message1 = eg.streamMessage();

src/outbox/__tests__/outboxReducer-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ import { MESSAGE_SEND_START } from '../../actionConstants';
77
import * as eg from '../../__tests__/lib/exampleData';
88

99
describe('outboxReducer', () => {
10+
describe('RESET_ACCOUNT_DATA', () => {
11+
const initialState = eg.baseReduxState.outbox;
12+
const action1 = { type: MESSAGE_SEND_START, outbox: eg.streamOutbox({}) };
13+
const prevState = outboxReducer(initialState, action1);
14+
expect(prevState).not.toEqual(initialState);
15+
16+
expect(outboxReducer(prevState, eg.action.reset_account_data)).toEqual(initialState);
17+
});
18+
1019
describe('REGISTER_COMPLETE', () => {
1120
test('filters out isSent', () => {
1221
const message1 = eg.streamOutbox({ content: 'New one' });

src/pm-conversations/__tests__/pmConversationsModel-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ describe('reducer', () => {
2323
const someKey = keyOfExactUsers([eg.makeUser().user_id]);
2424
const someState = { map: Immutable.Map([[someKey, 123]]), sorted: Immutable.List([someKey]) };
2525

26+
test('RESET_ACCOUNT_DATA', () => {
27+
expect(reducer(someState, eg.action.reset_account_data)).toEqual(initialState);
28+
});
29+
2630
describe('REGISTER_COMPLETE', () => {
2731
test('no data (old server)', () => {
2832
/* eslint-disable-next-line no-unused-vars */

src/typing/__tests__/typingReducer-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ describe('typingReducer', () => {
3232
: { ...base, op: 'stop', type: EVENT_TYPING_STOP };
3333
};
3434

35+
describe('RESET_ACCOUNT_DATA', () => {
36+
const initialState = eg.baseReduxState.typing;
37+
const action1 = egTypingAction({
38+
op: 'start',
39+
sender: user1,
40+
recipients: [user1, user2],
41+
time: 123456789,
42+
});
43+
const prevState = typingReducer(initialState, action1);
44+
expect(prevState).not.toEqual(initialState);
45+
46+
expect(typingReducer(prevState, eg.action.reset_account_data)).toEqual(initialState);
47+
});
48+
3549
describe('EVENT_TYPING_START', () => {
3650
test('adds sender as currently typing user', () => {
3751
const prevState = NULL_OBJECT;

0 commit comments

Comments
 (0)