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