mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-06 06:58:26 +00:00
Summary: Disables `prefetchEnabled` by default on `IGListCollectionView` (#318). - [x] All tests pass. Demo project builds and runs. - [x] I added tests, an experiment, or detailed why my change isn't tested. - [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md) Closes https://github.com/Instagram/IGListKit/pull/323 Differential Revision: D4319761 Pulled By: rnystrom fbshipit-source-id: a3ea4c3d1d1f3123a60c8168fb333e73ab93cb1e
99 lines
4 KiB
Objective-C
99 lines
4 KiB
Objective-C
/**
|
|
* Copyright (c) 2016-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
#import <XCTest/XCTest.h>
|
|
|
|
#import <IGListKit/IGListKit.h>
|
|
#import "IGTestStoryboardViewController.h"
|
|
|
|
static const CGRect kIGListCollectionViewTestFrame = (CGRect){{0.0, 0.0}, {100.0, 100.0}};
|
|
|
|
@interface IGListCollectionViewTests : XCTestCase
|
|
|
|
@end
|
|
|
|
@implementation IGListCollectionViewTests
|
|
|
|
- (void)setUp {
|
|
[super setUp];
|
|
}
|
|
|
|
- (void)tearDown {
|
|
[super tearDown];
|
|
|
|
[[IGListCollectionView appearance] setBackgroundColor:nil];
|
|
}
|
|
|
|
-(void)test_whenUsingUIAppearance_thatIGListCollectionViewUsesAppearanceBackgroundColor {
|
|
UIColor *appearanceColor = [UIColor redColor];
|
|
[[IGListCollectionView appearance] setBackgroundColor:appearanceColor];
|
|
|
|
IGListCollectionView *collectionView = [self setupIGListCollectionView];
|
|
|
|
XCTAssertEqualObjects(collectionView.backgroundColor, appearanceColor);
|
|
}
|
|
|
|
-(void)test_whenNotUsingUIAppearance_thatIGListCollectionViewUsesDefaultBackgroundColor {
|
|
|
|
IGListCollectionView *collectionView = [self setupIGListCollectionView];
|
|
|
|
XCTAssertEqualObjects(collectionView.backgroundColor, [UIColor whiteColor]);
|
|
}
|
|
|
|
-(void)test_thatIGListCollectionViewHasCorrectDefaults {
|
|
IGListCollectionView *collectionView = [[IGListCollectionView alloc] initWithFrame: kIGListCollectionViewTestFrame collectionViewLayout:[UICollectionViewFlowLayout new]];
|
|
|
|
XCTAssertTrue(collectionView.alwaysBounceVertical);
|
|
|
|
if ([collectionView respondsToSelector:@selector(isPrefetchingEnabled)]) {
|
|
XCTAssertFalse(collectionView.isPrefetchingEnabled);
|
|
}
|
|
}
|
|
|
|
-(void)test_thatStoryboardIGListCollectionViewHasCorrectDefaults {
|
|
UIWindow *window = [[UIWindow alloc] initWithFrame:kIGListCollectionViewTestFrame];
|
|
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"IGTestStoryboard" bundle:[NSBundle bundleForClass:self.class]];
|
|
IGTestStoryboardViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"testVC"];
|
|
[window addSubview:viewController.view];
|
|
[viewController performSelectorOnMainThread:@selector(loadView) withObject:nil waitUntilDone:YES];
|
|
|
|
XCTAssertFalse(viewController.collectionView.alwaysBounceVertical);
|
|
|
|
if ([UICollectionView instancesRespondToSelector:@selector(isPrefetchingEnabled)]) {
|
|
XCTAssertFalse(viewController.collectionView.isPrefetchingEnabled);
|
|
}
|
|
}
|
|
|
|
-(void)test_whenUsingUIAppearance_thatStoryboardIGListCollectionViewUsesAppearanceBackgroundColor {
|
|
UIColor *appearanceColor = [UIColor redColor];
|
|
[[IGListCollectionView appearance] setBackgroundColor:appearanceColor];
|
|
|
|
UIWindow *window = [[UIWindow alloc] initWithFrame:kIGListCollectionViewTestFrame];
|
|
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"IGTestStoryboard" bundle:[NSBundle bundleForClass:self.class]];
|
|
IGTestStoryboardViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"testVC"];
|
|
[window addSubview:viewController.view];
|
|
[viewController performSelectorOnMainThread:@selector(loadView) withObject:nil waitUntilDone:YES];
|
|
|
|
XCTAssertEqualObjects(viewController.collectionView.backgroundColor, appearanceColor);
|
|
}
|
|
|
|
#pragma mark - Helper Methods
|
|
|
|
-(IGListCollectionView *)setupIGListCollectionView {
|
|
UIWindow *window = [[UIWindow alloc] initWithFrame:kIGListCollectionViewTestFrame];
|
|
IGListCollectionView *collectionView = [[IGListCollectionView alloc] initWithFrame: kIGListCollectionViewTestFrame collectionViewLayout:[UICollectionViewFlowLayout new]];
|
|
UIViewController *viewController = [UIViewController new];
|
|
[viewController.view addSubview:collectionView];
|
|
[window addSubview:viewController.view];
|
|
[viewController performSelectorOnMainThread:@selector(loadView) withObject:nil waitUntilDone:YES];
|
|
|
|
return collectionView;
|
|
}
|
|
|
|
@end
|