Skip to content

Commit 1e54e4d

Browse files
chrisbobbegnprice
authored andcommitted
topics tests [nfc]: Tighten code style a bit
1 parent 2938916 commit 1e54e4d

File tree

1 file changed

+41
-119
lines changed

1 file changed

+41
-119
lines changed

src/topics/__tests__/topicsReducer-test.js

Lines changed: 41 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -11,107 +11,60 @@ describe('topicsReducer', () => {
1111
describe('ACCOUNT_SWITCH', () => {
1212
test('resets state to initial state', () => {
1313
const prevState = deepFreeze({ [eg.stream.stream_id]: [{ max_id: 1, name: 'some topic' }] });
14-
15-
const action = eg.action.account_switch;
16-
17-
const expectedState = NULL_OBJECT;
18-
19-
const actualState = topicsReducer(prevState, action);
20-
21-
expect(actualState).toEqual(expectedState);
14+
expect(topicsReducer(prevState, eg.action.account_switch)).toEqual(NULL_OBJECT);
2215
});
2316
});
2417

2518
describe('INIT_TOPICS', () => {
2619
test('adds new topics mapped to stream id', () => {
2720
const prevState = eg.plusReduxState.topics;
28-
29-
const action = deepFreeze({
30-
type: INIT_TOPICS,
31-
streamId: eg.stream.stream_id,
32-
topics: [
33-
{
34-
max_id: 1,
35-
name: 'topic1',
36-
},
37-
{
38-
max_id: 3,
39-
name: 'topic1',
40-
},
41-
],
42-
});
43-
44-
const expectedState = {
21+
expect(
22+
topicsReducer(
23+
prevState,
24+
deepFreeze({
25+
type: INIT_TOPICS,
26+
streamId: eg.stream.stream_id,
27+
topics: [
28+
{ max_id: 1, name: 'topic1' },
29+
{ max_id: 3, name: 'topic1' },
30+
],
31+
}),
32+
),
33+
).toEqual({
4534
[eg.stream.stream_id]: [
46-
{
47-
max_id: 1,
48-
name: 'topic1',
49-
},
50-
{
51-
max_id: 3,
52-
name: 'topic1',
53-
},
35+
{ max_id: 1, name: 'topic1' },
36+
{ max_id: 3, name: 'topic1' },
5437
],
55-
};
56-
57-
const newState = topicsReducer(prevState, action);
58-
59-
expect(newState).toEqual(expectedState);
38+
});
6039
});
6140

6241
test('if topics for stream already exist, replace them', () => {
63-
const prevState = deepFreeze({
42+
const prevState = deepFreeze({ [eg.stream.stream_id]: [{ max_id: 1, name: 'some topic' }] });
43+
expect(
44+
topicsReducer(
45+
prevState,
46+
deepFreeze({
47+
type: INIT_TOPICS,
48+
streamId: eg.stream.stream_id,
49+
topics: [
50+
{ max_id: 2, name: 'topic1' },
51+
{ max_id: 3, name: 'topic1' },
52+
],
53+
}),
54+
),
55+
).toEqual({
6456
[eg.stream.stream_id]: [
65-
{
66-
max_id: 1,
67-
name: 'some topic',
68-
},
57+
{ max_id: 2, name: 'topic1' },
58+
{ max_id: 3, name: 'topic1' },
6959
],
7060
});
71-
72-
const action = deepFreeze({
73-
type: INIT_TOPICS,
74-
streamId: eg.stream.stream_id,
75-
topics: [
76-
{
77-
max_id: 2,
78-
name: 'topic1',
79-
},
80-
{
81-
max_id: 3,
82-
name: 'topic1',
83-
},
84-
],
85-
});
86-
87-
const expectedState = {
88-
[eg.stream.stream_id]: [
89-
{
90-
max_id: 2,
91-
name: 'topic1',
92-
},
93-
{
94-
max_id: 3,
95-
name: 'topic1',
96-
},
97-
],
98-
};
99-
100-
const newState = topicsReducer(prevState, action);
101-
102-
expect(newState).toEqual(expectedState);
10361
});
10462
});
10563

10664
describe('EVENT_NEW_MESSAGE', () => {
10765
test('if message is not in stream do not change state', () => {
10866
const prevState = eg.plusReduxState.topics;
109-
110-
const action = eg.mkActionEventNewMessage(eg.pmMessage());
111-
112-
const actualState = topicsReducer(prevState, action);
113-
114-
expect(actualState).toBe(prevState);
67+
expect(topicsReducer(prevState, eg.mkActionEventNewMessage(eg.pmMessage()))).toBe(prevState);
11568
});
11669

11770
test('if stream message and topic exists update with latest message id', () => {
@@ -120,29 +73,10 @@ describe('topicsReducer', () => {
12073
const oldMessage = eg.streamMessage({ id: 1, stream, subject: topic });
12174
const newMessage = eg.streamMessage({ id: 2, stream, subject: topic });
12275

123-
const prevState = {
124-
[stream.stream_id]: [
125-
{
126-
max_id: oldMessage.id,
127-
name: topic,
128-
},
129-
],
130-
};
131-
132-
const action = eg.mkActionEventNewMessage(newMessage);
133-
134-
const expectedState = {
135-
[stream.stream_id]: [
136-
{
137-
max_id: newMessage.id,
138-
name: topic,
139-
},
140-
],
141-
};
142-
143-
const actualState = topicsReducer(prevState, action);
144-
145-
expect(actualState).toEqual(expectedState);
76+
const prevState = { [stream.stream_id]: [{ max_id: oldMessage.id, name: topic }] };
77+
expect(topicsReducer(prevState, eg.mkActionEventNewMessage(newMessage))).toEqual({
78+
[stream.stream_id]: [{ max_id: newMessage.id, name: topic }],
79+
});
14680
});
14781

14882
test('if stream message and topic does not exist, add it', () => {
@@ -151,21 +85,9 @@ describe('topicsReducer', () => {
15185
const message = eg.streamMessage({ stream, subject: topic });
15286

15387
const prevState = eg.plusReduxState.topics;
154-
155-
const action = eg.mkActionEventNewMessage(message);
156-
157-
const expectedState = {
158-
[stream.stream_id]: [
159-
{
160-
max_id: message.id,
161-
name: topic,
162-
},
163-
],
164-
};
165-
166-
const actualState = topicsReducer(prevState, action);
167-
168-
expect(actualState).toEqual(expectedState);
88+
expect(topicsReducer(prevState, eg.mkActionEventNewMessage(message))).toEqual({
89+
[stream.stream_id]: [{ max_id: message.id, name: topic }],
90+
});
16991
});
17092
});
17193
});

0 commit comments

Comments
 (0)