@@ -80,6 +80,144 @@ describe('Messages-Reducers', () => {
8080 expect ( nextState . latestMessageTimeStamp ) . not . toEqual ( mockData . allMessages [ mockData . allMessages . length - 1 ] . createdAt ) ;
8181 } ) ;
8282
83+ it ( 'should get prev message list considering messageListParams FETCH_PREV_MESSAGES_SUCCESS' , ( ) => {
84+ const MESSAGE_LIST_SIZE = 20 ;
85+ const mockData = generateMockChannel ( ) ;
86+ const nextState = reducers ( {
87+ ...mockData ,
88+ hasMorePrev : true ,
89+ hasMoreNext : true ,
90+ messageListParams : {
91+ prevResultSize : MESSAGE_LIST_SIZE ,
92+ nextResultSize : MESSAGE_LIST_SIZE ,
93+ }
94+ } , {
95+ type : actionTypes . FETCH_PREV_MESSAGES_SUCCESS ,
96+ payload : {
97+ currentGroupChannel : mockData . currentGroupChannel ,
98+ messages : new Array ( MESSAGE_LIST_SIZE + 1 ) . fill ( { } ) ,
99+ // MESSAGE_LIST_SIZE + 1: because server gives the response including a current message
100+ }
101+ } ) ;
102+ expect ( nextState . hasMorePrev ) . toEqual ( true ) ;
103+ expect ( nextState . hasMoreNext ) . toEqual ( true ) ;
104+ } ) ;
105+
106+ it ( 'should verify there is no more messages FETCH_PREV_MESSAGES_SUCCESS' , ( ) => {
107+ // request size > response size
108+ const MESSAGE_LIST_SIZE = 20 ;
109+ const mockData = generateMockChannel ( ) ;
110+ const nextState = reducers ( {
111+ ...mockData ,
112+ hasMorePrev : true ,
113+ hasMoreNext : true ,
114+ messageListParams : {
115+ prevResultSize : 30 ,
116+ nextResultSize : 30 ,
117+ }
118+ } , {
119+ type : actionTypes . FETCH_PREV_MESSAGES_SUCCESS ,
120+ payload : {
121+ currentGroupChannel : mockData . currentGroupChannel ,
122+ messages : new Array ( MESSAGE_LIST_SIZE + 1 ) . fill ( { } ) ,
123+ }
124+ } ) ;
125+ expect ( nextState . hasMorePrev ) . toEqual ( false ) ;
126+ expect ( nextState . hasMoreNext ) . toEqual ( true ) ;
127+ } ) ;
128+
129+ it ( 'should validate unexpected additional messages are fetched FETCH_PREV_MESSAGES_SUCCESS' , ( ) => {
130+ // request size < response size
131+ const MESSAGE_LIST_SIZE = 20 ;
132+ const mockData = generateMockChannel ( ) ;
133+ const nextState = reducers ( {
134+ ...mockData ,
135+ hasMorePrev : true ,
136+ hasMoreNext : true ,
137+ messageListParams : {
138+ prevResultSize : 10 ,
139+ nextResultSize : 10 ,
140+ }
141+ } , {
142+ type : actionTypes . FETCH_PREV_MESSAGES_SUCCESS ,
143+ payload : {
144+ currentGroupChannel : mockData . currentGroupChannel ,
145+ messages : new Array ( MESSAGE_LIST_SIZE + 1 ) . fill ( { } ) ,
146+ }
147+ } ) ;
148+ expect ( nextState . hasMorePrev ) . toEqual ( false ) ;
149+ expect ( nextState . hasMoreNext ) . toEqual ( true ) ;
150+ } ) ;
151+
152+ it ( 'should get next message list considering messageListParams FETCH_NEXT_MESSAGES_SUCCESS' , ( ) => {
153+ const MESSAGE_LIST_SIZE = 20 ;
154+ const mockData = generateMockChannel ( ) ;
155+ const nextState = reducers ( {
156+ ...mockData ,
157+ hasMorePrev : true ,
158+ hasMoreNext : true ,
159+ messageListParams : {
160+ prevResultSize : MESSAGE_LIST_SIZE ,
161+ nextResultSize : MESSAGE_LIST_SIZE ,
162+ }
163+ } , {
164+ type : actionTypes . FETCH_NEXT_MESSAGES_SUCCESS ,
165+ payload : {
166+ currentGroupChannel : mockData . currentGroupChannel ,
167+ messages : new Array ( MESSAGE_LIST_SIZE + 1 ) . fill ( { } ) ,
168+ // MESSAGE_LIST_SIZE + 1: because server gives the response including a current message
169+ }
170+ } ) ;
171+ expect ( nextState . hasMorePrev ) . toEqual ( true ) ;
172+ expect ( nextState . hasMoreNext ) . toEqual ( true ) ;
173+ } ) ;
174+
175+ it ( 'should verify there is no more messages FETCH_NEXT_MESSAGES_SUCCESS' , ( ) => {
176+ // request size > response size
177+ const MESSAGE_LIST_SIZE = 20 ;
178+ const mockData = generateMockChannel ( ) ;
179+ const nextState = reducers ( {
180+ ...mockData ,
181+ hasMorePrev : true ,
182+ hasMoreNext : true ,
183+ messageListParams : {
184+ prevResultSize : 30 ,
185+ nextResultSize : 30 ,
186+ }
187+ } , {
188+ type : actionTypes . FETCH_NEXT_MESSAGES_SUCCESS ,
189+ payload : {
190+ currentGroupChannel : mockData . currentGroupChannel ,
191+ messages : new Array ( MESSAGE_LIST_SIZE + 1 ) . fill ( { } ) ,
192+ }
193+ } ) ;
194+ expect ( nextState . hasMorePrev ) . toEqual ( true ) ;
195+ expect ( nextState . hasMoreNext ) . toEqual ( false ) ;
196+ } ) ;
197+
198+ it ( 'should validate unexpected additional messages are fetched FETCH_NEXT_MESSAGES_SUCCESS' , ( ) => {
199+ // request size < response size
200+ const MESSAGE_LIST_SIZE = 20 ;
201+ const mockData = generateMockChannel ( ) ;
202+ const nextState = reducers ( {
203+ ...mockData ,
204+ hasMorePrev : true ,
205+ hasMoreNext : true ,
206+ messageListParams : {
207+ prevResultSize : 10 ,
208+ nextResultSize : 10 ,
209+ }
210+ } , {
211+ type : actionTypes . FETCH_NEXT_MESSAGES_SUCCESS ,
212+ payload : {
213+ currentGroupChannel : mockData . currentGroupChannel ,
214+ messages : new Array ( MESSAGE_LIST_SIZE + 1 ) . fill ( { } ) ,
215+ }
216+ } ) ;
217+ expect ( nextState . hasMorePrev ) . toEqual ( true ) ;
218+ expect ( nextState . hasMoreNext ) . toEqual ( false ) ;
219+ } ) ;
220+
83221 it ( 'should set pending message on SEND_MESSAGEGE_START' , ( ) => {
84222 const mockData = generateMockChannel ( ) ;
85223 const nextState = reducers ( mockData , {
0 commit comments