diff --git a/crates/matrix-sdk-ui/src/timeline/tests/mod.rs b/crates/matrix-sdk-ui/src/timeline/tests/mod.rs index d3089044e..9f4f3989a 100644 --- a/crates/matrix-sdk-ui/src/timeline/tests/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/tests/mod.rs @@ -71,6 +71,7 @@ mod polls; mod reactions; mod read_receipts; mod redaction; +mod shields; mod virt; struct TestTimeline { @@ -116,6 +117,19 @@ impl TestTimeline { } } + fn with_is_room_encrypted(encrypted: bool) -> Self { + Self { + inner: TimelineInner::new( + TestRoomDataProvider::default(), + TimelineFocus::Live, + None, + None, + encrypted, + ), + event_builder: EventBuilder::new(), + } + } + fn with_settings(mut self, settings: TimelineInnerSettings) -> Self { self.inner = self.inner.with_settings(settings); self diff --git a/crates/matrix-sdk-ui/src/timeline/tests/shields.rs b/crates/matrix-sdk-ui/src/timeline/tests/shields.rs new file mode 100644 index 000000000..e865729e0 --- /dev/null +++ b/crates/matrix-sdk-ui/src/timeline/tests/shields.rs @@ -0,0 +1,41 @@ +use eyeball_im::VectorDiff; +use matrix_sdk_base::deserialized_responses::ShieldState; +use matrix_sdk_test::{async_test, ALICE}; +use ruma::events::room::message::RoomMessageEventContent; +use stream_assert::assert_next_matches; + +use crate::timeline::tests::TestTimeline; + +#[async_test] +async fn test_no_shield_in_unencrypted_room() { + let timeline = TestTimeline::new(); + let mut stream = timeline.subscribe().await; + + timeline + .handle_live_message_event( + &ALICE, + RoomMessageEventContent::text_plain("Unencrypted message."), + ) + .await; + + let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value); + let shield = item.as_event().unwrap().get_shield(false); + assert!(shield.is_none()); +} + +#[async_test] +async fn test_sent_in_clear_shield() { + let timeline = TestTimeline::with_is_room_encrypted(true); + let mut stream = timeline.subscribe().await; + + timeline + .handle_live_message_event( + &ALICE, + RoomMessageEventContent::text_plain("Unencrypted message."), + ) + .await; + + let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value); + let shield = item.as_event().unwrap().get_shield(false); + assert_eq!(shield, Some(ShieldState::Grey { message: "Sent in clear." })); +}