Skip to content

Commit

Permalink
chore: Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Jul 31, 2024
1 parent 11a26d7 commit dc1a34c
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 9 deletions.
8 changes: 7 additions & 1 deletion crates/matrix-sdk-ui/tests/integration/room_list_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ use stream_assert::{assert_next_matches, assert_pending};
use tokio::{spawn, sync::mpsc::channel, task::yield_now};
use wiremock::MockServer;

use crate::timeline::sliding_sync::{assert_timeline_stream, timeline_event};
use crate::{
mock_encryption_state,
timeline::sliding_sync::{assert_timeline_stream, timeline_event},
};

async fn new_room_list_service() -> Result<(Client, MockServer, RoomListService), Error> {
let (client, server) = logged_in_client_with_server().await;
Expand Down Expand Up @@ -2270,6 +2273,8 @@ async fn test_room_timeline() -> Result<(), Error> {
},
};

mock_encryption_state(&server, false).await;

let room = room_list.room(room_id)?;
room.init_timeline_with_builder(room.default_room_timeline_builder().await.unwrap()).await?;
let timeline = room.timeline().unwrap();
Expand Down Expand Up @@ -2320,6 +2325,7 @@ async fn test_room_timeline() -> Result<(), Error> {
#[async_test]
async fn test_room_latest_event() -> Result<(), Error> {
let (_, server, room_list) = new_room_list_service().await?;
mock_encryption_state(&server, false).await;

let sync = room_list.sync();
pin_mut!(sync);
Expand Down
9 changes: 7 additions & 2 deletions crates/matrix-sdk-ui/tests/integration/timeline/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ async fn test_echo() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = Arc::new(room.timeline().await.unwrap());
let (_, mut timeline_stream) = timeline.subscribe().await;

mock_encryption_state(&server, false).await;

Mock::given(method("PUT"))
.and(path_regex(r"^/_matrix/client/r0/rooms/.*/send/.*"))
.and(header("authorization", "Bearer 1234"))
Expand Down Expand Up @@ -140,6 +140,7 @@ async fn test_retry_failed() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();

client.send_queue().set_enabled(true).await;
mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = Arc::new(room.timeline().await.unwrap());
Expand Down Expand Up @@ -216,6 +217,8 @@ async fn test_dedup_by_event_id_late() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = Arc::new(room.timeline().await.unwrap());
let (_, mut timeline_stream) = timeline.subscribe().await;
Expand Down Expand Up @@ -291,6 +294,8 @@ async fn test_cancel_failed() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = Arc::new(room.timeline().await.unwrap());
let (_, mut timeline_stream) =
Expand Down
12 changes: 12 additions & 0 deletions crates/matrix-sdk-ui/tests/integration/timeline/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ async fn test_edit() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = room.timeline().await.unwrap();
let (_, mut timeline_stream) = timeline.subscribe().await;
Expand Down Expand Up @@ -166,6 +168,8 @@ async fn test_edit_local_echo() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = room.timeline().await.unwrap();
let (_, mut timeline_stream) = timeline.subscribe().await;
Expand Down Expand Up @@ -276,6 +280,8 @@ async fn test_send_edit() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = room.timeline().await.unwrap();
let (_, mut timeline_stream) =
Expand Down Expand Up @@ -350,6 +356,8 @@ async fn test_send_reply_edit() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = room.timeline().await.unwrap();
let (_, mut timeline_stream) =
Expand Down Expand Up @@ -443,6 +451,8 @@ async fn test_send_edit_poll() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = room.timeline().await.unwrap();
let (_, mut timeline_stream) =
Expand Down Expand Up @@ -534,6 +544,8 @@ async fn test_send_edit_when_timeline_is_clear() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = room.timeline().await.unwrap();
let (_, mut timeline_stream) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use matrix_sdk_ui::{timeline::TimelineFocus, Timeline};
use ruma::{event_id, events::room::message::RoomMessageEventContent, room_id};
use stream_assert::assert_pending;

use crate::{mock_context, mock_messages, mock_sync};
use crate::{mock_context, mock_encryption_state, mock_messages, mock_sync};

#[async_test]
async fn test_new_focused() {
Expand Down Expand Up @@ -68,6 +68,8 @@ async fn test_new_focused() {
)
.await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = Timeline::builder(&room)
.with_focus(TimelineFocus::Event {
Expand Down Expand Up @@ -207,6 +209,8 @@ async fn test_focused_timeline_reacts() {
)
.await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = Timeline::builder(&room)
.with_focus(TimelineFocus::Event {
Expand Down Expand Up @@ -302,6 +306,8 @@ async fn test_focused_timeline_doesnt_show_local_echoes() {
)
.await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = Timeline::builder(&room)
.with_focus(TimelineFocus::Event {
Expand Down
15 changes: 14 additions & 1 deletion crates/matrix-sdk-ui/tests/integration/timeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use wiremock::{
Mock, ResponseTemplate,
};

use crate::mock_sync;
use crate::{mock_encryption_state, mock_sync};

mod echo;
mod edit;
Expand All @@ -64,6 +64,8 @@ async fn test_reaction() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = room.timeline().await.unwrap();
let (_, mut timeline_stream) = timeline.subscribe().await;
Expand Down Expand Up @@ -171,6 +173,8 @@ async fn test_redacted_message() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = room.timeline().await.unwrap();
let (_, mut timeline_stream) = timeline.subscribe().await;
Expand Down Expand Up @@ -228,6 +232,8 @@ async fn test_redact_message() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = room.timeline().await.unwrap();
let (_, mut timeline_stream) = timeline.subscribe().await;
Expand Down Expand Up @@ -309,6 +315,8 @@ async fn test_read_marker() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = room.timeline().await.unwrap();
let (_, mut timeline_stream) = timeline.subscribe().await;
Expand Down Expand Up @@ -391,6 +399,8 @@ async fn test_sync_highlighted() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = room.timeline().await.unwrap();
let (_, mut timeline_stream) = timeline.subscribe().await;
Expand Down Expand Up @@ -457,6 +467,8 @@ async fn test_duplicate_maintains_correct_order() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = room.timeline().await.unwrap();

Expand Down Expand Up @@ -639,6 +651,7 @@ impl PinningTestSetup<'_> {
}

async fn timeline(&self) -> matrix_sdk_ui::Timeline {
mock_encryption_state(&self.server, false).await;
let room = self.client.get_room(self.room_id).unwrap();
room.timeline().await.unwrap()
}
Expand Down
18 changes: 17 additions & 1 deletion crates/matrix-sdk-ui/tests/integration/timeline/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use wiremock::{
Mock, ResponseTemplate,
};

use crate::mock_sync;
use crate::{mock_encryption_state, mock_sync};

#[async_test]
async fn test_back_pagination() {
Expand All @@ -61,6 +61,8 @@ async fn test_back_pagination() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = Arc::new(room.timeline().await.unwrap());
let (_, mut timeline_stream) = timeline.subscribe().await;
Expand Down Expand Up @@ -162,6 +164,8 @@ async fn test_back_pagination_highlighted() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = Arc::new(room.timeline().await.unwrap());
let (_, mut timeline_stream) = timeline.subscribe().await;
Expand Down Expand Up @@ -244,6 +248,8 @@ async fn test_wait_for_token() {
client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = Arc::new(room.timeline().await.unwrap());

Expand Down Expand Up @@ -305,6 +311,8 @@ async fn test_dedup_pagination() {
client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = Arc::new(room.timeline().await.unwrap());

Expand Down Expand Up @@ -365,6 +373,8 @@ async fn test_timeline_reset_while_paginating() {
client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = Arc::new(room.timeline().await.unwrap());

Expand Down Expand Up @@ -561,6 +571,8 @@ async fn test_empty_chunk() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = Arc::new(room.timeline().await.unwrap());
let (_, mut timeline_stream) = timeline.subscribe().await;
Expand Down Expand Up @@ -651,6 +663,8 @@ async fn test_until_num_items_with_empty_chunk() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = Arc::new(room.timeline().await.unwrap());
let (_, mut timeline_stream) = timeline.subscribe().await;
Expand Down Expand Up @@ -766,6 +780,8 @@ async fn test_back_pagination_aborted() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = Arc::new(room.timeline().await.unwrap());
let (_, mut back_pagination_status) = timeline.live_back_pagination_status().await.unwrap();
Expand Down
4 changes: 3 additions & 1 deletion crates/matrix-sdk-ui/tests/integration/timeline/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use wiremock::{
Mock, ResponseTemplate,
};

use crate::mock_sync;
use crate::{mock_encryption_state, mock_sync};

#[async_test]
async fn test_update_sender_profiles() {
Expand All @@ -46,6 +46,8 @@ async fn test_update_sender_profiles() {
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
server.reset().await;

mock_encryption_state(&server, false).await;

let room = client.get_room(&DEFAULT_TEST_ROOM_ID).unwrap();
let timeline = Arc::new(room.timeline().await.unwrap());

Expand Down
4 changes: 4 additions & 0 deletions crates/matrix-sdk-ui/tests/integration/timeline/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ async fn test_retry_order() {
mock_sync(&server, sync_response_builder.build_json_sync_response(), None).await;
let _response = client.sync_once(sync_settings.clone()).await.unwrap();

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = Arc::new(room.timeline().await.unwrap());
let (_, mut timeline_stream) =
Expand Down Expand Up @@ -229,6 +231,8 @@ async fn test_reloaded_failed_local_echoes_are_marked_as_failed() {
mock_sync(&server, sync_response_builder.build_json_sync_response(), None).await;
let _response = client.sync_once(sync_settings.clone()).await.unwrap();

mock_encryption_state(&server, false).await;

let room = client.get_room(room_id).unwrap();
let timeline = Arc::new(room.timeline().await.unwrap());
let (_, mut timeline_stream) =
Expand Down
Loading

0 comments on commit dc1a34c

Please sign in to comment.