mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-06-21 22:58:32 -04:00
sdk-ui: add test checking the pinned event cache is kept for different room instances
This commit is contained in:
committed by
Jorge Martin Espinosa
parent
674605aeab
commit
0496ef4313
@@ -184,6 +184,69 @@ async fn test_max_events_to_load_is_honored() {
|
||||
test_helper.server.reset().await;
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_cached_events_are_kept_for_different_room_instances() {
|
||||
let mut test_helper = TestHelper::new().await;
|
||||
let room_id = test_helper.room_id.clone();
|
||||
|
||||
// Join the room
|
||||
let _ = test_helper.setup_initial_sync_response().await;
|
||||
test_helper.server.reset().await;
|
||||
|
||||
// Load initial timeline items: a text message and a `m.room.pinned_events`
|
||||
// with event $1 and $2 pinned
|
||||
let _ = test_helper
|
||||
.setup_sync_response(vec![("$1", "in the end", false)], Some(vec!["$1", "$2"]))
|
||||
.await;
|
||||
|
||||
let room = test_helper.client.get_room(&room_id).unwrap();
|
||||
let timeline = Timeline::builder(&room)
|
||||
.with_focus(TimelineFocus::PinnedEvents { max_events_to_load: 2 })
|
||||
.build()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(
|
||||
timeline.live_back_pagination_status().await.is_none(),
|
||||
"there should be no live back-pagination status for a focused timeline"
|
||||
);
|
||||
|
||||
let (items, mut timeline_stream) = timeline.subscribe().await;
|
||||
|
||||
assert!(!items.is_empty()); // We just loaded some events
|
||||
assert_pending!(timeline_stream);
|
||||
|
||||
assert!(test_helper.client.pinned_event_cache().get(event_id!("$1")).await.is_some());
|
||||
|
||||
// Drop the existing room and timeline instances
|
||||
test_helper.server.reset().await;
|
||||
drop(timeline_stream);
|
||||
drop(timeline);
|
||||
drop(room);
|
||||
|
||||
// Set up a sync response with only the pinned event ids and no events, so if they exist later
|
||||
// we know they come from the cache
|
||||
let _ = test_helper
|
||||
.setup_sync_response(Vec::new(), Some(vec!["$1", "$2"]))
|
||||
.await;
|
||||
|
||||
// Get a new room instance
|
||||
let room = test_helper.client.get_room(&room_id).unwrap();
|
||||
|
||||
// And a new timeline one
|
||||
let timeline = Timeline::builder(&room)
|
||||
.with_focus(TimelineFocus::PinnedEvents { max_events_to_load: 2 })
|
||||
.build()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let (items, _) = timeline.subscribe().await;
|
||||
assert!(!items.is_empty()); // These events came from the cache
|
||||
assert!(test_helper.client.pinned_event_cache().get(event_id!("$1")).await.is_some());
|
||||
|
||||
test_helper.server.reset().await;
|
||||
}
|
||||
|
||||
struct TestHelper {
|
||||
pub client: Client,
|
||||
pub server: MockServer,
|
||||
|
||||
Reference in New Issue
Block a user