From 695440ec1f0edfae7886135b30970657c16a5ef6 Mon Sep 17 00:00:00 2001 From: Ryan Nystrom Date: Tue, 13 Dec 2016 07:22:49 -0800 Subject: [PATCH] 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 --- Tests/IGListAdapterUpdaterTests.m | 25 ++++++++++++++++++++-- Tests/IGListSingleSectionControllerTests.m | 14 ++++++++++++ Tests/IGReloadDataUpdaterTests.m | 11 +++++++++- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/Tests/IGListAdapterUpdaterTests.m b/Tests/IGListAdapterUpdaterTests.m index 8d2b08d7..39095840 100644 --- a/Tests/IGListAdapterUpdaterTests.m +++ b/Tests/IGListAdapterUpdaterTests.m @@ -8,6 +8,7 @@ */ #import +#import #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 diff --git a/Tests/IGListSingleSectionControllerTests.m b/Tests/IGListSingleSectionControllerTests.m index 5926b653..eabae0c7 100644 --- a/Tests/IGListSingleSectionControllerTests.m +++ b/Tests/IGListSingleSectionControllerTests.m @@ -8,7 +8,9 @@ */ #import +#import +#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 diff --git a/Tests/IGReloadDataUpdaterTests.m b/Tests/IGReloadDataUpdaterTests.m index bf221ad5..632f68aa 100644 --- a/Tests/IGReloadDataUpdaterTests.m +++ b/Tests/IGReloadDataUpdaterTests.m @@ -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