Skip to content

Commit

Permalink
test(ui): Test RoomList::entries_loading_state.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Jun 15, 2023
1 parent 4e92738 commit a073c14
Showing 1 changed file with 70 additions and 1 deletion.
71 changes: 70 additions & 1 deletion crates/matrix-sdk-ui/tests/integration/room_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use imbl::vector;
use matrix_sdk_test::async_test;
use matrix_sdk_ui::{
room_list::{
Error, Input, RoomListEntry, State, ALL_ROOMS_LIST_NAME as ALL_ROOMS,
EntriesLoadingState, Error, Input, RoomListEntry, State, ALL_ROOMS_LIST_NAME as ALL_ROOMS,
VISIBLE_ROOMS_LIST_NAME as VISIBLE_ROOMS,
},
timeline::{TimelineItem, VirtualTimelineItem},
Expand Down Expand Up @@ -235,9 +235,14 @@ macro_rules! assert_entries_stream {
async fn test_sync_from_init_to_enjoy() -> Result<(), Error> {
let (server, room_list) = new_room_list().await?;

let (entries_loading_state, mut entries_loading_state_stream) =
room_list.entries_loading_state().await?;

let sync = room_list.sync();
pin_mut!(sync);

assert_eq!(entries_loading_state, EntriesLoadingState::NotLoaded);

sync_then_assert_request_and_fake_response! {
[server, room_list, sync]
states = Init => FirstRooms,
Expand Down Expand Up @@ -290,6 +295,12 @@ async fn test_sync_from_init_to_enjoy() -> Result<(), Error> {
},
};

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

sync_then_assert_request_and_fake_response! {
[server, room_list, sync]
states = FirstRooms => AllRooms,
Expand Down Expand Up @@ -336,6 +347,13 @@ async fn test_sync_from_init_to_enjoy() -> Result<(), Error> {
},
};

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

sync_then_assert_request_and_fake_response! {
[server, room_list, sync]
states = AllRooms => CarryOn,
Expand Down Expand Up @@ -369,6 +387,12 @@ 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,
);

sync_then_assert_request_and_fake_response! {
[server, room_list, sync]
states = CarryOn => CarryOn,
Expand Down Expand Up @@ -402,6 +426,51 @@ 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,
);

sync_then_assert_request_and_fake_response! {
[server, room_list, sync]
states = CarryOn => CarryOn,
assert request = {
"lists": {
ALL_ROOMS: {
"ranges": [[0, 199]],
},
VISIBLE_ROOMS: {
"ranges": [],
},
},
},
respond with = {
"pos": "2",
"lists": {
ALL_ROOMS: {
"count": 200,
"ops": [
// let's ignore them for now
],
},
VISIBLE_ROOMS: {
"count": 0,
"ops": [],
},
},
"rooms": {
// let's ignore them for now
},
},
};

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

Ok(())
}
#[async_test]
Expand Down

0 comments on commit a073c14

Please sign in to comment.