@@ -92,6 +92,90 @@ describe('message reducer', () => {
9292} ) ;
9393} ) ;
9494
95+ it ( 'adds date markers when prepending messages' , ( ) => {
96+ let state = {
97+ srv :{
98+ '#chan1' :[ { id :0 , date :new Date ( 1999 , 0 , 1 ) } ]
99+ }
100+ } ;
101+
102+ state = reducer ( state , {
103+ type :actions . ADD_MESSAGES ,
104+ server :'srv' ,
105+ tab :'#chan1' ,
106+ prepend :true ,
107+ messages :[
108+ { id :1 , date :new Date ( 1990 , 0 , 2 ) } ,
109+ { id :2 , date :new Date ( 1990 , 0 , 3 ) }
110+ ]
111+ } ) ;
112+
113+ expect ( state ) . toMatchObject ( {
114+ srv :{
115+ '#chan1' :[
116+ { id :1 } ,
117+ { type :'date' } ,
118+ { id :2 } ,
119+ { type :'date' } ,
120+ { id :0 }
121+ ]
122+ }
123+ } ) ;
124+ } ) ;
125+
126+ it ( 'adds a date marker when adding a message' , ( ) => {
127+ let state = {
128+ srv :{
129+ '#chan1' :[ { id :0 , date :new Date ( 1999 , 0 , 1 ) } ]
130+ }
131+ } ;
132+
133+ state = reducer ( state , {
134+ type :actions . ADD_MESSAGE ,
135+ server :'srv' ,
136+ tab :'#chan1' ,
137+ message :{ id :1 , date :new Date ( 1990 , 0 , 2 ) }
138+ } ) ;
139+
140+ expect ( state ) . toMatchObject ( {
141+ srv :{
142+ '#chan1' :[ { id :0 } , { type :'date' } , { id :1 } ]
143+ }
144+ } ) ;
145+ } ) ;
146+
147+ it ( 'adds date markers when adding messages' , ( ) => {
148+ let state = {
149+ srv :{
150+ '#chan1' :[ { id :0 , date :new Date ( 1999 , 0 , 1 ) } ]
151+ }
152+ } ;
153+
154+ state = reducer ( state , {
155+ type :actions . ADD_MESSAGES ,
156+ server :'srv' ,
157+ tab :'#chan1' ,
158+ messages :[
159+ { id :1 , date :new Date ( 1990 , 0 , 2 ) } ,
160+ { id :2 , date :new Date ( 1990 , 0 , 3 ) } ,
161+ { id :3 , date :new Date ( 1990 , 0 , 3 ) }
162+ ]
163+ } ) ;
164+
165+ expect ( state ) . toMatchObject ( {
166+ srv :{
167+ '#chan1' :[
168+ { id :0 } ,
169+ { type :'date' } ,
170+ { id :1 } ,
171+ { type :'date' } ,
172+ { id :2 } ,
173+ { id :3 }
174+ ]
175+ }
176+ } ) ;
177+ } ) ;
178+
95179it ( 'adds messages to the correct tabs when broadcasting' , ( ) => {
96180let state = {
97181app :appReducer ( undefined , { type :'' } )