use of com.google.firebase.firestore.core.View.DocumentChanges in project firebase-android-sdk by firebase.
the class QueryListenerTest method testWillWaitForSyncIfOnline.
@Test
public void testWillWaitForSyncIfOnline() {
List<ViewSnapshot> events = new ArrayList<>();
Query query = Query.atPath(path("rooms"));
MutableDocument doc1 = doc("rooms/eros", 1, map("name", "eros"));
MutableDocument doc2 = doc("rooms/hades", 2, map("name", "hades"));
ListenOptions options = new ListenOptions();
options.waitForSyncWhenOnline = true;
QueryListener listener = queryListener(query, options, events);
View view = new View(query, DocumentKey.emptyKeySet());
ViewSnapshot snap1 = applyChanges(view, doc1);
ViewSnapshot snap2 = applyChanges(view, doc2);
DocumentChanges changes = view.computeDocChanges(docUpdates());
ViewSnapshot snap3 = view.applyChanges(changes, ackTarget(doc1, doc2)).getSnapshot();
// no event
listener.onOnlineStateChanged(OnlineState.ONLINE);
// no event
listener.onViewSnapshot(snap1);
// no event
listener.onOnlineStateChanged(OnlineState.UNKNOWN);
// no event
listener.onOnlineStateChanged(OnlineState.ONLINE);
// no event
listener.onViewSnapshot(snap2);
// event because synced
listener.onViewSnapshot(snap3);
DocumentViewChange change1 = DocumentViewChange.create(Type.ADDED, doc1);
DocumentViewChange change2 = DocumentViewChange.create(Type.ADDED, doc2);
ViewSnapshot expectedSnapshot = new ViewSnapshot(snap3.getQuery(), snap3.getDocuments(), DocumentSet.emptySet(snap3.getQuery().comparator()), asList(change1, change2), /* isFromCache= */
false, snap3.getMutatedKeys(), /* didSyncStateChange= */
true, /* excludesMetadataChanges= */
true);
assertEquals(asList(expectedSnapshot), events);
}
Aggregations