Clean up and test registration of internal supplementary node kinds

This commit is contained in:
Levi McCallum
2015-10-12 18:59:27 -07:00
parent 12194199cd
commit 9a37538582
2 changed files with 25 additions and 10 deletions

View File

@@ -33,8 +33,7 @@
_pendingNodes = [NSMutableDictionary dictionary]; _pendingNodes = [NSMutableDictionary dictionary];
_pendingIndexPaths = [NSMutableDictionary dictionary]; _pendingIndexPaths = [NSMutableDictionary dictionary];
NSArray *elementKinds = [self.collectionDataSource supplementaryNodeKindsInDataController:self]; [[self supplementaryKinds] enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
[elementKinds enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
LOG(@"Populating elements of kind: %@", kind); LOG(@"Populating elements of kind: %@", kind);
NSMutableArray *indexPaths = [NSMutableArray array]; NSMutableArray *indexPaths = [NSMutableArray array];
NSMutableArray *nodes = [NSMutableArray array]; NSMutableArray *nodes = [NSMutableArray array];
@@ -76,8 +75,7 @@
- (void)prepareForInsertSections:(NSIndexSet *)sections - (void)prepareForInsertSections:(NSIndexSet *)sections
{ {
NSArray *elementKinds = [self.collectionDataSource supplementaryNodeKindsInDataController:self]; [[self supplementaryKinds] enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
[elementKinds enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
LOG(@"Populating elements of kind: %@, for sections: %@", kind, sections); LOG(@"Populating elements of kind: %@, for sections: %@", kind, sections);
NSMutableArray *nodes = [NSMutableArray array]; NSMutableArray *nodes = [NSMutableArray array];
NSMutableArray *indexPaths = [NSMutableArray array]; NSMutableArray *indexPaths = [NSMutableArray array];
@@ -107,8 +105,7 @@
- (void)willDeleteSections:(NSIndexSet *)sections - (void)willDeleteSections:(NSIndexSet *)sections
{ {
NSArray *elementKinds = [self.collectionDataSource supplementaryNodeKindsInDataController:self]; [[self supplementaryKinds] enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
[elementKinds enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet([self editingNodesOfKind:kind], sections); NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet([self editingNodesOfKind:kind], sections);
[self deleteNodesOfKind:kind atIndexPaths:indexPaths completion:nil]; [self deleteNodesOfKind:kind atIndexPaths:indexPaths completion:nil];
@@ -118,8 +115,7 @@
- (void)prepareForReloadSections:(NSIndexSet *)sections - (void)prepareForReloadSections:(NSIndexSet *)sections
{ {
NSArray *elementKinds = [self.collectionDataSource supplementaryNodeKindsInDataController:self]; [[self supplementaryKinds] enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
[elementKinds enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
NSMutableArray *nodes = [NSMutableArray array]; NSMutableArray *nodes = [NSMutableArray array];
NSMutableArray *indexPaths = [NSMutableArray array]; NSMutableArray *indexPaths = [NSMutableArray array];
[self _populateSupplementaryNodesOfKind:kind withSections:sections mutableNodes:nodes mutableIndexPaths:indexPaths]; [self _populateSupplementaryNodesOfKind:kind withSections:sections mutableNodes:nodes mutableIndexPaths:indexPaths];
@@ -145,8 +141,7 @@
- (void)willMoveSection:(NSInteger)section toSection:(NSInteger)newSection - (void)willMoveSection:(NSInteger)section toSection:(NSInteger)newSection
{ {
NSArray *elementKinds = [self.collectionDataSource supplementaryNodeKindsInDataController:self]; [[self supplementaryKinds] enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
[elementKinds enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet([self editingNodesOfKind:kind], [NSIndexSet indexSetWithIndex:section]); NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet([self editingNodesOfKind:kind], [NSIndexSet indexSetWithIndex:section]);
NSArray *nodes = ASFindElementsInMultidimensionalArrayAtIndexPaths([self editingNodesOfKind:kind], indexPaths); NSArray *nodes = ASFindElementsInMultidimensionalArrayAtIndexPaths([self editingNodesOfKind:kind], indexPaths);
[self deleteNodesOfKind:kind atIndexPaths:indexPaths completion:nil]; [self deleteNodesOfKind:kind atIndexPaths:indexPaths completion:nil];
@@ -209,6 +204,11 @@
#pragma mark - Private Helpers #pragma mark - Private Helpers
- (NSArray *)supplementaryKinds
{
return [self.collectionDataSource supplementaryNodeKindsInDataController:self];
}
- (id<ASCollectionDataControllerSource>)collectionDataSource - (id<ASCollectionDataControllerSource>)collectionDataSource
{ {
return (id<ASCollectionDataControllerSource>)self.dataSource; return (id<ASCollectionDataControllerSource>)self.dataSource;

View File

@@ -7,6 +7,7 @@
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#import "ASCollectionView.h" #import "ASCollectionView.h"
#import "ASCollectionDataController.h"
#import "ASCollectionViewFlowLayoutInspector.h" #import "ASCollectionViewFlowLayoutInspector.h"
@interface ASCollectionViewTestDelegate : NSObject <ASCollectionViewDataSource, ASCollectionViewDelegate> @interface ASCollectionViewTestDelegate : NSObject <ASCollectionViewDataSource, ASCollectionViewDelegate>
@@ -74,6 +75,12 @@
@end @end
@interface ASCollectionView (InternalTesting)
- (NSArray *)supplementaryNodeKindsInDataController:(ASCollectionDataController *)dataController;
@end
@interface ASCollectionViewTests : XCTestCase @interface ASCollectionViewTests : XCTestCase
@end @end
@@ -95,6 +102,14 @@
XCTAssert(collectionView.layoutDelegate == nil, @"should not set a layout delegate for custom layouts"); XCTAssert(collectionView.layoutDelegate == nil, @"should not set a layout delegate for custom layouts");
} }
- (void)testThatRegisteringASupplementaryNodeStoresItForIntrospection
{
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
ASCollectionView *collectionView = [[ASCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
[collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader];
XCTAssertEqualObjects([collectionView supplementaryNodeKindsInDataController:nil], @[UICollectionElementKindSectionHeader]);
}
- (void)DISABLED_testCollectionViewController - (void)DISABLED_testCollectionViewController
{ {
ASCollectionViewTestController *testController = [[ASCollectionViewTestController alloc] initWithNibName:nil bundle:nil]; ASCollectionViewTestController *testController = [[ASCollectionViewTestController alloc] initWithNibName:nil bundle:nil];