From 003551e98c13a7d8041bf58e2c050eb41c4f875c Mon Sep 17 00:00:00 2001 From: Morgan Chen Date: Thu, 9 Mar 2017 10:01:26 -0800 Subject: [PATCH] expose FUIIndexArray's indexes in data sources --- .../FUIIndexCollectionViewDataSource.h | 10 ++++++++++ .../FUIIndexCollectionViewDataSource.m | 4 ++++ FirebaseDatabaseUI/FUIIndexTableViewDataSource.h | 9 ++++++++- FirebaseDatabaseUI/FUIIndexTableViewDataSource.m | 4 ++++ .../FUIIndexCollectionViewDataSourceTest.m | 12 ++++++++++++ .../FUIIndexTableViewDataSourceTest.m | 12 ++++++++++++ 6 files changed, 50 insertions(+), 1 deletion(-) diff --git a/FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.h b/FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.h index bc2093cb4af..9f0991af5c8 100644 --- a/FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.h +++ b/FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.h @@ -57,8 +57,18 @@ didFailLoadAtIndex:(NSUInteger)index */ @interface FUIIndexCollectionViewDataSource : NSObject +/** + * 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 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 *indexes; + - (instancetype)init NS_UNAVAILABLE; /** diff --git a/FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.m b/FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.m index 923c004af08..97cd70aba57 100644 --- a/FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.m +++ b/FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.m @@ -50,6 +50,10 @@ - (instancetype)initWithIndex:(FIRDatabaseQuery *)indexQuery return self; } +- (NSArray *)indexes { + return self.array.indexes; +} + #pragma mark - FUIIndexArrayDelegate - (void)array:(FUIIndexArray *)array diff --git a/FirebaseDatabaseUI/FUIIndexTableViewDataSource.h b/FirebaseDatabaseUI/FUIIndexTableViewDataSource.h index 9f035378091..4f0974ff7fe 100644 --- a/FirebaseDatabaseUI/FUIIndexTableViewDataSource.h +++ b/FirebaseDatabaseUI/FUIIndexTableViewDataSource.h @@ -58,10 +58,17 @@ didFailLoadAtIndex:(NSUInteger)index @interface FUIIndexTableViewDataSource : NSObject /** - * 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 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 *indexes; + - (instancetype)init NS_UNAVAILABLE; /** diff --git a/FirebaseDatabaseUI/FUIIndexTableViewDataSource.m b/FirebaseDatabaseUI/FUIIndexTableViewDataSource.m index 33f188a5e25..4ff9df08abc 100644 --- a/FirebaseDatabaseUI/FUIIndexTableViewDataSource.m +++ b/FirebaseDatabaseUI/FUIIndexTableViewDataSource.m @@ -58,6 +58,10 @@ - (instancetype)initWithIndex:(FIRDatabaseQuery *)indexQuery return self; } +- (NSArray *)indexes { + return self.array.indexes; +} + #pragma mark - FUIIndexArrayDelegate - (void)array:(FUIIndexArray *)array diff --git a/FirebaseDatabaseUITests/FUIIndexCollectionViewDataSourceTest.m b/FirebaseDatabaseUITests/FUIIndexCollectionViewDataSourceTest.m index a4813257af2..6941cd12090 100644 --- a/FirebaseDatabaseUITests/FUIIndexCollectionViewDataSourceTest.m +++ b/FirebaseDatabaseUITests/FUIIndexCollectionViewDataSourceTest.m @@ -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]]; diff --git a/FirebaseDatabaseUITests/FUIIndexTableViewDataSourceTest.m b/FirebaseDatabaseUITests/FUIIndexTableViewDataSourceTest.m index bee945e138e..3072df7439d 100644 --- a/FirebaseDatabaseUITests/FUIIndexTableViewDataSourceTest.m +++ b/FirebaseDatabaseUITests/FUIIndexTableViewDataSourceTest.m @@ -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]];