mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-06 06:53:32 -04:00
test(sdk): Remove TestTimeline::with_initial_events
It's not general enough for further inital event tests.
This commit is contained in:
committed by
Jonas Platte
parent
188aaecde3
commit
88376e85cd
@@ -1,6 +1,7 @@
|
||||
use assert_matches::assert_matches;
|
||||
use futures_signals::signal_vec::VecDiff;
|
||||
use futures_util::StreamExt;
|
||||
use matrix_sdk_base::deserialized_responses::SyncTimelineEvent;
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::{
|
||||
assign,
|
||||
@@ -18,7 +19,7 @@ use ruma::{
|
||||
FullStateEventContent,
|
||||
},
|
||||
};
|
||||
use serde_json::json;
|
||||
use serde_json::{json, Value as JsonValue};
|
||||
|
||||
use super::{TestTimeline, ALICE, BOB};
|
||||
use crate::room::timeline::{
|
||||
@@ -26,13 +27,26 @@ use crate::room::timeline::{
|
||||
VirtualTimelineItem,
|
||||
};
|
||||
|
||||
fn sync_timeline_event(event: JsonValue) -> SyncTimelineEvent {
|
||||
let event = serde_json::from_value(event).unwrap();
|
||||
SyncTimelineEvent { event, encryption_info: None }
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn initial_events() {
|
||||
let timeline = TestTimeline::with_initial_events([
|
||||
(*ALICE, RoomMessageEventContent::text_plain("A").into()),
|
||||
(*BOB, RoomMessageEventContent::text_plain("B").into()),
|
||||
])
|
||||
.await;
|
||||
let mut timeline = TestTimeline::new();
|
||||
timeline
|
||||
.inner
|
||||
.add_initial_events(vec![
|
||||
sync_timeline_event(
|
||||
timeline.make_message_event(*ALICE, RoomMessageEventContent::text_plain("A")),
|
||||
),
|
||||
sync_timeline_event(
|
||||
timeline.make_message_event(*BOB, RoomMessageEventContent::text_plain("B")),
|
||||
),
|
||||
])
|
||||
.await;
|
||||
|
||||
let mut stream = timeline.stream();
|
||||
|
||||
let items = assert_matches!(stream.next().await, Some(VecDiff::Replace { values }) => values);
|
||||
|
||||
@@ -22,7 +22,7 @@ use std::sync::{
|
||||
use async_trait::async_trait;
|
||||
use futures_core::Stream;
|
||||
use futures_signals::signal_vec::{SignalVecExt, VecDiff};
|
||||
use matrix_sdk_base::deserialized_responses::{SyncTimelineEvent, TimelineEvent};
|
||||
use matrix_sdk_base::deserialized_responses::TimelineEvent;
|
||||
use once_cell::sync::Lazy;
|
||||
use ruma::{
|
||||
events::{
|
||||
@@ -57,29 +57,6 @@ impl TestTimeline {
|
||||
Self { inner: TimelineInner::new(TestProfileProvider), next_ts: AtomicU64::new(0) }
|
||||
}
|
||||
|
||||
async fn with_initial_events<'a>(
|
||||
events: impl IntoIterator<Item = (&'a UserId, AnyMessageLikeEventContent)>,
|
||||
) -> Self {
|
||||
let mut this =
|
||||
Self { inner: TimelineInner::new(TestProfileProvider), next_ts: AtomicU64::new(0) };
|
||||
|
||||
this.inner
|
||||
.add_initial_events(
|
||||
events
|
||||
.into_iter()
|
||||
.map(|(sender, content)| {
|
||||
let event =
|
||||
serde_json::from_value(this.make_message_event(sender, content))
|
||||
.unwrap();
|
||||
SyncTimelineEvent { event, encryption_info: None }
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
.await;
|
||||
|
||||
this
|
||||
}
|
||||
|
||||
fn stream(&self) -> impl Stream<Item = VecDiff<Arc<TimelineItem>>> {
|
||||
self.inner.items_signal().to_stream()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user