Skip to content

Commit f06eb5f

Browse files
committed
Add two spec tests for raising initial empty snapshot from cache
1 parent a1cf3d1 commit f06eb5f

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

packages/firestore/test/unit/specs/listen_spec.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,4 +1698,53 @@ describeSpec('Listens:', [], () => {
16981698
})
16991699
.expectSnapshotsInSyncEvent(2);
17001700
});
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+
);
17011750
});

0 commit comments

Comments
 (0)