Add more missing unit tests

Summary:
Working on that coverage %. Hustle to ?

Seriously tho, nearly maxed the coverage that is realistic. I think we need to spend some time on the grid layout tho, there are parts untested that also are unnecessary. I should file a 3.0.0 issue to track work on that.

Waiting for CI ?
Closes https://github.com/Instagram/IGListKit/pull/324

Differential Revision: D4319806

Pulled By: rnystrom

fbshipit-source-id: b626abd65ad73709c231671c0c669414eef1660b
This commit is contained in:
Ryan Nystrom 2016-12-13 07:22:49 -08:00 committed by Facebook Github Bot
parent fb9d8cea8e
commit 695440ec1f
3 changed files with 47 additions and 3 deletions

View file

@ -8,6 +8,7 @@
*/
#import <XCTest/XCTest.h>
#import <OCMock/OCMock.h>
#import "IGListAdapterUpdaterInternal.h"
#import "IGListTestUICollectionViewDataSource.h"
@ -175,7 +176,7 @@
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 3);
XCTestExpectation *expectation = genExpectation;
[self.updater performUpdateWithCollectionView:self.collectionView fromObjects:from toObjects:to animated:YES objectTransitionBlock:self.updateBlock completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionView:self.collectionView fromObjects:from toObjects:to animated:NO objectTransitionBlock:self.updateBlock completion:^(BOOL finished) {
XCTAssertEqual([self.collectionView numberOfSections], 3);
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 2);
XCTAssertEqual([self.collectionView numberOfItemsInSection:1], 1);
@ -224,7 +225,7 @@
[self.collectionView setNeedsLayout];
XCTestExpectation *expectation = genExpectation;
[self.updater performUpdateWithCollectionView:self.collectionView fromObjects:from toObjects:to animated:YES objectTransitionBlock:self.updateBlock completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionView:self.collectionView fromObjects:from toObjects:to animated:NO objectTransitionBlock:self.updateBlock completion:^(BOOL finished) {
XCTAssertEqual([self.collectionView numberOfSections], 1);
[expectation fulfill];
}];
@ -397,4 +398,24 @@
XCTAssertEqual(inserts.count, 0);
}
- (void)test_whenReloadingData_withNilCollectionView_thatDelegateEventNotSent {
id mockDelegate = [OCMockObject mockForProtocol:@protocol(IGListAdapterUpdaterDelegate)];
self.updater.delegate = mockDelegate;
id compilerFriendlyNil = nil;
[[mockDelegate reject] listAdapterUpdater:self.updater willReloadDataWithCollectionView:compilerFriendlyNil];
[[mockDelegate reject] listAdapterUpdater:self.updater didReloadDataWithCollectionView:compilerFriendlyNil];
[self.updater performReloadDataWithCollectionView:compilerFriendlyNil];
[mockDelegate verify];
}
- (void)test_whenPerformingUpdates_withNilCollectionView_thatDelegateEventNotSent {
id mockDelegate = [OCMockObject mockForProtocol:@protocol(IGListAdapterUpdaterDelegate)];
self.updater.delegate = mockDelegate;
id compilerFriendlyNil = nil;
[[mockDelegate reject] listAdapterUpdater:self.updater willPerformBatchUpdatesWithCollectionView:compilerFriendlyNil];
[[mockDelegate reject] listAdapterUpdater:self.updater didPerformBatchUpdates:[OCMArg any] withCollectionView:compilerFriendlyNil];
[self.updater performBatchUpdatesWithCollectionView:compilerFriendlyNil];
[mockDelegate verify];
}
@end

View file

@ -8,7 +8,9 @@
*/
#import <XCTest/XCTest.h>
#import <OCMock/OCMock.h>
#import "IGListAdapterInternal.h"
#import "IGTestCell.h"
#import "IGTestSingleItemDataSource.h"
@ -117,4 +119,16 @@
[self waitForExpectationsWithTimeout:15 handler:nil];
}
- (void)test_whenSelected_thatDelegateReceivesEvent {
[self setupWithObjects:@[
genTestObject(@1, @"a")
]];
IGListSingleSectionController *section = [self.adapter sectionControllerForObject:self.dataSource.objects.firstObject];
id mockDelegate = [OCMockObject mockForProtocol:@protocol(IGListSingleSectionControllerDelegate)];
section.selectionDelegate = mockDelegate;
[[mockDelegate expect] didSelectSingleSectionController:section];
[self.adapter collectionView:self.collectionView didSelectItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
[mockDelegate verify];
}
@end

View file

@ -82,8 +82,17 @@
[self.adapter reloadDataWithCompletion:nil];
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 2);
IGListTestSection *section = [self.adapter sectionControllerForObject:@2];
[section.collectionContext insertInSectionController:section atIndexes:[NSIndexSet indexSetWithIndex:0]];
[section.collectionContext reloadInSectionController:section atIndexes:[NSIndexSet indexSetWithIndex:0]];
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 2);
}
- (void)test_whenPerformingUpdate_thatCompletionExecuted {
__block BOOL executed = NO;
self.dataSource.objects = @[@0, @1, @2];
[self.adapter performUpdatesAnimated:NO completion:^(BOOL finished) {
executed = YES;
}];
XCTAssertTrue(executed);
}
@end