@@ -641,6 +641,76 @@ - (void)testRemembersLocalMutationsFromPreviousCallToComputeChangesWithDocuments
641
641
XCTAssertEqual (changes.mutatedKeys , (DocumentKeySet{doc2.key }));
642
642
}
643
643
644
+ - (void )testRaisesHasPendingWritesForPendingMutationsInInitialSnapshot {
645
+ FSTQuery *query = [self queryForMessages ];
646
+ FSTDocument *doc1 = FSTTestDoc (" rooms/eros/messages/1" , 0 , @{}, FSTDocumentStateLocalMutations);
647
+ FSTView *view = [[FSTView alloc ] initWithQuery: query remoteDocuments: DocumentKeySet{}];
648
+ FSTViewDocumentChanges *changes = [view computeChangesWithDocuments: FSTTestDocUpdates (@[ doc1 ])];
649
+ FSTViewChange *viewChange = [view applyChangesToDocuments: changes];
650
+ XCTAssertTrue (viewChange.snapshot .hasPendingWrites );
651
+ }
652
+
653
+ - (void )testDoesntRaiseHasPendingWritesForCommittedMutationsInInitialSnapshot {
654
+ FSTQuery *query = [self queryForMessages ];
655
+ FSTDocument *doc1 =
656
+ FSTTestDoc (" rooms/eros/messages/1" , 0 , @{}, FSTDocumentStateCommittedMutations);
657
+ FSTView *view = [[FSTView alloc ] initWithQuery: query remoteDocuments: DocumentKeySet{}];
658
+ FSTViewDocumentChanges *changes = [view computeChangesWithDocuments: FSTTestDocUpdates (@[ doc1 ])];
659
+ FSTViewChange *viewChange = [view applyChangesToDocuments: changes];
660
+ XCTAssertFalse (viewChange.snapshot .hasPendingWrites );
661
+ }
662
+
663
+ - (void )testSuppressesWriteAcknowledgementIfWatchHasNotCaughtUp {
664
+ // This test verifies that we don't get three events for an FSTServerTimestamp mutation. We
665
+ // suppress the event generated by the write acknowledgement and instead wait for Watch to catch
666
+ // up.
667
+
668
+ FSTQuery *query = [self queryForMessages ];
669
+ FSTDocument *doc1 = FSTTestDoc (" rooms/eros/messages/1" , 1 ,
670
+ @{@" time" : @1 }, FSTDocumentStateLocalMutations);
671
+ FSTDocument *doc1Committed = FSTTestDoc (" rooms/eros/messages/1" , 2 ,
672
+ @{@" time" : @2 }, FSTDocumentStateCommittedMutations);
673
+ FSTDocument *doc1Acknowledged = FSTTestDoc (" rooms/eros/messages/1" , 2 ,
674
+ @{@" time" : @2 }, FSTDocumentStateSynced);
675
+ FSTDocument *doc2 = FSTTestDoc (" rooms/eros/messages/2" , 1 ,
676
+ @{@" time" : @1 }, FSTDocumentStateLocalMutations);
677
+ FSTDocument *doc2Modified = FSTTestDoc (" rooms/eros/messages/2" , 2 ,
678
+ @{@" time" : @3 }, FSTDocumentStateLocalMutations);
679
+ FSTDocument *doc2Acknowledged = FSTTestDoc (" rooms/eros/messages/2" , 2 ,
680
+ @{@" time" : @3 }, FSTDocumentStateSynced);
681
+ FSTView *view = [[FSTView alloc ] initWithQuery: query remoteDocuments: DocumentKeySet{}];
682
+ FSTViewDocumentChanges *changes =
683
+ [view computeChangesWithDocuments: FSTTestDocUpdates (@[ doc1, doc2 ])];
684
+ FSTViewChange *viewChange = [view applyChangesToDocuments: changes];
685
+
686
+ XCTAssertEqualObjects (
687
+ (@[
688
+ [FSTDocumentViewChange changeWithDocument: doc1 type: FSTDocumentViewChangeTypeAdded],
689
+ [FSTDocumentViewChange changeWithDocument: doc2 type: FSTDocumentViewChangeTypeAdded]
690
+ ]),
691
+ viewChange.snapshot .documentChanges );
692
+
693
+ changes = [view computeChangesWithDocuments: FSTTestDocUpdates (@[ doc1Committed, doc2Modified ])];
694
+ viewChange = [view applyChangesToDocuments: changes];
695
+ // The 'doc1Committed' update is suppressed
696
+ XCTAssertEqualObjects (
697
+ (@[ [FSTDocumentViewChange changeWithDocument: doc2Modified
698
+ type: FSTDocumentViewChangeTypeModified] ]),
699
+ viewChange.snapshot .documentChanges );
700
+
701
+ changes =
702
+ [view computeChangesWithDocuments: FSTTestDocUpdates (@[ doc1Acknowledged, doc2Acknowledged ])];
703
+ viewChange = [view applyChangesToDocuments: changes];
704
+ XCTAssertEqualObjects (
705
+ (@[
706
+ [FSTDocumentViewChange changeWithDocument: doc1Acknowledged
707
+ type: FSTDocumentViewChangeTypeModified],
708
+ [FSTDocumentViewChange changeWithDocument: doc2Acknowledged
709
+ type: FSTDocumentViewChangeTypeMetadata]
710
+ ]),
711
+ viewChange.snapshot .documentChanges );
712
+ }
713
+
644
714
@end
645
715
646
716
NS_ASSUME_NONNULL_END
0 commit comments