Skip to content

Commit

Permalink
Showing 6 changed files with 50 additions and 1 deletion.
10 changes: 10 additions & 0 deletions FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.h
Original file line number Diff line number Diff line change
@@ -57,8 +57,18 @@ didFailLoadAtIndex:(NSUInteger)index
*/
@interface FUIIndexCollectionViewDataSource : NSObject <UICollectionViewDataSource>

/**
* The delegate that should receive updates from this data source. Implement this delegate
* to handle load errors and successes.
*/
@property (nonatomic, readwrite, weak, nullable) id<FUIIndexCollectionViewDataSourceDelegate> delegate;

/**
* The indexes that have finished loading in the data source. Returns an empty array if no indexes
* have loaded.
*/
@property (nonatomic, readonly, copy) NSArray<FIRDataSnapshot *> *indexes;

- (instancetype)init NS_UNAVAILABLE;

/**
4 changes: 4 additions & 0 deletions FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.m
Original file line number Diff line number Diff line change
@@ -50,6 +50,10 @@ - (instancetype)initWithIndex:(FIRDatabaseQuery *)indexQuery
return self;
}

- (NSArray<FIRDataSnapshot *> *)indexes {
return self.array.indexes;
}

#pragma mark - FUIIndexArrayDelegate

- (void)array:(FUIIndexArray *)array
9 changes: 8 additions & 1 deletion FirebaseDatabaseUI/FUIIndexTableViewDataSource.h
Original file line number Diff line number Diff line change
@@ -58,10 +58,17 @@ didFailLoadAtIndex:(NSUInteger)index
@interface FUIIndexTableViewDataSource : NSObject <UITableViewDataSource>

/**
* The delegate that will receive events from this data source.
* The delegate that should receive updates from this data source. Implement this delegate
* to handle load errors and successes.
*/
@property (nonatomic, readwrite, weak, nullable) id<FUIIndexTableViewDataSourceDelegate> delegate;

/**
* The indexes that have finished loading in the data source. Returns an empty array if no indexes
* have loaded.
*/
@property (nonatomic, readonly, copy) NSArray<FIRDataSnapshot *> *indexes;

- (instancetype)init NS_UNAVAILABLE;

/**
4 changes: 4 additions & 0 deletions FirebaseDatabaseUI/FUIIndexTableViewDataSource.m
Original file line number Diff line number Diff line change
@@ -58,6 +58,10 @@ - (instancetype)initWithIndex:(FIRDatabaseQuery *)indexQuery
return self;
}

- (NSArray<FIRDataSnapshot *> *)indexes {
return self.array.indexes;
}

#pragma mark - FUIIndexArrayDelegate

- (void)array:(FUIIndexArray *)array
12 changes: 12 additions & 0 deletions FirebaseDatabaseUITests/FUIIndexCollectionViewDataSourceTest.m
Original file line number Diff line number Diff line change
@@ -93,6 +93,18 @@ - (void)tearDown {
[super tearDown];
}

- (void)testItReturnsItsArraysIndexes {
NSArray *expectedIndexes = @[
[FUIFakeSnapshot snapWithKey:@"1" value:@(YES)],
[FUIFakeSnapshot snapWithKey:@"2" value:@(YES)],
[FUIFakeSnapshot snapWithKey:@"3" value:@(YES)],
];

NSArray *indexes = self.dataSource.indexes;

XCTAssert([indexes isEqual:expectedIndexes], @"expected data source's indexes to equal its array's indexes");
}

- (void)testItPopulatesCells {
UICollectionViewCell *cell = [self.dataSource collectionView:self.collectionView
cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
12 changes: 12 additions & 0 deletions FirebaseDatabaseUITests/FUIIndexTableViewDataSourceTest.m
Original file line number Diff line number Diff line change
@@ -88,6 +88,18 @@ - (void)tearDown {
[super tearDown];
}

- (void)testItReturnsItsArraysIndexes {
NSArray *expectedIndexes = @[
[FUIFakeSnapshot snapWithKey:@"1" value:@(YES)],
[FUIFakeSnapshot snapWithKey:@"2" value:@(YES)],
[FUIFakeSnapshot snapWithKey:@"3" value:@(YES)],
];

NSArray *indexes = self.dataSource.indexes;

XCTAssert([indexes isEqual:expectedIndexes], @"expected data source's indexes to equal its array's indexes");
}

- (void)testItPopulatesCells {
UITableViewCell *cell = [self.dataSource tableView:self.tableView
cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];

0 comments on commit 1263bed

Please sign in to comment.