Skip to content

Commit

Permalink
test(ui): Use stream_assert to simplify the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Jun 15, 2023
1 parent d935f52 commit 5673422
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions crates/matrix-sdk-ui/tests/integration/room_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use ruma::{
room_id, uint,
};
use serde_json::json;
use stream_assert::{assert_next_eq, assert_pending};
use wiremock::{http::Method, Match, Mock, MockServer, Request, ResponseTemplate};

use crate::{
Expand Down Expand Up @@ -295,10 +296,10 @@ async fn test_sync_from_init_to_enjoy() -> Result<(), Error> {
},
};

assert_eq!(
entries_loading_state_stream.next().now_or_never(),
assert_next_eq!(
entries_loading_state_stream,
// It's `FullyLoaded` because it was a `Selective` sync-mode.
Some(Some(EntriesLoadingState::FullyLoaded)),
EntriesLoadingState::FullyLoaded
);

sync_then_assert_request_and_fake_response! {
Expand Down Expand Up @@ -347,11 +348,11 @@ async fn test_sync_from_init_to_enjoy() -> Result<(), Error> {
},
};

assert_eq!(
entries_loading_state_stream.next().now_or_never(),
assert_next_eq!(
entries_loading_state_stream,
// It's `PartiallyLoaded` because it's in `Growing` sync-mode,
// and it's not finished.
Some(Some(EntriesLoadingState::PartiallyLoaded))
EntriesLoadingState::PartiallyLoaded
);

sync_then_assert_request_and_fake_response! {
Expand Down Expand Up @@ -387,11 +388,7 @@ async fn test_sync_from_init_to_enjoy() -> Result<(), Error> {
},
};

assert_eq!(
entries_loading_state_stream.next().now_or_never(),
// The loading state is the same.
None,
);
assert_pending!(entries_loading_state_stream);

sync_then_assert_request_and_fake_response! {
[server, room_list, sync]
Expand Down Expand Up @@ -426,11 +423,7 @@ async fn test_sync_from_init_to_enjoy() -> Result<(), Error> {
},
};

assert_eq!(
entries_loading_state_stream.next().now_or_never(),
// The loading state is the same.
None,
);
assert_pending!(entries_loading_state_stream);

sync_then_assert_request_and_fake_response! {
[server, room_list, sync]
Expand Down Expand Up @@ -465,10 +458,10 @@ async fn test_sync_from_init_to_enjoy() -> Result<(), Error> {
},
};

assert_eq!(
entries_loading_state_stream.next().now_or_never(),
assert_next_eq!(
entries_loading_state_stream,
// Finally, it's `FullyLoaded`!.
Some(Some(EntriesLoadingState::FullyLoaded)),
EntriesLoadingState::FullyLoaded
);

Ok(())
Expand Down

0 comments on commit 5673422

Please sign in to comment.