Skip to content

Commit ffe6711

Browse files
committed
add spec test for multi-tab
1 parent da6dcc0 commit ffe6711

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,4 +1747,72 @@ describeSpec('Listens:', [], () => {
17471747
);
17481748
}
17491749
);
1750+
1751+
specTest(
1752+
'Empty initial snapshot is raised from cache in multiple tabs',
1753+
['multi-client'],
1754+
() => {
1755+
const query1 = query('collection');
1756+
return (
1757+
client(0, /* withGcEnabled= */ false)
1758+
// Populate the cache with the empty query results.
1759+
.userListens(query1)
1760+
.watchAcksFull(query1, 1000)
1761+
.expectEvents(query1, { fromCache: false })
1762+
// Query is shared in second client
1763+
.client(1)
1764+
.expectListen(query1)
1765+
.client(0)
1766+
.userUnlistens(query1)
1767+
.watchRemoves(query1)
1768+
.client(1)
1769+
.expectUnlisten(query1)
1770+
// Re-listen to the query in second client and verify that the empty
1771+
// snapshot is raised from cache.
1772+
.userListens(query1, { resumeToken: 'resume-token-1000' })
1773+
.expectEvents(query1, { fromCache: true })
1774+
.client(0)
1775+
.expectListen(query1, { resumeToken: 'resume-token-1000' })
1776+
// Verify that another snapshot is raised once the query result comes
1777+
// back from Watch.
1778+
.watchAcksFull(query1, 2000)
1779+
.client(1)
1780+
.expectEvents(query1, { fromCache: false })
1781+
);
1782+
}
1783+
);
1784+
specTest(
1785+
'Empty-due-to-delete initial snapshot is raised from cache in multiple tabs',
1786+
['multi-client'],
1787+
() => {
1788+
const query1 = query('collection');
1789+
const doc1 = doc('collection/a', 1000, { v: 1 });
1790+
const doc1Deleted = deletedDoc('collection/a', 2000);
1791+
1792+
return (
1793+
client(0, /* withGcEnabled= */ false)
1794+
// Populate the cache with the empty query results.
1795+
.userListens(query1)
1796+
.watchAcksFull(query1, 1000, doc1)
1797+
.expectEvents(query1, { added: [doc1] })
1798+
.userUnlistens(query1)
1799+
.watchRemoves(query1)
1800+
// Delete the only document in the result set locally on the client.
1801+
.userDeletes('collection/a')
1802+
// Re-listen to the query in second client and verify that the empty
1803+
// snapshot is raised from cache with local mutation.
1804+
.client(1)
1805+
.userListens(query1)
1806+
.expectEvents(query1, { fromCache: true })
1807+
// Should get events once stream is caught up.
1808+
.client(0)
1809+
.expectListen(query1, { resumeToken: 'resume-token-1000' })
1810+
.writeAcks('collection/a', 2000)
1811+
.watchAcksFull(query1, 2000, doc1Deleted)
1812+
.client(1)
1813+
.expectListen(query1, { resumeToken: 'resume-token-2000' })
1814+
.expectEvents(query1, { fromCache: false })
1815+
);
1816+
}
1817+
);
17501818
});

0 commit comments

Comments
 (0)