IGListKit/Tests/IGListCollectionViewTests.m
Leyla Hujer 68a264d29c Revert D4640425: [IGListKit] kill IGListCollectionView. GH issue #409
Summary: This reverts commit 871b75eaeb1c9f2a40fe8f3fd81b209661704587

Differential Revision: D4640425

fbshipit-source-id: 4b0e8a9820891062cf7f8d13de13d678adb5df4a
2017-03-06 16:15:31 -08:00

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