From 3f1a2fb0acaaa23d0d8737946451e500add7cddc Mon Sep 17 00:00:00 2001 From: Maxime Ollivier Date: Tue, 8 Sep 2020 09:06:16 -0700 Subject: [PATCH] unit test missing section-controller fix Summary: Lets test that the new updater (`IGListExperimentalAdapterUpdater`) can handle a missing section-controller. The old adapater `IGListAdapterUpdater` would crash. Reviewed By: patters Differential Revision: D23145773 fbshipit-source-id: 4589dcb11ddef5c7400947aea4b6827f1b2caaa8 --- Tests/IGListExperimentalAdapterE2ETests.m | 26 +++++++++++++++++++++++ Tests/Objects/IGTestDelegateDataSource.h | 2 ++ Tests/Objects/IGTestDelegateDataSource.m | 5 +++++ 3 files changed, 33 insertions(+) diff --git a/Tests/IGListExperimentalAdapterE2ETests.m b/Tests/IGListExperimentalAdapterE2ETests.m index 82097089..dd26700f 100644 --- a/Tests/IGListExperimentalAdapterE2ETests.m +++ b/Tests/IGListExperimentalAdapterE2ETests.m @@ -1976,4 +1976,30 @@ [self waitForExpectationsWithTimeout:30 handler:nil]; } +- (void)test_whenUpdating_withMissingSectionController_thatDoesNotCrash { + [self setupWithObjects:@[ + genTestObject(@0, @"Foo"), + genTestObject(@1, @"Bar") + ]]; + + // Adding an object that won't have a corresponding section-controller + self.dataSource.objects = @[ + genTestObject(@0, @"Foo"), + genTestObject(@1, @"Bar"), + kIGTestDelegateDataSourceSkipObject + ]; + + // Perform updates on the adapter + XCTestExpectation *expectation = genExpectation; + [self.adapter performUpdatesAnimated:NO completion:^(BOOL finished) { + // Checked that the update worked + XCTAssertTrue(finished); + // Check that we skipped the object with a missing section-controller + XCTAssertEqual([self.collectionView numberOfSections], 2); + XCTAssertEqual(self.adapter.objects.count, 2); + [expectation fulfill]; + }]; + [self waitForExpectationsWithTimeout:30 handler:nil]; +} + @end diff --git a/Tests/Objects/IGTestDelegateDataSource.h b/Tests/Objects/IGTestDelegateDataSource.h index 6c3e8d9c..e33c860a 100644 --- a/Tests/Objects/IGTestDelegateDataSource.h +++ b/Tests/Objects/IGTestDelegateDataSource.h @@ -14,6 +14,8 @@ @class IGTestDelegateController; @class IGTestObject; +extern NSObject *const kIGTestDelegateDataSourceSkipObject; + @interface IGTestDelegateDataSource : NSObject @property (nonatomic, copy) NSArray *objects; diff --git a/Tests/Objects/IGTestDelegateDataSource.m b/Tests/Objects/IGTestDelegateDataSource.m index 57664fe3..84a4197c 100644 --- a/Tests/Objects/IGTestDelegateDataSource.m +++ b/Tests/Objects/IGTestDelegateDataSource.m @@ -12,6 +12,8 @@ #import "IGTestDelegateController.h" #import "IGTestObject.h" +NSObject *const kIGTestDelegateDataSourceSkipObject = @"kIGTestDelegateDataSourceSkipObject"; + @implementation IGTestDelegateDataSource - (NSArray *)objectsForListAdapter:(IGListAdapter *)listAdapter { @@ -19,6 +21,9 @@ } - (IGListSectionController *)listAdapter:(IGListAdapter *)listAdapter sectionControllerForObject:(id)object { + if ([object isEqual:kIGTestDelegateDataSourceSkipObject]) { + return nil; + } IGTestDelegateController *sectionController = [[IGTestDelegateController alloc] init]; sectionController.cellConfigureBlock = self.cellConfigureBlock; return sectionController;