Skip to content

Commit 5c35392

Browse files
committed
timeline: add test for poll edit in relations overriding pending poll edit
1 parent dc4cc02 commit 5c35392

File tree

1 file changed

+79
-1
lines changed
  • crates/matrix-sdk-ui/src/timeline/tests

1 file changed

+79
-1
lines changed

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

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ async fn test_edit_updates_encryption_info() {
217217
}
218218

219219
#[async_test]
220-
async fn test_relations_edit_overrides_pending_edit() {
220+
async fn test_relations_edit_overrides_pending_edit_msg() {
221221
let timeline = TestTimeline::new();
222222
let mut stream = timeline.subscribe().await;
223223

@@ -278,3 +278,81 @@ async fn test_relations_edit_overrides_pending_edit() {
278278

279279
assert_pending!(stream);
280280
}
281+
282+
#[async_test]
283+
async fn test_relations_edit_overrides_pending_edit_poll() {
284+
let timeline = TestTimeline::new();
285+
let mut stream = timeline.subscribe().await;
286+
287+
let f = &timeline.factory;
288+
289+
let original_event_id = event_id!("$original");
290+
let edit1_event_id = event_id!("$edit1");
291+
let edit2_event_id = event_id!("$edit2");
292+
293+
// Pending edit is stashed, nothing comes from the stream.
294+
timeline
295+
.handle_live_event(
296+
f.poll_edit(
297+
original_event_id,
298+
"Can the fake slim shady please stand up?",
299+
vec!["Excuse me?"],
300+
)
301+
.sender(*ALICE)
302+
.event_id(edit1_event_id),
303+
)
304+
.await;
305+
assert_pending!(stream);
306+
307+
// Now we receive the original event, with a bundled relations group.
308+
let mut relations = BundledMessageLikeRelations::new();
309+
relations.replace = Some(Box::new(
310+
f.poll_edit(
311+
original_event_id,
312+
"Can the real slim shady please stand up?",
313+
vec!["Excuse me?", "Please stand up 🎵", "Please stand up 🎶"],
314+
)
315+
.sender(*ALICE)
316+
.event_id(edit2_event_id)
317+
.into(),
318+
));
319+
320+
let ev = f
321+
.poll_start(
322+
"Can the fake slim shady please stand down?\nExcuse me?",
323+
"Can the fake slim shady please stand down?",
324+
vec!["Excuse me?"],
325+
)
326+
.sender(*ALICE)
327+
.event_id(original_event_id)
328+
.bundled_relations(relations);
329+
330+
timeline.handle_live_event(ev).await;
331+
332+
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
333+
334+
// We receive the latest edit, not the pending one.
335+
let event = item.as_event().unwrap();
336+
assert_eq!(
337+
event
338+
.latest_edit_json()
339+
.expect("we should have an edit json")
340+
.deserialize()
341+
.unwrap()
342+
.event_id(),
343+
edit2_event_id
344+
);
345+
346+
let poll = event.content().as_poll().unwrap();
347+
assert!(poll.has_been_edited);
348+
assert_eq!(
349+
poll.start_event_content.poll_start.question.text,
350+
"Can the real slim shady please stand up?"
351+
);
352+
assert_eq!(poll.start_event_content.poll_start.answers.len(), 3);
353+
354+
let day_divider = assert_next_matches!(stream, VectorDiff::PushFront { value } => value);
355+
assert!(day_divider.is_day_divider());
356+
357+
assert_pending!(stream);
358+
}

0 commit comments

Comments
 (0)