@@ -804,6 +804,98 @@ - (void)testCollectionGroupQueriesWithStartAtEndAtWithArbitraryDocumentIDs {
804
804
XCTAssertEqualObjects (ids, (@[ @" cg-doc2" ]));
805
805
}
806
806
807
+ - (void )testSnapshotListenerSortsQueryByDocumentIdInTheSameOrderAsServer {
808
+ FIRCollectionReference *collRef = [self collectionRefWithDocuments: @{
809
+ @" A" : @{@" a" : @1 },
810
+ @" a" : @{@" a" : @1 },
811
+ @" Aa" : @{@" a" : @1 },
812
+ @" 7" : @{@" a" : @1 },
813
+ @" 12" : @{@" a" : @1 },
814
+ @" __id7__" : @{@" a" : @1 },
815
+ @" __id12__" : @{@" a" : @1 },
816
+ @" __id-2__" : @{@" a" : @1 },
817
+ @" __id1_" : @{@" a" : @1 },
818
+ @" _id1__" : @{@" a" : @1 },
819
+ @" __id" : @{@" a" : @1 },
820
+ @" __id9223372036854775807__" : @{@" a" : @1 },
821
+ @" __id-9223372036854775808__" : @{@" a" : @1 },
822
+ }];
823
+
824
+ FIRQuery *query = [collRef queryOrderedByFieldPath: [FIRFieldPath documentID ]];
825
+ NSArray <NSString *> *expectedDocs = @[
826
+ @" __id-9223372036854775808__" , @" __id-2__" , @" __id7__" , @" __id12__" ,
827
+ @" __id9223372036854775807__" , @" 12" , @" 7" , @" A" , @" Aa" , @" __id" , @" __id1_" , @" _id1__" , @" a"
828
+ ];
829
+ FIRQuerySnapshot *getSnapshot = [self readDocumentSetForRef: query];
830
+ XCTAssertEqualObjects (FIRQuerySnapshotGetIDs (getSnapshot), expectedDocs);
831
+
832
+ id <FIRListenerRegistration> registration =
833
+ [query addSnapshotListener: self .eventAccumulator.valueEventHandler];
834
+ FIRQuerySnapshot *watchSnapshot = [self .eventAccumulator awaitEventWithName: @" Snapshot" ];
835
+ XCTAssertEqualObjects (FIRQuerySnapshotGetIDs (watchSnapshot), expectedDocs);
836
+
837
+ [registration remove ];
838
+ }
839
+
840
+ - (void )testSnapshotListenerSortsFilteredQueryByDocumentIdInTheSameOrderAsServer {
841
+ FIRCollectionReference *collRef = [self collectionRefWithDocuments: @{
842
+ @" A" : @{@" a" : @1 },
843
+ @" a" : @{@" a" : @1 },
844
+ @" Aa" : @{@" a" : @1 },
845
+ @" 7" : @{@" a" : @1 },
846
+ @" 12" : @{@" a" : @1 },
847
+ @" __id7__" : @{@" a" : @1 },
848
+ @" __id12__" : @{@" a" : @1 },
849
+ @" __id-2__" : @{@" a" : @1 },
850
+ @" __id1_" : @{@" a" : @1 },
851
+ @" _id1__" : @{@" a" : @1 },
852
+ @" __id" : @{@" a" : @1 },
853
+ @" __id9223372036854775807__" : @{@" a" : @1 },
854
+ @" __id-9223372036854775808__" : @{@" a" : @1 },
855
+ }];
856
+
857
+ FIRQuery *query = [[[collRef queryWhereFieldPath: [FIRFieldPath documentID ]
858
+ isGreaterThan: @" __id7__" ]
859
+ queryWhereFieldPath: [FIRFieldPath documentID ]
860
+ isLessThanOrEqualTo: @" A" ] queryOrderedByFieldPath: [FIRFieldPath documentID ]];
861
+ NSArray <NSString *> *expectedDocs =
862
+ @[ @" __id12__" , @" __id9223372036854775807__" , @" 12" , @" 7" , @" A" ];
863
+ FIRQuerySnapshot *getSnapshot = [self readDocumentSetForRef: query];
864
+ XCTAssertEqualObjects (FIRQuerySnapshotGetIDs (getSnapshot), expectedDocs);
865
+
866
+ id <FIRListenerRegistration> registration =
867
+ [query addSnapshotListener: self .eventAccumulator.valueEventHandler];
868
+ FIRQuerySnapshot *watchSnapshot = [self .eventAccumulator awaitEventWithName: @" Snapshot" ];
869
+ XCTAssertEqualObjects (FIRQuerySnapshotGetIDs (watchSnapshot), expectedDocs);
870
+
871
+ [registration remove ];
872
+ }
873
+
874
+ - (void )testSdkOrdersQueryByDocumentIdTheSameWayOnlineAndOffline {
875
+ FIRCollectionReference *collRef = [self collectionRefWithDocuments: @{
876
+ @" A" : @{@" a" : @1 },
877
+ @" a" : @{@" a" : @1 },
878
+ @" Aa" : @{@" a" : @1 },
879
+ @" 7" : @{@" a" : @1 },
880
+ @" 12" : @{@" a" : @1 },
881
+ @" __id7__" : @{@" a" : @1 },
882
+ @" __id12__" : @{@" a" : @1 },
883
+ @" __id-2__" : @{@" a" : @1 },
884
+ @" __id1_" : @{@" a" : @1 },
885
+ @" _id1__" : @{@" a" : @1 },
886
+ @" __id" : @{@" a" : @1 },
887
+ @" __id9223372036854775807__" : @{@" a" : @1 },
888
+ @" __id-9223372036854775808__" : @{@" a" : @1 },
889
+ }];
890
+
891
+ [self checkOnlineAndOfflineQuery: [collRef queryOrderedByFieldPath: [FIRFieldPath documentID ]]
892
+ matchesResult: @[
893
+ @" __id-9223372036854775808__" , @" __id-2__" , @" __id7__" , @" __id12__" ,
894
+ @" __id9223372036854775807__" , @" 12" , @" 7" , @" A" , @" Aa" , @" __id" , @" __id1_" ,
895
+ @" _id1__" , @" a"
896
+ ]];
897
+ }
898
+
807
899
- (void )testCollectionGroupQueriesWithWhereFiltersOnArbitraryDocumentIDs {
808
900
// Use .document() to get a random collection group name to use but ensure it starts with 'b'
809
901
// for predictable ordering.
0 commit comments