ui: Use stream_assert for timeline unit tests
This commit is contained in:
parent
0b5a341633
commit
329a7b63f3
|
@ -14,7 +14,6 @@
|
|||
|
||||
use assert_matches::assert_matches;
|
||||
use eyeball_im::VectorDiff;
|
||||
use futures_util::StreamExt;
|
||||
use imbl::vector;
|
||||
use matrix_sdk::deserialized_responses::SyncTimelineEvent;
|
||||
use matrix_sdk_test::async_test;
|
||||
|
@ -32,6 +31,7 @@ use ruma::{
|
|||
},
|
||||
};
|
||||
use serde_json::{json, Value as JsonValue};
|
||||
use stream_assert::assert_next_matches;
|
||||
|
||||
use super::{TestTimeline, ALICE, BOB};
|
||||
use crate::timeline::{
|
||||
|
@ -61,11 +61,11 @@ async fn initial_events() {
|
|||
])
|
||||
.await;
|
||||
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
assert_matches!(&*item, TimelineItem::Virtual(VirtualTimelineItem::DayDivider(_)));
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
assert_eq!(item.as_event().unwrap().sender(), *ALICE);
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
assert_eq!(item.as_event().unwrap().sender(), *BOB);
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ async fn sticker() {
|
|||
}))
|
||||
.await;
|
||||
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
assert_matches!(item.content(), TimelineItemContent::Sticker(_));
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ async fn room_member() {
|
|||
)
|
||||
.await;
|
||||
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let membership =
|
||||
assert_matches!(item.content(), TimelineItemContent::MembershipChange(ev) => ev);
|
||||
assert_matches!(membership.content(), FullStateEventContent::Original { .. });
|
||||
|
@ -130,7 +130,7 @@ async fn room_member() {
|
|||
)
|
||||
.await;
|
||||
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let membership =
|
||||
assert_matches!(item.content(), TimelineItemContent::MembershipChange(ev) => ev);
|
||||
assert_matches!(membership.content(), FullStateEventContent::Original { .. });
|
||||
|
@ -147,7 +147,7 @@ async fn room_member() {
|
|||
)
|
||||
.await;
|
||||
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let profile = assert_matches!(item.content(), TimelineItemContent::ProfileChange(ev) => ev);
|
||||
assert_matches!(profile.displayname_change(), Some(_));
|
||||
assert_matches!(profile.avatar_url_change(), None);
|
||||
|
@ -160,7 +160,7 @@ async fn room_member() {
|
|||
)
|
||||
.await;
|
||||
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let membership =
|
||||
assert_matches!(item.content(), TimelineItemContent::MembershipChange(ev) => ev);
|
||||
assert_matches!(membership.content(), FullStateEventContent::Redacted(_));
|
||||
|
@ -180,10 +180,9 @@ async fn other_state() {
|
|||
)
|
||||
.await;
|
||||
|
||||
let _day_divider =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let _day_divider = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let ev = assert_matches!(item.as_event().unwrap().content(), TimelineItemContent::OtherState(ev) => ev);
|
||||
let full_content =
|
||||
assert_matches!(ev.content(), AnyOtherFullStateEventContent::RoomName(c) => c);
|
||||
|
@ -193,7 +192,7 @@ async fn other_state() {
|
|||
|
||||
timeline.handle_live_redacted_state_event(&ALICE, RedactedRoomTopicEventContent::new()).await;
|
||||
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let ev = assert_matches!(item.as_event().unwrap().content(), TimelineItemContent::OtherState(ev) => ev);
|
||||
let full_content =
|
||||
assert_matches!(ev.content(), AnyOtherFullStateEventContent::RoomTopic(c) => c);
|
||||
|
@ -258,10 +257,9 @@ async fn sanitized() {
|
|||
)
|
||||
.await;
|
||||
|
||||
let _day_divider =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let _day_divider = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let event = item.as_event().unwrap();
|
||||
let message = assert_matches!(event.content(), TimelineItemContent::Message(msg) => msg);
|
||||
let text = assert_matches!(message.msgtype(), MessageType::Text(text) => text);
|
||||
|
@ -287,10 +285,9 @@ async fn reply() {
|
|||
)
|
||||
.await;
|
||||
|
||||
let _day_divider =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let _day_divider = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let first_event = item.as_event().unwrap();
|
||||
let first_event_id = first_event.event_id().unwrap();
|
||||
let first_event_sender = *ALICE;
|
||||
|
@ -318,7 +315,7 @@ async fn reply() {
|
|||
|
||||
timeline.handle_live_message_event(&BOB, reply).await;
|
||||
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let message = assert_matches!(item.as_event().unwrap().content(), TimelineItemContent::Message(msg) => msg);
|
||||
|
||||
let text = assert_matches!(message.msgtype(), MessageType::Text(text) => text);
|
||||
|
|
|
@ -16,7 +16,6 @@ use std::{io, sync::Arc};
|
|||
|
||||
use assert_matches::assert_matches;
|
||||
use eyeball_im::VectorDiff;
|
||||
use futures_util::StreamExt;
|
||||
use matrix_sdk::Error;
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::{
|
||||
|
@ -24,6 +23,7 @@ use ruma::{
|
|||
events::{room::message::RoomMessageEventContent, AnyMessageLikeEventContent},
|
||||
};
|
||||
use serde_json::json;
|
||||
use stream_assert::assert_next_matches;
|
||||
|
||||
use super::{TestTimeline, ALICE, BOB};
|
||||
use crate::timeline::event_item::EventSendState;
|
||||
|
@ -40,13 +40,11 @@ async fn remote_echo_full_trip() {
|
|||
))
|
||||
.await;
|
||||
|
||||
let _day_divider =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let _day_divider = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
|
||||
// Scenario 1: The local event has not been sent yet to the server.
|
||||
{
|
||||
let item =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let event = item.as_event().unwrap();
|
||||
assert_matches!(event.send_state(), Some(EventSendState::NotSentYet));
|
||||
}
|
||||
|
@ -63,10 +61,7 @@ async fn remote_echo_full_trip() {
|
|||
)
|
||||
.await;
|
||||
|
||||
let item = assert_matches!(
|
||||
stream.next().await,
|
||||
Some(VectorDiff::Set { value, index: 1 }) => value
|
||||
);
|
||||
let item = assert_next_matches!(stream, VectorDiff::Set { value, index: 1 } => value);
|
||||
let event = item.as_event().unwrap();
|
||||
assert_matches!(event.send_state(), Some(EventSendState::SendingFailed { .. }));
|
||||
}
|
||||
|
@ -83,10 +78,7 @@ async fn remote_echo_full_trip() {
|
|||
)
|
||||
.await;
|
||||
|
||||
let item = assert_matches!(
|
||||
stream.next().await,
|
||||
Some(VectorDiff::Set { value, index: 1 }) => value
|
||||
);
|
||||
let item = assert_next_matches!(stream, VectorDiff::Set { value, index: 1 } => value);
|
||||
let event_item = item.as_event().unwrap();
|
||||
assert_matches!(event_item.send_state(), Some(EventSendState::Sent { .. }));
|
||||
|
||||
|
@ -109,8 +101,7 @@ async fn remote_echo_full_trip() {
|
|||
.await;
|
||||
|
||||
// The local echo is replaced with the remote echo
|
||||
let item =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::Set { index: 1, value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::Set { index: 1, value } => value);
|
||||
assert!(!item.as_event().unwrap().is_local_echo());
|
||||
}
|
||||
|
||||
|
@ -126,19 +117,16 @@ async fn remote_echo_new_position() {
|
|||
))
|
||||
.await;
|
||||
|
||||
let _day_divider =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let _day_divider = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let txn_id_from_event = item.as_event().unwrap();
|
||||
assert_eq!(txn_id, txn_id_from_event.transaction_id().unwrap());
|
||||
|
||||
// … and another event that comes back before the remote echo
|
||||
timeline.handle_live_message_event(&BOB, RoomMessageEventContent::text_plain("test")).await;
|
||||
let _day_divider =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let _bob_message =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let _day_divider = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let _bob_message = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
|
||||
// When the remote echo comes in…
|
||||
timeline
|
||||
|
@ -158,12 +146,12 @@ async fn remote_echo_new_position() {
|
|||
.await;
|
||||
|
||||
// … the local echo should be removed
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::Remove { index: 1 }));
|
||||
assert_next_matches!(stream, VectorDiff::Remove { index: 1 });
|
||||
// … along with its day divider
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::Remove { index: 0 }));
|
||||
assert_next_matches!(stream, VectorDiff::Remove { index: 0 });
|
||||
|
||||
// … and the remote echo added (no new day divider because both bob's and
|
||||
// alice's message are from the same day according to server timestamps)
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
assert!(!item.as_event().unwrap().is_local_echo());
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
use assert_matches::assert_matches;
|
||||
use eyeball_im::VectorDiff;
|
||||
use futures_util::StreamExt;
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::{
|
||||
assign,
|
||||
|
@ -28,6 +27,7 @@ use ruma::{
|
|||
server_name, EventId,
|
||||
};
|
||||
use serde_json::json;
|
||||
use stream_assert::assert_next_matches;
|
||||
|
||||
use super::{TestTimeline, ALICE};
|
||||
use crate::timeline::TimelineItemContent;
|
||||
|
@ -40,9 +40,8 @@ async fn live_redacted() {
|
|||
timeline
|
||||
.handle_live_redacted_message_event(*ALICE, RedactedRoomMessageEventContent::new())
|
||||
.await;
|
||||
let _day_divider =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let _day_divider = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
|
||||
let redacted_event_id = item.as_event().unwrap().event_id().unwrap();
|
||||
|
||||
|
@ -72,10 +71,9 @@ async fn live_sanitized() {
|
|||
)
|
||||
.await;
|
||||
|
||||
let _day_divider =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let _day_divider = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let first_event = item.as_event().unwrap();
|
||||
let message = assert_matches!(first_event.content(), TimelineItemContent::Message(msg) => msg);
|
||||
let text = assert_matches!(message.msgtype(), MessageType::Text(text) => text);
|
||||
|
@ -100,8 +98,7 @@ async fn live_sanitized() {
|
|||
);
|
||||
timeline.handle_live_message_event(&ALICE, edit).await;
|
||||
|
||||
let item =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::Set { index: 1, value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::Set { index: 1, value } => value);
|
||||
let first_event = item.as_event().unwrap();
|
||||
let message = assert_matches!(first_event.content(), TimelineItemContent::Message(msg) => msg);
|
||||
let text = assert_matches!(message.msgtype(), MessageType::Text(text) => text);
|
||||
|
@ -155,9 +152,8 @@ async fn aggregated_sanitized() {
|
|||
});
|
||||
timeline.handle_live_event(Raw::new(&ev).unwrap().cast()).await;
|
||||
|
||||
let _day_divider =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let _day_divider = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let first_event = item.as_event().unwrap();
|
||||
let message = assert_matches!(first_event.content(), TimelineItemContent::Message(msg) => msg);
|
||||
let text = assert_matches!(message.msgtype(), MessageType::Text(text) => text);
|
||||
|
|
|
@ -18,7 +18,6 @@ use std::{collections::BTreeSet, io::Cursor, iter};
|
|||
|
||||
use assert_matches::assert_matches;
|
||||
use eyeball_im::VectorDiff;
|
||||
use futures_util::StreamExt;
|
||||
use matrix_sdk::crypto::{decrypt_room_key_export, OlmMachine};
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::{
|
||||
|
@ -29,6 +28,7 @@ use ruma::{
|
|||
},
|
||||
room_id, user_id,
|
||||
};
|
||||
use stream_assert::assert_next_matches;
|
||||
|
||||
use super::{TestTimeline, BOB};
|
||||
use crate::timeline::{EncryptedMessage, TimelineItemContent};
|
||||
|
@ -80,9 +80,8 @@ async fn retry_message_decryption() {
|
|||
|
||||
assert_eq!(timeline.inner.items().await.len(), 2);
|
||||
|
||||
let _day_divider =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let _day_divider = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let event = item.as_event().unwrap();
|
||||
let session_id = assert_matches!(
|
||||
event.content(),
|
||||
|
@ -109,8 +108,7 @@ async fn retry_message_decryption() {
|
|||
|
||||
assert_eq!(timeline.inner.items().await.len(), 2);
|
||||
|
||||
let item =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::Set { index: 1, value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::Set { index: 1, value } => value);
|
||||
let event = item.as_event().unwrap();
|
||||
assert_matches!(event.encryption_info(), Some(_));
|
||||
let text = assert_matches!(event.content(), TimelineItemContent::Message(msg) => msg.body());
|
||||
|
@ -372,9 +370,8 @@ async fn retry_message_decryption_highlighted() {
|
|||
|
||||
assert_eq!(timeline.inner.items().await.len(), 2);
|
||||
|
||||
let _day_divider =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let _day_divider = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let event = item.as_event().unwrap();
|
||||
let session_id = assert_matches!(
|
||||
event.content(),
|
||||
|
@ -401,8 +398,7 @@ async fn retry_message_decryption_highlighted() {
|
|||
|
||||
assert_eq!(timeline.inner.items().await.len(), 2);
|
||||
|
||||
let item =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::Set { index: 1, value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::Set { index: 1, value } => value);
|
||||
let event = item.as_event().unwrap();
|
||||
assert_matches!(event.encryption_info(), Some(_));
|
||||
let text = assert_matches!(event.content(), TimelineItemContent::Message(msg) => msg.body());
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
use assert_matches::assert_matches;
|
||||
use eyeball_im::VectorDiff;
|
||||
use futures_util::StreamExt;
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::{
|
||||
assign,
|
||||
|
@ -26,6 +25,7 @@ use ruma::{
|
|||
uint, MilliSecondsSinceUnixEpoch,
|
||||
};
|
||||
use serde_json::json;
|
||||
use stream_assert::assert_next_matches;
|
||||
|
||||
use super::{TestTimeline, ALICE, BOB};
|
||||
use crate::timeline::TimelineItemContent;
|
||||
|
@ -36,7 +36,7 @@ async fn invalid_edit() {
|
|||
let mut stream = timeline.subscribe_events().await;
|
||||
|
||||
timeline.handle_live_message_event(&ALICE, RoomMessageEventContent::text_plain("test")).await;
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let msg = item.content().as_message().unwrap();
|
||||
assert_eq!(msg.body(), "test");
|
||||
|
||||
|
@ -73,7 +73,7 @@ async fn invalid_event_content() {
|
|||
}))
|
||||
.await;
|
||||
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
assert_eq!(item.sender(), "@alice:example.org");
|
||||
assert_eq!(item.event_id().unwrap(), "$eeG0HA0FAZ37wP8kXlNkxx3I");
|
||||
assert_eq!(item.timestamp(), MilliSecondsSinceUnixEpoch(uint!(10)));
|
||||
|
@ -96,7 +96,7 @@ async fn invalid_event_content() {
|
|||
}))
|
||||
.await;
|
||||
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
assert_eq!(item.sender(), "@alice:example.org");
|
||||
assert_eq!(item.event_id().unwrap(), "$d5G0HA0FAZ37wP8kXlNkxx3I");
|
||||
assert_eq!(item.timestamp(), MilliSecondsSinceUnixEpoch(uint!(2179)));
|
||||
|
|
|
@ -12,14 +12,13 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use assert_matches::assert_matches;
|
||||
use eyeball_im::VectorDiff;
|
||||
use futures_util::StreamExt;
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::events::{
|
||||
receipt::{ReceiptThread, ReceiptType},
|
||||
room::message::RoomMessageEventContent,
|
||||
};
|
||||
use stream_assert::assert_next_matches;
|
||||
|
||||
use super::{TestTimeline, ALICE, BOB};
|
||||
|
||||
|
@ -31,18 +30,15 @@ async fn read_receipts_updates() {
|
|||
timeline.handle_live_message_event(*ALICE, RoomMessageEventContent::text_plain("A")).await;
|
||||
timeline.handle_live_message_event(*BOB, RoomMessageEventContent::text_plain("B")).await;
|
||||
|
||||
let _day_divider =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let _day_divider = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
|
||||
// No read receipt for our own user.
|
||||
let item_a =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item_a = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let event_a = item_a.as_event().unwrap();
|
||||
assert!(event_a.read_receipts().is_empty());
|
||||
|
||||
// Implicit read receipt of Bob.
|
||||
let item_b =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item_b = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let event_b = item_b.as_event().unwrap();
|
||||
assert_eq!(event_b.read_receipts().len(), 1);
|
||||
assert!(event_b.read_receipts().get(*BOB).is_some());
|
||||
|
@ -50,21 +46,18 @@ async fn read_receipts_updates() {
|
|||
// Implicit read receipt of Bob is updated.
|
||||
timeline.handle_live_message_event(*BOB, RoomMessageEventContent::text_plain("C")).await;
|
||||
|
||||
let item_a =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::Set { index: 2, value }) => value);
|
||||
let item_a = assert_next_matches!(stream, VectorDiff::Set { index: 2, value } => value);
|
||||
let event_a = item_a.as_event().unwrap();
|
||||
assert!(event_a.read_receipts().is_empty());
|
||||
|
||||
let item_c =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item_c = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let event_c = item_c.as_event().unwrap();
|
||||
assert_eq!(event_c.read_receipts().len(), 1);
|
||||
assert!(event_c.read_receipts().get(*BOB).is_some());
|
||||
|
||||
timeline.handle_live_message_event(*ALICE, RoomMessageEventContent::text_plain("D")).await;
|
||||
|
||||
let item_d =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item_d = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let event_d = item_d.as_event().unwrap();
|
||||
assert!(event_d.read_receipts().is_empty());
|
||||
|
||||
|
@ -78,13 +71,11 @@ async fn read_receipts_updates() {
|
|||
)])
|
||||
.await;
|
||||
|
||||
let item_c =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::Set { index: 3, value }) => value);
|
||||
let item_c = assert_next_matches!(stream, VectorDiff::Set { index: 3, value } => value);
|
||||
let event_c = item_c.as_event().unwrap();
|
||||
assert!(event_c.read_receipts().is_empty());
|
||||
|
||||
let item_d =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::Set { index: 4, value }) => value);
|
||||
let item_d = assert_next_matches!(stream, VectorDiff::Set { index: 4, value } => value);
|
||||
let event_d = item_d.as_event().unwrap();
|
||||
assert_eq!(event_d.read_receipts().len(), 1);
|
||||
assert!(event_d.read_receipts().get(*BOB).is_some());
|
||||
|
|
|
@ -12,9 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use assert_matches::assert_matches;
|
||||
use eyeball_im::VectorDiff;
|
||||
use futures_util::StreamExt;
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::events::{
|
||||
reaction::ReactionEventContent,
|
||||
|
@ -22,6 +20,7 @@ use ruma::events::{
|
|||
room::message::{RedactedRoomMessageEventContent, RoomMessageEventContent},
|
||||
};
|
||||
use serde_json::json;
|
||||
use stream_assert::assert_next_matches;
|
||||
|
||||
use super::{TestTimeline, ALICE, BOB};
|
||||
|
||||
|
@ -31,15 +30,14 @@ async fn reaction_redaction() {
|
|||
let mut stream = timeline.subscribe_events().await;
|
||||
|
||||
timeline.handle_live_message_event(&ALICE, RoomMessageEventContent::text_plain("hi!")).await;
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
assert_eq!(item.reactions().len(), 0);
|
||||
|
||||
let msg_event_id = item.event_id().unwrap();
|
||||
|
||||
let rel = Annotation::new(msg_event_id.to_owned(), "+1".to_owned());
|
||||
timeline.handle_live_message_event(&BOB, ReactionEventContent::new(rel)).await;
|
||||
let item =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::Set { index: 0, value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::Set { index: 0, value } => value);
|
||||
assert_eq!(item.reactions().len(), 1);
|
||||
|
||||
// TODO: After adding raw timeline items, check for one here
|
||||
|
@ -47,8 +45,7 @@ async fn reaction_redaction() {
|
|||
let reaction_event_id = item.event_id().unwrap();
|
||||
|
||||
timeline.handle_live_redaction(&BOB, reaction_event_id).await;
|
||||
let item =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::Set { index: 0, value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::Set { index: 0, value } => value);
|
||||
assert_eq!(item.reactions().len(), 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,12 +15,12 @@
|
|||
use assert_matches::assert_matches;
|
||||
use chrono::{Datelike, Local, TimeZone};
|
||||
use eyeball_im::VectorDiff;
|
||||
use futures_util::StreamExt;
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::{
|
||||
event_id,
|
||||
events::{room::message::RoomMessageEventContent, AnyMessageLikeEventContent},
|
||||
};
|
||||
use stream_assert::assert_next_matches;
|
||||
|
||||
use super::{TestTimeline, ALICE, BOB};
|
||||
use crate::timeline::{TimelineItem, VirtualTimelineItem};
|
||||
|
@ -37,8 +37,7 @@ async fn day_divider() {
|
|||
)
|
||||
.await;
|
||||
|
||||
let day_divider =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let day_divider = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let ts = assert_matches!(
|
||||
day_divider.as_virtual().unwrap(),
|
||||
VirtualTimelineItem::DayDivider(ts) => *ts
|
||||
|
@ -48,7 +47,7 @@ async fn day_divider() {
|
|||
assert_eq!(date.month(), 1);
|
||||
assert_eq!(date.day(), 1);
|
||||
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
item.as_event().unwrap();
|
||||
|
||||
timeline
|
||||
|
@ -58,7 +57,7 @@ async fn day_divider() {
|
|||
)
|
||||
.await;
|
||||
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
item.as_event().unwrap();
|
||||
|
||||
// Timestamps start at unix epoch, advance to one day later
|
||||
|
@ -71,8 +70,7 @@ async fn day_divider() {
|
|||
)
|
||||
.await;
|
||||
|
||||
let day_divider =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let day_divider = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let ts = assert_matches!(
|
||||
day_divider.as_virtual().unwrap(),
|
||||
VirtualTimelineItem::DayDivider(ts) => *ts
|
||||
|
@ -82,7 +80,7 @@ async fn day_divider() {
|
|||
assert_eq!(date.month(), 1);
|
||||
assert_eq!(date.day(), 2);
|
||||
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
item.as_event().unwrap();
|
||||
|
||||
let _ = timeline
|
||||
|
@ -93,11 +91,10 @@ async fn day_divider() {
|
|||
|
||||
// The other events are in the past so a local event always creates a new day
|
||||
// divider.
|
||||
let day_divider =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let day_divider = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
assert_matches!(day_divider.as_virtual().unwrap(), VirtualTimelineItem::DayDivider { .. });
|
||||
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
item.as_event().unwrap();
|
||||
}
|
||||
|
||||
|
@ -107,9 +104,8 @@ async fn update_read_marker() {
|
|||
let mut stream = timeline.subscribe().await;
|
||||
|
||||
timeline.handle_live_message_event(&ALICE, RoomMessageEventContent::text_plain("A")).await;
|
||||
let _day_divider =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let _day_divider = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let first_event_id = item.as_event().unwrap().event_id().unwrap().to_owned();
|
||||
|
||||
timeline.inner.set_fully_read_event(first_event_id.clone()).await;
|
||||
|
@ -117,27 +113,25 @@ async fn update_read_marker() {
|
|||
// Nothing should happen, the marker cannot be added at the end.
|
||||
|
||||
timeline.handle_live_message_event(&BOB, RoomMessageEventContent::text_plain("B")).await;
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let second_event_id = item.as_event().unwrap().event_id().unwrap().to_owned();
|
||||
|
||||
// Now the read marker appears after the first event.
|
||||
let item =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::Insert { index: 2, value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::Insert { index: 2, value } => value);
|
||||
assert_matches!(item.as_virtual(), Some(VirtualTimelineItem::ReadMarker));
|
||||
|
||||
timeline.inner.set_fully_read_event(second_event_id.clone()).await;
|
||||
|
||||
// The read marker is removed but not reinserted, because it cannot be added at
|
||||
// the end.
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::Remove { index: 2 }));
|
||||
assert_next_matches!(stream, VectorDiff::Remove { index: 2 });
|
||||
|
||||
timeline.handle_live_message_event(&ALICE, RoomMessageEventContent::text_plain("C")).await;
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let third_event_id = item.as_event().unwrap().event_id().unwrap().to_owned();
|
||||
|
||||
// Now the read marker is reinserted after the second event.
|
||||
let marker =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::Insert { index: 3, value }) => value);
|
||||
let marker = assert_next_matches!(stream, VectorDiff::Insert { index: 3, value } => value);
|
||||
assert_matches!(*marker, TimelineItem::Virtual(VirtualTimelineItem::ReadMarker));
|
||||
|
||||
// Nothing should happen if the fully read event is set back to an older event.
|
||||
|
@ -151,14 +145,13 @@ async fn update_read_marker() {
|
|||
timeline.inner.set_fully_read_event(second_event_id).await;
|
||||
|
||||
timeline.handle_live_message_event(&ALICE, RoomMessageEventContent::text_plain("D")).await;
|
||||
let item = assert_matches!(stream.next().await, Some(VectorDiff::PushBack { value }) => value);
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
item.as_event().unwrap();
|
||||
|
||||
timeline.inner.set_fully_read_event(third_event_id).await;
|
||||
|
||||
// The read marker is moved after the third event.
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::Remove { index: 3 }));
|
||||
let marker =
|
||||
assert_matches!(stream.next().await, Some(VectorDiff::Insert { index: 4, value }) => value);
|
||||
assert_next_matches!(stream, VectorDiff::Remove { index: 3 });
|
||||
let marker = assert_next_matches!(stream, VectorDiff::Insert { index: 4, value } => value);
|
||||
assert_matches!(*marker, TimelineItem::Virtual(VirtualTimelineItem::ReadMarker));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue