@@ -1698,4 +1698,53 @@ describeSpec('Listens:', [], () => {
1698
1698
} )
1699
1699
. expectSnapshotsInSyncEvent ( 2 ) ;
1700
1700
} ) ;
1701
+
1702
+ specTest ( 'Empty initial snapshot is raised from cache' , [ ] , ( ) => {
1703
+ const query1 = query ( 'collection' ) ;
1704
+ return (
1705
+ spec ( )
1706
+ // Disable GC so the cache persists across listens.
1707
+ . withGCEnabled ( false )
1708
+ // Populate the cache with the empty query results.
1709
+ . userListens ( query1 )
1710
+ . watchAcksFull ( query1 , 1000 )
1711
+ . expectEvents ( query1 , { fromCache : false } )
1712
+ . userUnlistens ( query1 )
1713
+ . watchRemoves ( query1 )
1714
+ // Listen to the query again and verify that the empty snapshot is
1715
+ // raised from cache.
1716
+ . userListens ( query1 , { resumeToken : 'resume-token-1000' } )
1717
+ . expectEvents ( query1 , { fromCache : true } )
1718
+ // Verify that another snapshot is raised once the query result comes
1719
+ // back from Watch.
1720
+ . watchAcksFull ( query1 , 2000 )
1721
+ . expectEvents ( query1 , { fromCache : false } )
1722
+ ) ;
1723
+ } ) ;
1724
+
1725
+ specTest (
1726
+ 'Empty-due-to-delete initial snapshot is raised from cache' ,
1727
+ [ ] ,
1728
+ ( ) => {
1729
+ const query1 = query ( 'collection' ) ;
1730
+ const doc1 = doc ( 'collection/a' , 1000 , { v : 1 } ) ;
1731
+ return (
1732
+ spec ( )
1733
+ // Disable GC so the cache persists across listens.
1734
+ . withGCEnabled ( false )
1735
+ // Populate the cache with the empty query results.
1736
+ . userListens ( query1 )
1737
+ . watchAcksFull ( query1 , 1000 , doc1 )
1738
+ . expectEvents ( query1 , { added : [ doc1 ] } )
1739
+ . userUnlistens ( query1 )
1740
+ . watchRemoves ( query1 )
1741
+ // Delete the only document in the result set locally on the client.
1742
+ . userDeletes ( 'collection/a' )
1743
+ // Listen to the query again and verify that the empty snapshot is
1744
+ // raised from cache, even though the write is not yet acknowledged.
1745
+ . userListens ( query1 , { resumeToken : 'resume-token-1000' } )
1746
+ . expectEvents ( query1 , { fromCache : true } )
1747
+ ) ;
1748
+ }
1749
+ ) ;
1701
1750
} ) ;
0 commit comments