Skip to content

Commit

Permalink
add spec test
Browse files Browse the repository at this point in the history
  • Loading branch information
milaGGL committed Jun 27, 2024
1 parent 5ce0041 commit 15ec65f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/firestore/src/core/sync_engine_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ export async function syncEngineEmitNewSnapsAndNotifyLocalStore(
if (syncEngineImpl.isPrimaryClient) {
// Query state is set to `current` if:
// - The is a view change and it is up-to-date, or,
// - There are no changes and the Target is current
// - We received a global snapshot and the Target is current
const isCurrent = viewSnapshot
? !viewSnapshot.fromCache
: remoteEvent?.targetChanges.get(queryView.targetId)?.current;
Expand Down
28 changes: 28 additions & 0 deletions packages/firestore/test/unit/specs/listen_spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1895,4 +1895,32 @@ describeSpec('Listens:', [], () => {
.restoreListen(query1, 'resume-token-1000', /* expectedCount= */ 1);
}
);

specTest(
'Global snapshots would not alter query state if there is no changes',
['multi-client'],
() => {
const query1 = query('collection');
const docA = doc('collection/a', 1000, { key: 'a' });
return (
client(0)
.becomeVisible()
// Listen to the first query in the primary client
.expectPrimaryState(true)
.userListens(query1)
.watchAcksFull(query1, 1000, docA)
.expectEvents(query1, { added: [docA] })
// Reproduces: https://github.com/firebase/firebase-js-sdk/issues/8314
// Watch could send existence filters along with a global snapshot.
// If existence filter matches, there will be no view changes, and query should not be
// marked as "not-current" as the Target is up to date.
.watchFilters([query1], [docA.key])
.watchSnapshots(2000, [], 'resume-token-2000')
// Listening to the query in the secondary tab. The snapshot is up to date.
.client(1)
.userListens(query1)
.expectEvents(query1, { added: [docA] })
);
}
);
});

0 comments on commit 15ec65f

Please sign in to comment.