@@ -231,7 +231,7 @@ function transformTemporary(temporary: Linkman): Linkman {
231231}
232232
233233const localStorage = getData ( ) ;
234- const initialState : State = {
234+ export const initialState : State = {
235235 user : null ,
236236 linkmans : { } ,
237237 focus : '' ,
@@ -305,16 +305,10 @@ function reducer(state: State = initialState, action: Action): State {
305305 // @ts -ignore
306306 ...friends . map ( transformFriend ) ,
307307 ] ;
308- linkmans . forEach ( ( linkman ) => {
309- let existMessages = { } ;
310- if ( state . linkmans [ linkman . _id ] ) {
311- existMessages = state . linkmans [ linkman . _id ] . messages ;
312- }
313- linkman . messages = existMessages ;
314- } ) ;
315308
316309 // 如果没登录过, 则将聚焦联系人设置为第一个联系人
317310 let { focus } = state ;
311+ /* istanbul ignore next */
318312 if ( ! state . user && linkmans . length > 0 ) {
319313 focus = linkmans [ 0 ] . _id ;
320314 }
@@ -368,7 +362,10 @@ function reducer(state: State = initialState, action: Action): State {
368362 case ActionTypes . SetFocus : {
369363 const focus = action . payload as string ;
370364 if ( ! state . linkmans [ focus ] ) {
371- console . warn ( `ActionTypes.SetFocus Error: 联系人 ${ focus } 不存在` ) ;
365+ /* istanbul ignore next */
366+ if ( ! __TEST__ ) {
367+ console . warn ( `ActionTypes.SetFocus Error: 联系人 ${ focus } 不存在` ) ;
368+ }
372369 return state ;
373370 }
374371
@@ -429,7 +426,7 @@ function reducer(state: State = initialState, action: Action): State {
429426 ...state ,
430427 linkmans : {
431428 ...state . linkmans ,
432- [ linkman . _id ] : transformedLinkman ,
429+ [ transformedLinkman . _id ] : transformedLinkman ,
433430 } ,
434431 focus,
435432 } ;
@@ -510,7 +507,10 @@ function reducer(state: State = initialState, action: Action): State {
510507 case ActionTypes . DeleteMessage : {
511508 const { linkmanId, messageId } = action . payload as DeleteMessagePayload ;
512509 if ( ! state . linkmans [ linkmanId ] ) {
513- console . warn ( `ActionTypes.DeleteMessage Error: 联系人 ${ linkmanId } 不存在` ) ;
510+ /* istanbul ignore next */
511+ if ( ! __TEST__ ) {
512+ console . warn ( `ActionTypes.DeleteMessage Error: 联系人 ${ linkmanId } 不存在` ) ;
513+ }
514514 return state ;
515515 }
516516
0 commit comments