@@ -11,107 +11,60 @@ describe('topicsReducer', () => {
11
11
describe ( 'ACCOUNT_SWITCH' , ( ) => {
12
12
test ( 'resets state to initial state' , ( ) => {
13
13
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 ) ;
22
15
} ) ;
23
16
} ) ;
24
17
25
18
describe ( 'INIT_TOPICS' , ( ) => {
26
19
test ( 'adds new topics mapped to stream id' , ( ) => {
27
20
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 ( {
45
34
[ 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' } ,
54
37
] ,
55
- } ;
56
-
57
- const newState = topicsReducer ( prevState , action ) ;
58
-
59
- expect ( newState ) . toEqual ( expectedState ) ;
38
+ } ) ;
60
39
} ) ;
61
40
62
41
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 ( {
64
56
[ 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' } ,
69
59
] ,
70
60
} ) ;
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 ) ;
103
61
} ) ;
104
62
} ) ;
105
63
106
64
describe ( 'EVENT_NEW_MESSAGE' , ( ) => {
107
65
test ( 'if message is not in stream do not change state' , ( ) => {
108
66
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 ) ;
115
68
} ) ;
116
69
117
70
test ( 'if stream message and topic exists update with latest message id' , ( ) => {
@@ -120,29 +73,10 @@ describe('topicsReducer', () => {
120
73
const oldMessage = eg . streamMessage ( { id : 1 , stream, subject : topic } ) ;
121
74
const newMessage = eg . streamMessage ( { id : 2 , stream, subject : topic } ) ;
122
75
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
+ } ) ;
146
80
} ) ;
147
81
148
82
test ( 'if stream message and topic does not exist, add it' , ( ) => {
@@ -151,21 +85,9 @@ describe('topicsReducer', () => {
151
85
const message = eg . streamMessage ( { stream, subject : topic } ) ;
152
86
153
87
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
+ } ) ;
169
91
} ) ;
170
92
} ) ;
171
93
} ) ;
0 commit comments