From a073c1422cc89ba03f7ff128d5677eab88ef9df9 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 15 Jun 2023 14:54:38 +0200 Subject: [PATCH] test(ui): Test `RoomList::entries_loading_state`. --- .../tests/integration/room_list.rs | 71 ++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/crates/matrix-sdk-ui/tests/integration/room_list.rs b/crates/matrix-sdk-ui/tests/integration/room_list.rs index 0422aaa6cd6..bb3cf16e0bf 100644 --- a/crates/matrix-sdk-ui/tests/integration/room_list.rs +++ b/crates/matrix-sdk-ui/tests/integration/room_list.rs @@ -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]