From 97120d288dd04179f044478841a217f847ca9a44 Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Mon, 17 Apr 2023 20:41:49 -0700 Subject: [PATCH] Added remaining test coverage to IGListBindingSectionController Summary: Added remaining test cases to cover `IGListBindingSectionController` Reviewed By: candance Differential Revision: D45004640 fbshipit-source-id: 2dd1662af849841ab5dccc1f6731ddac800657a0 --- Tests/IGListBindingSectionControllerTests.m | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Tests/IGListBindingSectionControllerTests.m b/Tests/IGListBindingSectionControllerTests.m index b0b34e67..cc210cbc 100644 --- a/Tests/IGListBindingSectionControllerTests.m +++ b/Tests/IGListBindingSectionControllerTests.m @@ -24,6 +24,12 @@ #import "IGTestObject.h" #import "IGTestStringBindableCell.h" +@interface IGListBindingSectionController (Tests) + +- (void)setState:(NSInteger)state; + +@end + @interface IGListBindingSectionControllerTests : IGListTestCase @end @@ -481,4 +487,25 @@ XCTAssertEqual([section.viewModels lastObject], @20); } +#pragma mark - Illegal state validation + +- (void)test_whenAdapterReloadsObjects_andStateIsInconsistent_thatExecutionCompletes { + [self setupWithObjects:@[ + [[IGTestDiffingObject alloc] initWithKey:@1 objects:@[@7, @"seven"]], + ]]; + [self.adapter reloadObjects:@[[[IGTestDiffingObject alloc] initWithKey:@1 objects:@[@"four", @4, @"seven", @7]]]]; + + // Queue up the batch operation which will be called on the next main run loop + XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)]; + [self.adapter performBatchAnimated:YES updates:^(id batchContext){} completion:^(BOOL finished) { + [expectation fulfill]; + }]; + + // Before the next run loop triggers, set the state back to idle + IGListBindingSectionController *controller = (IGListBindingSectionController *)[self.adapter sectionControllerForSection:0]; + [controller setState:0]; + + [self waitForExpectationsWithTimeout:30 handler:nil]; +} + @end