Skip to content

Commit 9df1c48

Browse files
committed
timeline(tests): ASCII art ✨
1 parent 977a999 commit 9df1c48

File tree

1 file changed

+43
-4
lines changed
  • crates/matrix-sdk-ui/src/timeline/tests

1 file changed

+43
-4
lines changed

crates/matrix-sdk-ui/src/timeline/tests/virt.rs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,41 +97,56 @@ async fn test_update_read_marker() {
9797
let f = &timeline.factory;
9898
timeline.handle_live_event(f.text_msg("A").sender(&own_user)).await;
9999

100+
// Timeline: [A].
101+
// No read marker.
100102
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
101103
let event_id1 = item.as_event().unwrap().event_id().unwrap().to_owned();
102104

105+
// Timeline: [day-divider, A].
103106
let day_divider = assert_next_matches!(stream, VectorDiff::PushFront { value } => value);
104107
assert!(day_divider.is_day_divider());
105108

106-
timeline.controller.handle_fully_read_marker(event_id1.to_owned()).await;
109+
timeline.controller.handle_fully_read_marker(event_id1.clone()).await;
107110

108111
// Nothing should happen, the marker cannot be added at the end.
112+
// Timeline: [A].
113+
// ^-- fully read
114+
assert!(stream.next().now_or_never().is_none());
109115

116+
// Timeline: [day-divider, A, B].
110117
timeline.handle_live_event(f.text_msg("B").sender(&BOB)).await;
111118
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
112119
let event_id2 = item.as_event().unwrap().event_id().unwrap().to_owned();
113120

114121
// Now the read marker appears after the first event.
122+
// Timeline: [day-divider, A, read-marker, B].
123+
// fully read --^
115124
let item = assert_next_matches!(stream, VectorDiff::Insert { index: 2, value } => value);
116125
assert_matches!(item.as_virtual(), Some(VirtualTimelineItem::ReadMarker));
117126

118127
timeline.controller.handle_fully_read_marker(event_id2.clone()).await;
119128

120129
// The read marker is removed but not reinserted, because it cannot be added at
121130
// the end.
131+
// Timeline: [day-divider, A, B].
132+
// ^-- fully read
122133
assert_next_matches!(stream, VectorDiff::Remove { index: 2 });
123134

135+
// Timeline: [day-divider, A, B, C].
136+
// ^-- fully read
124137
timeline.handle_live_event(f.text_msg("C").sender(&BOB)).await;
125138
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
126139
let event_id3 = item.as_event().unwrap().event_id().unwrap().to_owned();
127140

128141
// Now the read marker is reinserted after the second event.
142+
// Timeline: [day-divider, A, B, read-marker, C].
143+
// ^-- fully read
129144
let marker = assert_next_matches!(stream, VectorDiff::Insert { index: 3, value } => value);
130145
assert!(marker.is_read_marker());
131146

132147
// Nothing should happen if the fully read event is set back to an older event
133148
// sent by another user.
134-
timeline.controller.handle_fully_read_marker(event_id1.to_owned()).await;
149+
timeline.controller.handle_fully_read_marker(event_id1).await;
135150
assert!(stream.next().now_or_never().is_none());
136151

137152
// Nothing should happen if the fully read event isn't found.
@@ -143,18 +158,27 @@ async fn test_update_read_marker() {
143158
timeline.controller.handle_fully_read_marker(event_id2).await;
144159
assert!(stream.next().now_or_never().is_none());
145160

161+
// Timeline: [day-divider, A, B, read-marker, C, D].
162+
// ^-- fully read
146163
timeline.handle_live_event(f.text_msg("D").sender(&BOB)).await;
147164
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
148165
let event_id4 = item.as_event().unwrap().event_id().unwrap().to_owned();
149166

150167
timeline.controller.handle_fully_read_marker(event_id3).await;
151168

152169
// The read marker is moved after the third event (sent by another user).
170+
// Timeline: [day-divider, A, B, C, D].
171+
// fully read --^
153172
assert_next_matches!(stream, VectorDiff::Remove { index: 3 });
173+
174+
// Timeline: [day-divider, A, B, C, read-marker, D].
175+
// fully read --^
154176
let marker = assert_next_matches!(stream, VectorDiff::Insert { index: 4, value } => value);
155177
assert!(marker.is_read_marker());
156178

157179
// If the current user sends an event afterwards, the read marker doesn't move.
180+
// Timeline: [day-divider, A, B, C, read-marker, D, E].
181+
// fully read --^
158182
timeline.handle_live_event(f.text_msg("E").sender(&own_user)).await;
159183
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
160184
item.as_event().unwrap();
@@ -163,28 +187,43 @@ async fn test_update_read_marker() {
163187

164188
// If the marker moved forward to another user's event, and there's no other
165189
// event sent from another user, then it will be removed.
190+
// Timeline: [day-divider, A, B, C, D, E].
191+
// fully read --^
166192
timeline.controller.handle_fully_read_marker(event_id4).await;
167193
assert_next_matches!(stream, VectorDiff::Remove { index: 4 });
168194

169195
assert!(stream.next().now_or_never().is_none());
170196

171197
// When a last event is inserted by ourselves, still no read marker.
198+
// Timeline: [day-divider, A, B, C, D, E, F].
199+
// fully read --^
172200
timeline.handle_live_event(f.text_msg("F").sender(&own_user)).await;
173201
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
174202
item.as_event().unwrap();
175203

204+
// Timeline: [day-divider, A, B, C, D, E, F, G].
205+
// fully read --^
176206
timeline.handle_live_event(f.text_msg("G").sender(&own_user)).await;
177207
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
178208
item.as_event().unwrap();
179209

180210
assert!(stream.next().now_or_never().is_none());
181211

182-
// But when it's another user who sent the event, then we get a read marker for
183-
// their message.
212+
// But when it's another user who sent the event, then we get a read marker just
213+
// before their message. It is the first message that's both after the
214+
// fully-read event and not sent by us.
215+
//
216+
// Timeline: [day-divider, A, B, C, D, E, F, G, H].
217+
// fully read --^
184218
timeline.handle_live_event(f.text_msg("H").sender(&BOB)).await;
185219
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
186220
item.as_event().unwrap();
187221

222+
// [our own] v-- sent by Bob
223+
// Timeline: [day-divider, A, B, C, D, E, F, G, read-marker, H].
224+
// fully read --^
188225
let marker = assert_next_matches!(stream, VectorDiff::Insert { index: 8, value } => value);
189226
assert!(marker.is_read_marker());
227+
228+
assert!(stream.next().now_or_never().is_none());
190229
}

0 commit comments

Comments
 (0)