ui: Add tests for Sent In Clear shield.

This commit is contained in:
Doug
2024-07-31 12:56:09 +01:00
parent bae0f304f7
commit 1abbaa8607
2 changed files with 55 additions and 0 deletions

View File

@@ -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

View File

@@ -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." }));
}