Skip to content

Commit 5a01e5d

Browse files
committed
expose index array's loaded indexes
1 parent 9477dea commit 5a01e5d

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

FirebaseDatabaseUI/FUIIndexArray.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ didFailLoadWithError:(NSError *)error;
118118
*/
119119
@property(nonatomic, copy, readonly) NSArray<FIRDataSnapshot *> *items;
120120

121+
/**
122+
* An immutable copy of the loaded indexes in the array. Returns an empty
123+
* array if no indexes have loaded.
124+
*/
125+
@property(nonatomic, copy, readonly) NSArray<FIRDataSnapshot *> *indexes;
126+
121127
/**
122128
* The delegate that this array should forward events to.
123129
*/

FirebaseDatabaseUI/FUIIndexArray.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ - (void)observeQueries {
7474
[_indexArray observeQuery];
7575
}
7676

77-
- (NSArray <FIRDataSnapshot *> *)items {
77+
- (NSArray<FIRDataSnapshot *> *)items {
7878
NSArray *observers = [self.observers copy];
7979
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:observers.count];
8080
for (FUIQueryObserver *observer in observers) {
@@ -85,6 +85,10 @@ - (void)observeQueries {
8585
return [array copy];
8686
}
8787

88+
- (NSArray<FIRDataSnapshot *> *) indexes {
89+
return self.indexArray.items;
90+
}
91+
8892
- (NSUInteger)count {
8993
return self.observers.count;
9094
}

FirebaseDatabaseUITests/FUIIndexArrayTest.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,23 @@ - (void)tearDown {
7474
}
7575

7676
- (void)testItHasContents {
77+
NSArray *indexes = self.array.indexes;
7778
NSArray *items = self.array.items;
7879

79-
NSArray *expected = @[
80+
NSArray *expectedIndexes = @[
81+
[FUIFakeSnapshot snapWithKey:@"1" value:@(YES)],
82+
[FUIFakeSnapshot snapWithKey:@"2" value:@(YES)],
83+
[FUIFakeSnapshot snapWithKey:@"3" value:@(YES)],
84+
];
85+
86+
NSArray *expectedContents = @[
8087
[FUIFakeSnapshot snapWithKey:@"data" value:@"1"],
8188
[FUIFakeSnapshot snapWithKey:@"data" value:@"2"],
8289
[FUIFakeSnapshot snapWithKey:@"data" value:@"3"],
8390
];
8491

85-
XCTAssertEqualObjects(items, expected, @"expected contents to equal %@", expected);
92+
XCTAssertEqualObjects(indexes, expectedIndexes, @"expected indexes to equal %@", expectedIndexes);
93+
XCTAssertEqualObjects(items, expectedContents, @"expected contents to equal %@", expectedContents);
8694
}
8795

8896
- (void)testItUpdatesOnInsertion {

0 commit comments

Comments
 (0)