Skip to content

Commit 9472686

Browse files
chrisbobbegnprice
authored andcommitted
model tests: Fill in coverage of all interesting REGISTER_COMPLETE handlers
1 parent a595be8 commit 9472686

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

src/caughtup/__tests__/caughtUpReducer-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ describe('caughtUpReducer', () => {
2525
expect(caughtUpReducer(prevState, eg.action.reset_account_data)).toEqual(initialState);
2626
});
2727

28+
describe('REGISTER_COMPLETE', () => {
29+
const initialState = eg.baseReduxState.caughtUp;
30+
const prevState = caughtUpReducer(initialState, {
31+
...eg.action.message_fetch_complete,
32+
foundNewest: true,
33+
foundOldest: true,
34+
});
35+
expect(prevState).not.toEqual(initialState);
36+
37+
expect(caughtUpReducer(prevState, eg.action.register_complete)).toEqual(initialState);
38+
});
39+
2840
describe('MESSAGE_FETCH_START', () => {
2941
test('when fetch starts caught up does not change', () => {
3042
const prevState = deepFreeze({ [HOME_NARROW_STR]: { older: true, newer: true } });

src/chat/__tests__/flagsReducer-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ import flagsReducer from '../flagsReducer';
77
import { EVENT_UPDATE_MESSAGE_FLAGS } from '../../actionConstants';
88

99
describe('flagsReducer', () => {
10+
describe('REGISTER_COMPLETE', () => {
11+
const initialState = eg.baseReduxState.flags;
12+
const prevState = flagsReducer(
13+
initialState,
14+
eg.mkActionEventNewMessage(eg.streamMessage({ flags: ['read', 'starred'] })),
15+
);
16+
expect(prevState).not.toEqual(initialState);
17+
18+
expect(flagsReducer(prevState, eg.action.register_complete)).toEqual(initialState);
19+
});
20+
1021
describe('MESSAGE_FETCH_COMPLETE', () => {
1122
test('flags from all messages are extracted and stored by id', () => {
1223
const message1 = eg.streamMessage();

src/chat/__tests__/narrowsReducer-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ describe('narrowsReducer', () => {
3939
expect(narrowsReducer(prevState, eg.action.reset_account_data)).toEqual(initialState);
4040
});
4141

42+
describe('REGISTER_COMPLETE', () => {
43+
const initialState = eg.baseReduxState.narrows;
44+
const prevState = narrowsReducer(initialState, {
45+
...eg.action.message_fetch_complete,
46+
messages: [eg.streamMessage()],
47+
});
48+
expect(prevState).not.toEqual(initialState);
49+
50+
expect(narrowsReducer(prevState, eg.action.register_complete)).toEqual(initialState);
51+
});
52+
4253
describe('EVENT_NEW_MESSAGE', () => {
4354
test('if not caught up in narrow, do not add message in home narrow', () => {
4455
const message = eg.streamMessage({ id: 3, flags: [] });

src/message/__tests__/messagesReducer-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ describe('messagesReducer', () => {
2727
).toEqual(eg.baseReduxState.messages);
2828
});
2929

30+
describe('REGISTER_COMPLETE', () => {
31+
const initialState = eg.baseReduxState.messages;
32+
const prevState = messagesReducer(
33+
initialState,
34+
{ ...eg.action.message_fetch_complete, messages: [eg.streamMessage()] },
35+
eg.baseReduxState,
36+
);
37+
expect(prevState).not.toEqual(initialState);
38+
39+
expect(messagesReducer(prevState, eg.action.register_complete, eg.baseReduxState)).toEqual(
40+
initialState,
41+
);
42+
});
43+
3044
describe('EVENT_NEW_MESSAGE', () => {
3145
test('appends message to state, if any narrow is caught up to newest', () => {
3246
const message1 = eg.streamMessage();

src/streams/__tests__/streamsReducer-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ describe('streamsReducer', () => {
1919
});
2020
});
2121

22+
describe('REGISTER_COMPLETE', () => {
23+
test('stores initial streams data', () => {
24+
const streams = [eg.makeStream(), eg.makeStream()];
25+
26+
const prevState = eg.baseReduxState.streams;
27+
const action = eg.mkActionRegisterComplete({ streams });
28+
expect(streamsReducer(prevState, action)).toEqual(streams);
29+
});
30+
});
31+
2232
describe('EVENT -> stream -> create', () => {
2333
test('add new stream', () => {
2434
const stream1 = eg.makeStream({ name: 'some stream', stream_id: 1 });

0 commit comments

Comments
 (0)