Skip to content

Commit

Permalink
ui: Add tests for Sent In Clear shield.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Jul 31, 2024
1 parent 0321afa commit a3e3fa3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/matrix-sdk-ui/src/timeline/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ mod polls;
mod reactions;
mod read_receipts;
mod redaction;
mod shields;
mod virt;

struct TestTimeline {
Expand Down Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions crates/matrix-sdk-ui/src/timeline/tests/shields.rs
Original file line number Diff line number Diff line change
@@ -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." }));
}

0 comments on commit a3e3fa3

Please sign in to comment.