Skip to content

Commit

Permalink
test(ui): Adjust tests according to the new Timeline behaviour.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Jan 8, 2025
1 parent 3b42057 commit ba57d99
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 327 deletions.
5 changes: 0 additions & 5 deletions crates/matrix-sdk-ui/src/timeline/event_item/content/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,6 @@ impl TimelineItemContent {
as_variant!(self, Self::UnableToDecrypt)
}

#[cfg(test)]
pub(crate) fn is_redacted(&self) -> bool {
matches!(self, Self::RedactedMessage)
}

// These constructors could also be `From` implementations, but that would
// allow users to call them directly, which should not be supported
pub(crate) fn message(
Expand Down
73 changes: 1 addition & 72 deletions crates/matrix-sdk-ui/src/timeline/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use ruma::{
receipt::{Receipt, ReceiptThread, ReceiptType},
room::{
member::{MembershipState, RedactedRoomMemberEventContent, RoomMemberEventContent},
message::{MessageType, RoomMessageEventContent},
message::MessageType,
name::RoomNameEventContent,
topic::RedactedRoomTopicEventContent,
},
Expand Down Expand Up @@ -280,77 +280,6 @@ async fn test_other_state() {
assert_matches!(full_content, FullStateEventContent::Redacted(_));
}

#[async_test]
async fn test_dedup_pagination() {
let timeline = TestTimeline::new();

let event = timeline
.event_builder
.make_sync_message_event(*ALICE, RoomMessageEventContent::text_plain("o/"));
timeline.handle_live_event(SyncTimelineEvent::new(event.clone())).await;
// This cast is not actually correct, sync events aren't valid
// back-paginated events, as they are missing `room_id`. However, the
// timeline doesn't care about that `room_id` and casts back to
// `Raw<AnySyncTimelineEvent>` before attempting to deserialize.
timeline.handle_back_paginated_event(event.cast()).await;

let timeline_items = timeline.controller.items().await;
assert_eq!(timeline_items.len(), 2);
assert_matches!(
timeline_items[0].kind,
TimelineItemKind::Virtual(VirtualTimelineItem::DateDivider(_))
);
assert_matches!(timeline_items[1].kind, TimelineItemKind::Event(_));
}

#[async_test]
async fn test_dedup_initial() {
let timeline = TestTimeline::new();

let f = &timeline.factory;
let event_a = f.text_msg("A").sender(*ALICE).into_sync();
let event_b = f.text_msg("B").sender(*BOB).into_sync();
let event_c = f.text_msg("C").sender(*CAROL).into_sync();

timeline
.controller
.add_events_at(
[
// two events
event_a.clone(),
event_b.clone(),
// same events got duplicated in next sync response
event_a,
event_b,
// … and a new event also came in
event_c,
]
.into_iter(),
TimelineNewItemPosition::End { origin: RemoteEventOrigin::Sync },
)
.await;

let timeline_items = timeline.controller.items().await;
assert_eq!(timeline_items.len(), 4);

assert!(timeline_items[0].is_date_divider());

let event1 = &timeline_items[1];
let event2 = &timeline_items[2];
let event3 = &timeline_items[3];

// Make sure the order is right.
assert_eq!(event1.as_event().unwrap().sender(), *ALICE);
assert_eq!(event2.as_event().unwrap().sender(), *BOB);
assert_eq!(event3.as_event().unwrap().sender(), *CAROL);

// Make sure we reused IDs when deduplicating events.
assert_eq!(event1.unique_id().0, "0");
assert_eq!(event2.unique_id().0, "1");
assert_eq!(event3.unique_id().0, "2");
assert_eq!(timeline_items[0].unique_id().0, "3");
}

#[async_test]
async fn test_internal_id_prefix() {
let timeline = TestTimeline::with_internal_id_prefix("le_prefix_".to_owned());
Expand Down
38 changes: 1 addition & 37 deletions crates/matrix-sdk-ui/src/timeline/tests/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use assert_matches::assert_matches;
use eyeball_im::VectorDiff;
use matrix_sdk::{assert_next_matches_with_timeout, send_queue::RoomSendQueueUpdate};
use matrix_sdk_base::store::QueueWedgeError;
use matrix_sdk_test::{async_test, event_factory::EventFactory, ALICE, BOB};
use matrix_sdk_test::{async_test, ALICE, BOB};
use ruma::{
event_id,
events::{room::message::RoomMessageEventContent, AnyMessageLikeEventContent},
Expand Down Expand Up @@ -187,42 +187,6 @@ async fn test_remote_echo_new_position() {
assert_pending!(stream);
}

#[async_test]
async fn test_date_divider_duplication() {
let timeline = TestTimeline::new();

// Given two remote events from one day, and a local event from another day…
let f = EventFactory::new().sender(&BOB);
timeline.handle_live_event(f.text_msg("A")).await;
timeline.handle_live_event(f.text_msg("B")).await;
timeline
.handle_local_event(AnyMessageLikeEventContent::RoomMessage(
RoomMessageEventContent::text_plain("C"),
))
.await;

let items = timeline.controller.items().await;
assert_eq!(items.len(), 5);
assert!(items[0].is_date_divider());
assert!(items[1].is_remote_event());
assert!(items[2].is_remote_event());
assert!(items[3].is_date_divider());
assert!(items[4].is_local_echo());

// … when the second remote event is re-received (day still the same)
let event_id = items[2].as_event().unwrap().event_id().unwrap();
timeline.handle_live_event(f.text_msg("B").event_id(event_id).server_ts(1)).await;

// … it should not impact the date dividers.
let items = timeline.controller.items().await;
assert_eq!(items.len(), 5);
assert!(items[0].is_date_divider());
assert!(items[1].is_remote_event());
assert!(items[2].is_remote_event());
assert!(items[3].is_date_divider());
assert!(items[4].is_local_echo());
}

#[async_test]
async fn test_date_divider_removed_after_local_echo_disappeared() {
let timeline = TestTimeline::new();
Expand Down
58 changes: 1 addition & 57 deletions crates/matrix-sdk-ui/src/timeline/tests/redaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ use matrix_sdk_base::deserialized_responses::SyncTimelineEvent;
use matrix_sdk_test::{async_test, ALICE, BOB};
use ruma::events::{
reaction::RedactedReactionEventContent,
room::{
message::{OriginalSyncRoomMessageEvent, RedactedRoomMessageEventContent},
name::RoomNameEventContent,
},
room::{message::OriginalSyncRoomMessageEvent, name::RoomNameEventContent},
FullStateEventContent,
};
use stream_assert::assert_next_matches;
Expand Down Expand Up @@ -177,56 +174,3 @@ async fn test_reaction_redaction_timeline_filter() {
assert_eq!(item.reactions().len(), 0);
assert_eq!(timeline.controller.items().await.len(), 2);
}

#[async_test]
async fn test_receive_unredacted() {
let timeline = TestTimeline::new();

let f = &timeline.factory;

// send two events, second one redacted
timeline.handle_live_event(f.text_msg("about to be redacted").sender(&ALICE)).await;
timeline
.handle_live_redacted_message_event(&ALICE, RedactedRoomMessageEventContent::new())
.await;

// redact the first one as well
let items = timeline.controller.items().await;
assert!(items[0].is_date_divider());
let fst = items[1].as_event().unwrap();
timeline.handle_live_event(f.redaction(fst.event_id().unwrap()).sender(&ALICE)).await;

let items = timeline.controller.items().await;
assert_eq!(items.len(), 3);
let fst = items[1].as_event().unwrap();
let snd = items[2].as_event().unwrap();

// make sure we have two redacted events
assert!(fst.content.is_redacted());
assert!(snd.content.is_redacted());

// send new events with the same event ID as the previous ones
timeline
.handle_live_event(
f.text_msg("unredacted #1")
.sender(*ALICE)
.event_id(fst.event_id().unwrap())
.server_ts(fst.timestamp()),
)
.await;

timeline
.handle_live_event(
f.text_msg("unredacted #2")
.sender(*ALICE)
.event_id(snd.event_id().unwrap())
.server_ts(snd.timestamp()),
)
.await;

// make sure we still have two redacted events
let items = timeline.controller.items().await;
assert_eq!(items.len(), 3);
assert!(items[1].as_event().unwrap().content.is_redacted());
assert!(items[2].as_event().unwrap().content.is_redacted());
}
Loading

0 comments on commit ba57d99

Please sign in to comment.