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
This commit is contained in:
Maxime Ollivier 2020-09-08 09:06:16 -07:00 committed by Facebook GitHub Bot
parent caf058c85a
commit 3f1a2fb0ac
3 changed files with 33 additions and 0 deletions

View file

@ -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

View file

@ -14,6 +14,8 @@
@class IGTestDelegateController;
@class IGTestObject;
extern NSObject *const kIGTestDelegateDataSourceSkipObject;
@interface IGTestDelegateDataSource : NSObject <IGListTestCaseDataSource>
@property (nonatomic, copy) NSArray <IGTestObject *> *objects;

View file

@ -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;