mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-06-21 22:58:32 -04:00
ui: Add tests for Sent In Clear shield.
This commit is contained in:
@@ -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
|
||||
|
||||
41
crates/matrix-sdk-ui/src/timeline/tests/shields.rs
Normal file
41
crates/matrix-sdk-ui/src/timeline/tests/shields.rs
Normal 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." }));
|
||||
}
|
||||
Reference in New Issue
Block a user