use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class ViewTest method testRemovesKeysFromMutatedDocumentKeysWhenNewDocDoesNotHaveChanges.
@Test
public void testRemovesKeysFromMutatedDocumentKeysWhenNewDocDoesNotHaveChanges() {
Query query = messageQuery().limitToFirst(2);
MutableDocument doc1 = doc("rooms/eros/messages/0", 0, map());
MutableDocument doc2 = doc("rooms/eros/messages/1", 0, map()).setHasLocalMutations();
View view = new View(query, DocumentKey.emptyKeySet());
// Start with a full view.
View.DocumentChanges changes = view.computeDocChanges(docUpdates(doc1, doc2));
view.applyChanges(changes);
assertEquals(keySet(doc2.getKey()), changes.mutatedKeys);
MutableDocument doc2Prime = doc("rooms/eros/messages/1", 0, map());
changes = view.computeDocChanges(docUpdates(doc2Prime));
view.applyChanges(changes);
assertEquals(keySet(), changes.mutatedKeys);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class ViewTest method testReturnsNilIfNoChange.
@Test
public void testReturnsNilIfNoChange() {
Query query = messageQuery();
View view = new View(query, DocumentKey.emptyKeySet());
MutableDocument doc1 = doc("rooms/eros/messages/1", 0, map("text", "msg1"));
MutableDocument doc2 = doc("rooms/eros/messages/2", 0, map("text", "msg2"));
// initial state
applyChanges(view, doc1, doc2);
ViewSnapshot snapshot = applyChanges(view, doc1, doc2).getSnapshot();
assertNull(snapshot);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class ViewTest method testDoesNotNeedRefillOnReorderWithinLimit.
@Test
public void testDoesNotNeedRefillOnReorderWithinLimit() {
Query query = messageQuery().orderBy(orderBy("order")).limitToFirst(3);
MutableDocument doc1 = doc("rooms/eros/messages/0", 0, map("order", 1));
MutableDocument doc2 = doc("rooms/eros/messages/1", 0, map("order", 2));
MutableDocument doc3 = doc("rooms/eros/messages/2", 0, map("order", 3));
MutableDocument doc4 = doc("rooms/eros/messages/3", 0, map("order", 4));
MutableDocument doc5 = doc("rooms/eros/messages/4", 0, map("order", 5));
View view = new View(query, DocumentKey.emptyKeySet());
// Start with a full view.
View.DocumentChanges changes = view.computeDocChanges(docUpdates(doc1, doc2, doc3, doc4, doc5));
assertEquals(3, changes.documentSet.size());
assertFalse(changes.needsRefill());
assertEquals(3, changes.changeSet.getChanges().size());
view.applyChanges(changes);
// Move one of the docs.
doc1 = doc("rooms/eros/messages/0", 1, map("order", 3));
changes = view.computeDocChanges(docUpdates(doc1));
assertEquals(3, changes.documentSet.size());
assertFalse(changes.needsRefill());
assertEquals(1, changes.changeSet.getChanges().size());
view.applyChanges(changes);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class ViewTest method testReturnsNeedsRefillOnDeleteInLimitQuery.
@Test
public void testReturnsNeedsRefillOnDeleteInLimitQuery() {
Query query = messageQuery().limitToFirst(2);
MutableDocument doc1 = doc("rooms/eros/messages/0", 0, map());
MutableDocument doc2 = doc("rooms/eros/messages/1", 0, map());
View view = new View(query, DocumentKey.emptyKeySet());
// Start with a full view.
View.DocumentChanges changes = view.computeDocChanges(docUpdates(doc1, doc2));
assertEquals(2, changes.documentSet.size());
assertFalse(changes.needsRefill());
assertEquals(2, changes.changeSet.getChanges().size());
view.applyChanges(changes);
// Remove one of the docs.
changes = view.computeDocChanges(docUpdates(deletedDoc("rooms/eros/messages/0", 0)));
assertEquals(1, changes.documentSet.size());
assertTrue(changes.needsRefill());
assertEquals(1, changes.changeSet.getChanges().size());
// Refill it with just the one doc remaining.
changes = view.computeDocChanges(docUpdates(doc2), changes);
assertEquals(1, changes.documentSet.size());
assertFalse(changes.needsRefill());
assertEquals(1, changes.changeSet.getChanges().size());
view.applyChanges(changes);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class ViewTest method testDoesNotReportChangesForDocumentBeyondLimit.
@Test
public void testDoesNotReportChangesForDocumentBeyondLimit() {
Query query = messageQuery().orderBy(orderBy("num")).limitToFirst(2);
View view = new View(query, DocumentKey.emptyKeySet());
MutableDocument doc1 = doc("rooms/eros/messages/1", 0, map("num", 1));
MutableDocument doc2 = doc("rooms/eros/messages/2", 0, map("num", 2));
MutableDocument doc3 = doc("rooms/eros/messages/3", 0, map("num", 3));
MutableDocument doc4 = doc("rooms/eros/messages/4", 0, map("num", 4));
applyChanges(view, doc1, doc2);
// change doc2 to 5, and add doc3 and doc4.
// doc2 will be modified + removed = removed
// doc3 will be added
// doc4 will be added + removed = nothing
doc2 = doc("rooms/eros/messages/2", 1, map("num", 5));
View.DocumentChanges viewDocChanges = view.computeDocChanges(docUpdates(doc2, doc3, doc4));
assertTrue(viewDocChanges.needsRefill());
// Verify that all the docs still match.
viewDocChanges = view.computeDocChanges(docUpdates(doc1, doc2, doc3, doc4), viewDocChanges);
ViewSnapshot snapshot = view.applyChanges(viewDocChanges, ackTarget(doc1, doc2, doc3, doc4)).getSnapshot();
assertEquals(query, snapshot.getQuery());
assertEquals(asList(doc1, doc3), snapshot.getDocuments().toList());
assertEquals(asList(DocumentViewChange.create(Type.REMOVED, doc2), DocumentViewChange.create(Type.ADDED, doc3)), snapshot.getChanges());
assertFalse(snapshot.isFromCache());
assertTrue(snapshot.didSyncStateChange());
}
Aggregations