|
1 | 1 | /* @flow strict-local */ |
2 | 2 | import Immutable from 'immutable'; |
3 | 3 |
|
4 | | -import { ACCOUNT_SWITCH, EVENT_UPDATE_MESSAGE_FLAGS } from '../../actionConstants'; |
| 4 | +import { |
| 5 | + ACCOUNT_SWITCH, |
| 6 | + EVENT_UPDATE_MESSAGE_FLAGS, |
| 7 | + EVENT_UPDATE_MESSAGE, |
| 8 | +} from '../../actionConstants'; |
5 | 9 | import { reducer } from '../unreadModel'; |
6 | 10 | import { type UnreadState } from '../unreadModelTypes'; |
7 | 11 | import * as eg from '../../__tests__/lib/exampleData'; |
@@ -63,6 +67,95 @@ describe('stream substate', () => { |
63 | 67 | }); |
64 | 68 | }); |
65 | 69 |
|
| 70 | + describe('EVENT_UPDATE_MESSAGE', () => { |
| 71 | + const mkAction = args => { |
| 72 | + const { |
| 73 | + message_id, |
| 74 | + message_ids = [message_id], |
| 75 | + stream_id = 123, |
| 76 | + new_stream_id = undefined, |
| 77 | + orig_subject = 'foo', |
| 78 | + subject = 'foo', |
| 79 | + } = args; |
| 80 | + return { |
| 81 | + id: 1, |
| 82 | + type: EVENT_UPDATE_MESSAGE, |
| 83 | + edit_timestamp: 10000, |
| 84 | + message_id, |
| 85 | + message_ids, |
| 86 | + stream_id, |
| 87 | + new_stream_id, |
| 88 | + orig_content: '', |
| 89 | + orig_subject, |
| 90 | + orig_rendered_content: '', |
| 91 | + prev_rendered_content_version: 0, |
| 92 | + rendered_content: '', |
| 93 | + subject_links: [], |
| 94 | + subject, |
| 95 | + user_id: eg.selfUser.user_id, |
| 96 | + }; |
| 97 | + }; |
| 98 | + |
| 99 | + const baseState = (() => { |
| 100 | + const streamAction = args => eg.mkActionEventNewMessage(eg.streamMessage(args)); |
| 101 | + const r = (state, action) => reducer(state, action, eg.plusReduxState); |
| 102 | + let state = initialState; |
| 103 | + state = r(state, streamAction({ stream_id: 123, subject: 'foo', id: 1 })); |
| 104 | + state = r(state, streamAction({ stream_id: 123, subject: 'foo', id: 2 })); |
| 105 | + state = r(state, streamAction({ stream_id: 123, subject: 'foo', id: 3 })); |
| 106 | + state = r(state, streamAction({ stream_id: 123, subject: 'foo', id: 4 })); |
| 107 | + state = r(state, streamAction({ stream_id: 123, subject: 'foo', id: 5 })); |
| 108 | + state = r(state, streamAction({ stream_id: 456, subject: 'zzz', id: 6 })); |
| 109 | + state = r(state, streamAction({ stream_id: 456, subject: 'zzz', id: 7 })); |
| 110 | + return state; |
| 111 | + })(); |
| 112 | + |
| 113 | + test('if topic not updated, return original state', () => { |
| 114 | + const state = reducer(baseState, mkAction({ message_id: 5 }), eg.plusReduxState); |
| 115 | + expect(state.streams).toBe(baseState.streams); |
| 116 | + }); |
| 117 | + |
| 118 | + test('if topic updated, but no unreads, return original state', () => { |
| 119 | + const state = reducer(baseState, mkAction({ message_id: 100 }), eg.plusReduxState); |
| 120 | + expect(state.streams).toBe(baseState.streams); |
| 121 | + }); |
| 122 | + |
| 123 | + test('if topic updated, move unreads', () => { |
| 124 | + const state = reducer( |
| 125 | + baseState, |
| 126 | + mkAction({ |
| 127 | + message_id: 3, |
| 128 | + message_ids: [3, 4, 5], |
| 129 | + orig_subject: 'foo', |
| 130 | + subject: 'bar', |
| 131 | + }), |
| 132 | + eg.plusReduxState, |
| 133 | + ); |
| 134 | + // prettier-ignore |
| 135 | + expect(summary(state)).toEqual(Immutable.Map([ |
| 136 | + [123, Immutable.Map([['foo', [1, 2]], ['bar', [3, 4, 5]]])], |
| 137 | + [456, Immutable.Map([['zzz', [6, 7]]])], |
| 138 | + ])); |
| 139 | + }); |
| 140 | + |
| 141 | + test('if stream updated, move unreads', () => { |
| 142 | + const state = reducer( |
| 143 | + baseState, |
| 144 | + mkAction({ |
| 145 | + message_id: 3, |
| 146 | + message_ids: [3, 4, 5], |
| 147 | + new_stream_id: 456, |
| 148 | + }), |
| 149 | + eg.plusReduxState, |
| 150 | + ); |
| 151 | + // prettier-ignore |
| 152 | + expect(summary(state)).toEqual(Immutable.Map([ |
| 153 | + [123, Immutable.Map([['foo', [1, 2]]])], |
| 154 | + [456, Immutable.Map([['zzz', [6, 7]], ['foo', [3, 4, 5]]])], |
| 155 | + ])); |
| 156 | + }); |
| 157 | + }); |
| 158 | + |
66 | 159 | describe('EVENT_NEW_MESSAGE', () => { |
67 | 160 | const action = eg.mkActionEventNewMessage; |
68 | 161 |
|
|
0 commit comments