Skip to content

Commit f9f6ff8

Browse files
committed
update tests
1 parent fdb8f4b commit f9f6ff8

File tree

1 file changed

+46
-27
lines changed

1 file changed

+46
-27
lines changed

packages/firestore/test/integration/api/query.test.ts

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ apiDescribe('Queries', (persistence: boolean) => {
12911291

12921292
// eslint-disable-next-line no-restricted-properties
12931293
// Reproduces https://github.com/firebase/firebase-js-sdk/issues/5873
1294-
(persistence ? describe.only : describe.skip)('Caching empty results ', () => {
1294+
(persistence ? describe : describe.skip)('Caching empty results ', () => {
12951295
it('can cache empty query results', () => {
12961296
return withTestCollection(persistence, {}, async coll => {
12971297
const snapshot1 = await getDocs(coll); // Populate the cache
@@ -1321,39 +1321,58 @@ apiDescribe('Queries', (persistence: boolean) => {
13211321

13221322
// Add a snapshot listener whose first event should be raised from cache.
13231323
const storeEvent = new EventsAccumulator<QuerySnapshot>();
1324-
onSnapshot(
1325-
coll,
1326-
{ includeMetadataChanges: true },
1327-
storeEvent.storeEvent
1328-
);
1324+
onSnapshot(coll, storeEvent.storeEvent);
13291325
const snapshot2 = await storeEvent.awaitEvent();
13301326
expect(snapshot2.metadata.fromCache).to.be.true;
13311327
expect(toDataArray(snapshot2)).to.deep.equal([]);
1332-
1333-
// why this if fromCahe:false ????
1334-
const snapshot3 = await storeEvent.awaitEvent();
1335-
expect(snapshot3.metadata.fromCache).to.be.false;
1336-
expect(toDataArray(snapshot3)).to.deep.equal([]);
13371328
});
13381329
});
13391330

1340-
it('can add new doc to cached empty query result', () => {
1341-
return withTestCollection(persistence, {}, async coll => {
1342-
await getDocs(coll); // Populate the cache
1343-
1344-
const storeEvent = new EventsAccumulator<QuerySnapshot>();
1345-
onSnapshot(coll, storeEvent.storeEvent);
1346-
const snapshot1 = await storeEvent.awaitEvent();
1347-
expect(snapshot1.metadata.fromCache).to.be.true;
1348-
expect(toDataArray(snapshot1)).to.deep.equal([]);
1349-
1350-
await addDoc(coll, { key: 'a' });
1331+
it('can raise snapshot from a cached collection which was emptied offline', () => {
1332+
const testDocs = {
1333+
a: { key: 'a' }
1334+
};
1335+
return withTestCollection(
1336+
persistence,
1337+
testDocs,
1338+
async (coll, firestore) => {
1339+
await getDocs(coll); // Populate the cache
1340+
const storeEvent = new EventsAccumulator<QuerySnapshot>();
1341+
onSnapshot(coll, storeEvent.storeEvent);
1342+
await storeEvent.awaitEvent();
1343+
1344+
await disableNetwork(firestore);
1345+
deleteDoc(doc(coll, 'a'));
1346+
await enableNetwork(firestore);
1347+
1348+
const snapshot = await storeEvent.awaitEvent();
1349+
expect(snapshot.metadata.fromCache).to.be.true;
1350+
expect(toDataArray(snapshot)).to.deep.equal([]);
1351+
}
1352+
);
1353+
});
13511354

1352-
const snapshot2 = await storeEvent.awaitEvent();
1353-
expect(snapshot2.metadata.fromCache).to.be.true;
1354-
expect(toDataArray(snapshot2)).to.deep.equal([{ key: 'a' }]);
1355-
expect(snapshot2.metadata.hasPendingWrites).to.equal(true);
1356-
});
1355+
it('can register a listener and empty cache offline, and raise snaoshot from it when came back online', () => {
1356+
const testDocs = {
1357+
a: { key: 'a' }
1358+
};
1359+
return withTestCollection(
1360+
persistence,
1361+
testDocs,
1362+
async (coll, firestore) => {
1363+
await getDocs(coll); // Populate the cache
1364+
await disableNetwork(firestore);
1365+
const storeEvent = new EventsAccumulator<QuerySnapshot>();
1366+
onSnapshot(coll, storeEvent.storeEvent);
1367+
await storeEvent.awaitEvent();
1368+
deleteDoc(doc(coll, 'a'));
1369+
await enableNetwork(firestore);
1370+
1371+
const snapshot = await storeEvent.awaitEvent();
1372+
expect(snapshot.metadata.fromCache).to.be.true;
1373+
expect(toDataArray(snapshot)).to.deep.equal([]);
1374+
}
1375+
);
13571376
});
13581377
});
13591378
});

0 commit comments

Comments
 (0)