diff --git a/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm b/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm index b1cd36a5c49..0b92a36ea48 100644 --- a/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm +++ b/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm @@ -896,6 +896,142 @@ - (void)testSdkOrdersQueryByDocumentIdTheSameWayOnlineAndOffline { ]]; } +- (void)testSnapshotListenerSortsUnicodeStringsInTheSameOrderAsServer { + FIRCollectionReference *collRef = [self collectionRefWithDocuments:@{ + @"a" : @{@"value" : @"Łukasiewicz"}, + @"b" : @{@"value" : @"Sierpiński"}, + @"c" : @{@"value" : @"岩澤"}, + @"d" : @{@"value" : @"🄟"}, + @"e" : @{@"value" : @"P"}, + @"f" : @{@"value" : @"︒"}, + @"g" : @{@"value" : @"🐵"} + + }]; + + FIRQuery *query = [collRef queryOrderedByField:@"value"]; + NSArray *expectedDocs = @[ @"b", @"a", @"c", @"f", @"e", @"d", @"g" ]; + FIRQuerySnapshot *getSnapshot = [self readDocumentSetForRef:query]; + XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(getSnapshot), expectedDocs); + + id registration = + [query addSnapshotListener:self.eventAccumulator.valueEventHandler]; + FIRQuerySnapshot *watchSnapshot = [self.eventAccumulator awaitEventWithName:@"Snapshot"]; + XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(watchSnapshot), expectedDocs); + + [registration remove]; + + [self checkOnlineAndOfflineQuery:query matchesResult:expectedDocs]; +} + +- (void)testSnapshotListenerSortsUnicodeStringsInArrayInTheSameOrderAsServer { + FIRCollectionReference *collRef = [self collectionRefWithDocuments:@{ + @"a" : @{@"value" : @[ @"Łukasiewicz" ]}, + @"b" : @{@"value" : @[ @"Sierpiński" ]}, + @"c" : @{@"value" : @[ @"岩澤" ]}, + @"d" : @{@"value" : @[ @"🄟" ]}, + @"e" : @{@"value" : @[ @"P" ]}, + @"f" : @{@"value" : @[ @"︒" ]}, + @"g" : @{@"value" : @[ @"🐵" ]} + + }]; + + FIRQuery *query = [collRef queryOrderedByField:@"value"]; + NSArray *expectedDocs = @[ @"b", @"a", @"c", @"f", @"e", @"d", @"g" ]; + FIRQuerySnapshot *getSnapshot = [self readDocumentSetForRef:query]; + XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(getSnapshot), expectedDocs); + + id registration = + [query addSnapshotListener:self.eventAccumulator.valueEventHandler]; + FIRQuerySnapshot *watchSnapshot = [self.eventAccumulator awaitEventWithName:@"Snapshot"]; + XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(watchSnapshot), expectedDocs); + + [registration remove]; + + [self checkOnlineAndOfflineQuery:query matchesResult:expectedDocs]; +} + +- (void)testSnapshotListenerSortsUnicodeStringsInMapInTheSameOrderAsServer { + FIRCollectionReference *collRef = [self collectionRefWithDocuments:@{ + @"a" : @{@"value" : @{@"foo" : @"Łukasiewicz"}}, + @"b" : @{@"value" : @{@"foo" : @"Sierpiński"}}, + @"c" : @{@"value" : @{@"foo" : @"岩澤"}}, + @"d" : @{@"value" : @{@"foo" : @"🄟"}}, + @"e" : @{@"value" : @{@"foo" : @"P"}}, + @"f" : @{@"value" : @{@"foo" : @"︒"}}, + @"g" : @{@"value" : @{@"foo" : @"🐵"}} + + }]; + + FIRQuery *query = [collRef queryOrderedByField:@"value"]; + NSArray *expectedDocs = @[ @"b", @"a", @"c", @"f", @"e", @"d", @"g" ]; + FIRQuerySnapshot *getSnapshot = [self readDocumentSetForRef:query]; + XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(getSnapshot), expectedDocs); + + id registration = + [query addSnapshotListener:self.eventAccumulator.valueEventHandler]; + FIRQuerySnapshot *watchSnapshot = [self.eventAccumulator awaitEventWithName:@"Snapshot"]; + XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(watchSnapshot), expectedDocs); + + [registration remove]; + + [self checkOnlineAndOfflineQuery:query matchesResult:expectedDocs]; +} + +- (void)testSnapshotListenerSortsUnicodeStringsInMapKeyInTheSameOrderAsServer { + FIRCollectionReference *collRef = [self collectionRefWithDocuments:@{ + @"a" : @{@"value" : @{@"Łukasiewicz" : @"foo"}}, + @"b" : @{@"value" : @{@"Sierpiński" : @"foo"}}, + @"c" : @{@"value" : @{@"岩澤" : @"foo"}}, + @"d" : @{@"value" : @{@"🄟" : @"foo"}}, + @"e" : @{@"value" : @{@"P" : @"foo"}}, + @"f" : @{@"value" : @{@"︒" : @"foo"}}, + @"g" : @{@"value" : @{@"🐵" : @"foo"}} + + }]; + + FIRQuery *query = [collRef queryOrderedByField:@"value"]; + NSArray *expectedDocs = @[ @"b", @"a", @"c", @"f", @"e", @"d", @"g" ]; + FIRQuerySnapshot *getSnapshot = [self readDocumentSetForRef:query]; + XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(getSnapshot), expectedDocs); + + id registration = + [query addSnapshotListener:self.eventAccumulator.valueEventHandler]; + FIRQuerySnapshot *watchSnapshot = [self.eventAccumulator awaitEventWithName:@"Snapshot"]; + XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(watchSnapshot), expectedDocs); + + [registration remove]; + + [self checkOnlineAndOfflineQuery:query matchesResult:expectedDocs]; +} + +- (void)testSnapshotListenerSortsUnicodeStringsInDocumentKeyInTheSameOrderAsServer { + FIRCollectionReference *collRef = [self collectionRefWithDocuments:@{ + @"Łukasiewicz" : @{@"value" : @"foo"}, + @"Sierpiński" : @{@"value" : @"foo"}, + @"岩澤" : @{@"value" : @"foo"}, + @"🄟" : @{@"value" : @"foo"}, + @"P" : @{@"value" : @"foo"}, + @"︒" : @{@"value" : @"foo"}, + @"🐵" : @{@"value" : @"foo"} + + }]; + + FIRQuery *query = [collRef queryOrderedByFieldPath:[FIRFieldPath documentID]]; + NSArray *expectedDocs = + @[ @"Sierpiński", @"Łukasiewicz", @"岩澤", @"︒", @"P", @"🄟", @"🐵" ]; + FIRQuerySnapshot *getSnapshot = [self readDocumentSetForRef:query]; + XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(getSnapshot), expectedDocs); + + id registration = + [query addSnapshotListener:self.eventAccumulator.valueEventHandler]; + FIRQuerySnapshot *watchSnapshot = [self.eventAccumulator awaitEventWithName:@"Snapshot"]; + XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(watchSnapshot), expectedDocs); + + [registration remove]; + + [self checkOnlineAndOfflineQuery:query matchesResult:expectedDocs]; +} + - (void)testCollectionGroupQueriesWithWhereFiltersOnArbitraryDocumentIDs { // Use .document() to get a random collection group name to use but ensure it starts with 'b' // for predictable ordering.