test(ui): Test RoomList::entries_loading_state.

This commit is contained in:
Ivan Enderlin
2023-06-15 14:54:38 +02:00
parent 4e92738c28
commit a073c1422c

View File

@@ -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},
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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]