|
| 1 | +// |
| 2 | +// ASCollectionViewTests.m |
| 3 | +// AsyncDisplayKit |
| 4 | +// |
| 5 | +// Copyright (c) 2015 Facebook. All rights reserved. |
| 6 | +// |
| 7 | + |
| 8 | +#import <XCTest/XCTest.h> |
| 9 | +#import <AsyncDisplayKit/ASCollectionView.h> |
| 10 | + |
| 11 | +@interface ASCollectionViewTestDelegate : NSObject <ASCollectionViewDataSource, ASCollectionViewDelegate> |
| 12 | + |
| 13 | +@property (nonatomic, assign) NSInteger numberOfSections; |
| 14 | +@property (nonatomic, assign) NSInteger numberOfItemsInSection; |
| 15 | + |
| 16 | +@end |
| 17 | + |
| 18 | +@implementation ASCollectionViewTestDelegate |
| 19 | + |
| 20 | +- (id)initWithNumberOfSections:(NSInteger)numberOfSections numberOfItemsInSection:(NSInteger)numberOfItemsInSection { |
| 21 | + if (self = [super init]) { |
| 22 | + _numberOfSections = numberOfSections; |
| 23 | + _numberOfItemsInSection = numberOfItemsInSection; |
| 24 | + } |
| 25 | + |
| 26 | + return self; |
| 27 | +} |
| 28 | + |
| 29 | +- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForItemAtIndexPath:(NSIndexPath *)indexPath { |
| 30 | + ASTextCellNode *textCellNode = [ASTextCellNode new]; |
| 31 | + textCellNode.text = indexPath.description; |
| 32 | + |
| 33 | + return textCellNode; |
| 34 | +} |
| 35 | + |
| 36 | +- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { |
| 37 | + return self.numberOfSections; |
| 38 | +} |
| 39 | + |
| 40 | +- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { |
| 41 | + return self.numberOfItemsInSection; |
| 42 | +} |
| 43 | + |
| 44 | +@end |
| 45 | + |
| 46 | +@interface ASCollectionViewTestController: UIViewController |
| 47 | + |
| 48 | +@property (nonatomic, strong) ASCollectionViewTestDelegate *asyncDelegate; |
| 49 | +@property (nonatomic, strong) ASCollectionView *collectionView; |
| 50 | + |
| 51 | +@end |
| 52 | + |
| 53 | +@implementation ASCollectionViewTestController |
| 54 | + |
| 55 | +- (void)viewDidLoad { |
| 56 | + [super viewDidLoad]; |
| 57 | + |
| 58 | + self.asyncDelegate = [[ASCollectionViewTestDelegate alloc] initWithNumberOfSections:10 numberOfItemsInSection:10]; |
| 59 | + |
| 60 | + self.collectionView = [[ASCollectionView alloc] initWithFrame:self.view.bounds |
| 61 | + collectionViewLayout:[UICollectionViewFlowLayout new]]; |
| 62 | + self.collectionView.asyncDataSource = self.asyncDelegate; |
| 63 | + self.collectionView.asyncDelegate = self.asyncDelegate; |
| 64 | + |
| 65 | + [self.view addSubview:self.collectionView]; |
| 66 | +} |
| 67 | + |
| 68 | +- (void)viewWillLayoutSubviews { |
| 69 | + [super viewWillLayoutSubviews]; |
| 70 | + |
| 71 | + self.collectionView.frame = self.view.bounds; |
| 72 | +} |
| 73 | + |
| 74 | +@end |
| 75 | + |
| 76 | +@interface ASCollectionViewTests : XCTestCase |
| 77 | + |
| 78 | +@end |
| 79 | + |
| 80 | +@implementation ASCollectionViewTests |
| 81 | + |
| 82 | +- (void)DISABLED_testCollectionViewController { |
| 83 | + ASCollectionViewTestController *testController = [[ASCollectionViewTestController alloc] initWithNibName:nil bundle:nil]; |
| 84 | + |
| 85 | + UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; |
| 86 | + [containerView addSubview:testController.view]; |
| 87 | + |
| 88 | + [testController.collectionView reloadData]; |
| 89 | + |
| 90 | + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]]; |
| 91 | +} |
| 92 | + |
| 93 | +@end |
0 commit comments