@@ -502,6 +502,59 @@ pub async fn test_load_last_chunk(store: IndexeddbEventCacheStore) {
502
502
assert_eq ! ( chunk_identifier_generator. current( ) , 42 ) ;
503
503
}
504
504
505
+ pub async fn test_load_previous_chunk ( store : IndexeddbEventCacheStore ) {
506
+ let room_id = & DEFAULT_TEST_ROOM_ID ;
507
+ let linked_chunk_id = LinkedChunkId :: Room ( room_id) ;
508
+ let event = |msg : & str | make_test_event ( room_id, msg) ;
509
+
510
+ // Case #1: no chunk at all, equivalent to having an nonexistent
511
+ // `before_chunk_identifier`.
512
+ let previous_chunk =
513
+ store. load_previous_chunk ( linked_chunk_id, ChunkIdentifier :: new ( 153 ) ) . await . unwrap ( ) ;
514
+ assert ! ( previous_chunk. is_none( ) ) ;
515
+
516
+ // Case #2: there is one chunk only: we request the previous on this
517
+ // one, it doesn't exist.
518
+ let updates =
519
+ vec ! [ Update :: NewItemsChunk { previous: None , new: ChunkIdentifier :: new( 42 ) , next: None } ] ;
520
+ store. handle_linked_chunk_updates ( linked_chunk_id, updates) . await . unwrap ( ) ;
521
+
522
+ let previous_chunk =
523
+ store. load_previous_chunk ( linked_chunk_id, ChunkIdentifier :: new ( 42 ) ) . await . unwrap ( ) ;
524
+ assert ! ( previous_chunk. is_none( ) ) ;
525
+
526
+ // Case #3: there are two chunks.
527
+ let updates = vec ! [
528
+ // new chunk before the one that exists.
529
+ Update :: NewItemsChunk {
530
+ previous: None ,
531
+ new: ChunkIdentifier :: new( 7 ) ,
532
+ next: Some ( ChunkIdentifier :: new( 42 ) ) ,
533
+ } ,
534
+ Update :: PushItems {
535
+ at: Position :: new( ChunkIdentifier :: new( 7 ) , 0 ) ,
536
+ items: vec![ event( "brigand du jorat" ) , event( "morbier" ) ] ,
537
+ } ,
538
+ ] ;
539
+ store. handle_linked_chunk_updates ( linked_chunk_id, updates) . await . unwrap ( ) ;
540
+
541
+ let previous_chunk =
542
+ store. load_previous_chunk ( linked_chunk_id, ChunkIdentifier :: new ( 42 ) ) . await . unwrap ( ) ;
543
+
544
+ assert_matches ! ( previous_chunk, Some ( previous_chunk) => {
545
+ assert_eq!( previous_chunk. identifier, 7 ) ;
546
+ assert!( previous_chunk. previous. is_none( ) ) ;
547
+ assert_matches!( previous_chunk. next, Some ( next) => {
548
+ assert_eq!( next, 42 ) ;
549
+ } ) ;
550
+ assert_matches!( previous_chunk. content, ChunkContent :: Items ( items) => {
551
+ assert_eq!( items. len( ) , 2 ) ;
552
+ check_test_event( & items[ 0 ] , "brigand du jorat" ) ;
553
+ check_test_event( & items[ 1 ] , "morbier" ) ;
554
+ } ) ;
555
+ } ) ;
556
+ }
557
+
505
558
/// Macro for generating tests for IndexedDB implementation of
506
559
/// [`EventCacheStore`]
507
560
///
@@ -621,6 +674,13 @@ macro_rules! indexeddb_event_cache_store_integration_tests {
621
674
$crate:: event_cache_store:: integration_tests:: test_load_last_chunk( store)
622
675
. await
623
676
}
677
+
678
+ #[ async_test]
679
+ async fn test_load_previous_chunk( ) {
680
+ let store = get_event_cache_store( ) . await . expect( "Failed to get event cache store" ) ;
681
+ $crate:: event_cache_store:: integration_tests:: test_load_previous_chunk( store)
682
+ . await
683
+ }
624
684
}
625
685
} ;
626
686
}
@@ -654,6 +714,13 @@ macro_rules! event_cache_store_integration_tests {
654
714
event_cache_store. test_handle_updates_and_rebuild_linked_chunk( ) . await ;
655
715
}
656
716
717
+ #[ async_test]
718
+ async fn test_linked_chunk_incremental_loading( ) {
719
+ let event_cache_store =
720
+ get_event_cache_store( ) . await . unwrap( ) . into_event_cache_store( ) ;
721
+ event_cache_store. test_linked_chunk_incremental_loading( ) . await ;
722
+ }
723
+
657
724
#[ async_test]
658
725
async fn test_rebuild_empty_linked_chunk( ) {
659
726
let event_cache_store =
0 commit comments