Skip to content

Commit 062b2f9

Browse files
TimOlivermeta-codesync[bot]
authored andcommitted
Bring Test Coverage back to > 99% (#1654)
Summary: ## Changes in this pull request It's been a few years since I did an audit of our test suite. The majority of changes to IGListKit since then were adding additional error checking and hardening, so this was relatively straightforward. ### Checklist - [x] All tests pass. Demo project builds and runs. - [x] I added tests, an experiment, or detailed why my change isn't tested. - [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/main/.github/CONTRIBUTING.md) Pull Request resolved: #1654 Reviewed By: jurmarcus Differential Revision: D91551666 Pulled By: TimOliver fbshipit-source-id: c89c7a45abebb44dbf50b252bfadc9a7c2928683
1 parent dcda4e7 commit 062b2f9

20 files changed

Lines changed: 843 additions & 8 deletions

Examples/Examples-iOS/IGListKitExamples-UITests/DemosViewControllerUITests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ final class DemosViewControllerUITests: UITestCase {
9797
let exactBar = app.navigationBars[title]
9898
let compactBar = app.navigationBars[title.replacingOccurrences(of: " ", with: "")]
9999

100-
waitToAppear(element: exactBar, timeout: 2)
100+
waitToAppear(element: exactBar, timeout: 5)
101101

102102
if !exactBar.exists {
103-
waitToAppear(element: compactBar, timeout: 2)
103+
waitToAppear(element: compactBar, timeout: 5)
104104
}
105105

106106
XCTAssertTrue(

IGListKit.xcodeproj/project.pbxproj

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828
16B71CEE22B0A08400FE96ED /* IGTestInvalidateLayoutDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 16B71CE822B0A08300FE96ED /* IGTestInvalidateLayoutDataSource.m */; };
2929
16B71CEF22B0A08400FE96ED /* IGTestInvalidateLayoutObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 16B71CEA22B0A08300FE96ED /* IGTestInvalidateLayoutObject.m */; };
3030
16B71CF022B0A08400FE96ED /* IGTestInvalidateLayoutObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 16B71CEA22B0A08300FE96ED /* IGTestInvalidateLayoutObject.m */; };
31+
22907ABD2F2862830015F3D0 /* IGListViewVisibilityTrackerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 22907ABC2F2862830015F3D0 /* IGListViewVisibilityTrackerTests.m */; };
32+
22907ABE2F2862830015F3D0 /* IGListViewVisibilityTrackerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 22907ABC2F2862830015F3D0 /* IGListViewVisibilityTrackerTests.m */; };
33+
22907AC12F2864450015F3D0 /* IGListItemUpdatesCollectorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 22907AC02F2864450015F3D0 /* IGListItemUpdatesCollectorTests.m */; };
34+
22907AC22F2864450015F3D0 /* IGListItemUpdatesCollectorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 22907AC02F2864450015F3D0 /* IGListItemUpdatesCollectorTests.m */; };
35+
22907AC42F2866160015F3D0 /* IGListUpdateCoalescerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 22907AC32F2866160015F3D0 /* IGListUpdateCoalescerTests.m */; };
36+
22907AC52F2866160015F3D0 /* IGListUpdateCoalescerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 22907AC32F2866160015F3D0 /* IGListUpdateCoalescerTests.m */; };
37+
22907AC72F28679B0015F3D0 /* UIViewControllerIGListAdapterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 22907AC62F28679B0015F3D0 /* UIViewControllerIGListAdapterTests.m */; };
38+
22907AC82F28679B0015F3D0 /* UIViewControllerIGListAdapterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 22907AC62F28679B0015F3D0 /* UIViewControllerIGListAdapterTests.m */; };
39+
22907ACA2F2870020015F3D0 /* IGListPerformDiffTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 22907AC92F2870020015F3D0 /* IGListPerformDiffTests.m */; };
40+
22907ACB2F2870020015F3D0 /* IGListPerformDiffTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 22907AC92F2870020015F3D0 /* IGListPerformDiffTests.m */; };
3141
26271C8A1DAE94E40073E116 /* IGTestSingleNibItemDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 26271C891DAE94E40073E116 /* IGTestSingleNibItemDataSource.m */; };
3242
26271C8C1DAE96740073E116 /* IGListSingleNibItemControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 26271C8B1DAE96740073E116 /* IGListSingleNibItemControllerTests.m */; };
3343
290DF3771E9323E6009FE456 /* IGListDebuggerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 290DF3761E9323E6009FE456 /* IGListDebuggerTests.m */; };
@@ -639,6 +649,11 @@
639649
16B71CE822B0A08300FE96ED /* IGTestInvalidateLayoutDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGTestInvalidateLayoutDataSource.m; sourceTree = "<group>"; };
640650
16B71CE922B0A08300FE96ED /* IGTestInvalidateLayoutObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGTestInvalidateLayoutObject.h; sourceTree = "<group>"; };
641651
16B71CEA22B0A08300FE96ED /* IGTestInvalidateLayoutObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGTestInvalidateLayoutObject.m; sourceTree = "<group>"; };
652+
22907ABC2F2862830015F3D0 /* IGListViewVisibilityTrackerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IGListViewVisibilityTrackerTests.m; sourceTree = "<group>"; };
653+
22907AC02F2864450015F3D0 /* IGListItemUpdatesCollectorTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IGListItemUpdatesCollectorTests.m; sourceTree = "<group>"; };
654+
22907AC32F2866160015F3D0 /* IGListUpdateCoalescerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IGListUpdateCoalescerTests.m; sourceTree = "<group>"; };
655+
22907AC62F28679B0015F3D0 /* UIViewControllerIGListAdapterTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UIViewControllerIGListAdapterTests.m; sourceTree = "<group>"; };
656+
22907AC92F2870020015F3D0 /* IGListPerformDiffTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IGListPerformDiffTests.m; sourceTree = "<group>"; };
642657
26271C881DAE94E40073E116 /* IGTestSingleNibItemDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGTestSingleNibItemDataSource.h; sourceTree = "<group>"; };
643658
26271C891DAE94E40073E116 /* IGTestSingleNibItemDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGTestSingleNibItemDataSource.m; sourceTree = "<group>"; };
644659
26271C8B1DAE96740073E116 /* IGListSingleNibItemControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGListSingleNibItemControllerTests.m; sourceTree = "<group>"; };
@@ -1357,7 +1372,9 @@
13571372
88144EE91D870EDC007C7F66 /* IGListDisplayHandlerTests.m */,
13581373
29DA5CA21EA7C72400113926 /* IGListGenericSectionControllerTests.m */,
13591374
F1ED68AE29E9B3B9003744F8 /* IGListInteractiveMovingTests.m */,
1375+
22907AC02F2864450015F3D0 /* IGListItemUpdatesCollectorTests.m */,
13601376
88144EEB1D870EDC007C7F66 /* IGListKitTests-Bridging-Header.h */,
1377+
22907AC92F2870020015F3D0 /* IGListPerformDiffTests.m */,
13611378
F18CC76529EFBC3800DC3B9A /* IGListReloadDataUpdaterTests.m */,
13621379
F1E6302229EA43080060B4D6 /* IGListSectionControllerTests.m */,
13631380
829D7BA81DD1816400549816 /* IGListSectionMapTests.m */,
@@ -1368,7 +1385,10 @@
13681385
29DA5CA61EA7D37000113926 /* IGListTestCase.m */,
13691386
29DA5CAA1EA7D3FF00113926 /* IGListTestHelpers.h */,
13701387
F1ED68B029E9B3B9003744F8 /* IGListTransactionTests.m */,
1388+
22907AC32F2866160015F3D0 /* IGListUpdateCoalescerTests.m */,
13711389
88144EEF1D870EDC007C7F66 /* IGListWorkingRangeHandlerTests.m */,
1390+
22907ABC2F2862830015F3D0 /* IGListViewVisibilityTrackerTests.m */,
1391+
22907AC62F28679B0015F3D0 /* UIViewControllerIGListAdapterTests.m */,
13721392
887D0B571D870E1E009E01F7 /* Info.plist */,
13731393
88144EF01D870EDC007C7F66 /* Objects */,
13741394
);
@@ -1861,7 +1881,7 @@
18611881
BuildIndependentTargetsInParallel = YES;
18621882
CLASSPREFIX = IG;
18631883
LastSwiftUpdateCheck = 1120;
1864-
LastUpgradeCheck = 2600;
1884+
LastUpgradeCheck = 2620;
18651885
ORGANIZATIONNAME = Instagram;
18661886
TargetAttributes = {
18671887
7A02D01C2361520200B49FAE = {
@@ -2188,6 +2208,7 @@
21882208
828540511DE40D2D00118B94 /* IGListTestAdapterHorizontalDataSource.m in Sources */,
21892209
885FE2371DC51B76009CE2B4 /* IGListWorkingRangeHandlerTests.m in Sources */,
21902210
8285404D1DE40C6E00118B94 /* IGListTestHorizontalSection.m in Sources */,
2211+
22907ACA2F2870020015F3D0 /* IGListPerformDiffTests.m in Sources */,
21912212
298DDA061E3AE2B000F76F50 /* IGTestNumberBindableCell.m in Sources */,
21922213
885FE2381DC51B86009CE2B4 /* IGListTestAdapterDataSource.m in Sources */,
21932214
F1ED68B529E9B3B9003744F8 /* IGListDebugDescriptionTests.m in Sources */,
@@ -2197,9 +2218,11 @@
21972218
F1ED68B729E9B3B9003744F8 /* IGListTransactionTests.m in Sources */,
21982219
F1ED68BE29E9B41A003744F8 /* IGListContentInsetTests.m in Sources */,
21992220
5766613F2CB5A72500E20F73 /* IGListAdapterDelegateAnnouncerTests.m in Sources */,
2221+
22907ABD2F2862830015F3D0 /* IGListViewVisibilityTrackerTests.m in Sources */,
22002222
885FE2421DC51B86009CE2B4 /* IGTestSingleStoryboardItemDataSource.m in Sources */,
22012223
885FE2301DC51B76009CE2B4 /* IGListDiffTests.m in Sources */,
22022224
885FE22E1DC51B76009CE2B4 /* IGListBatchUpdateDataTests.m in Sources */,
2225+
22907AC72F28679B0015F3D0 /* UIViewControllerIGListAdapterTests.m in Sources */,
22032226
298DDA3C1E3B170300F76F50 /* IGLayoutTestSection.m in Sources */,
22042227
298DDA0A1E3AE31E00F76F50 /* IGTestDiffingSectionController.m in Sources */,
22052228
29C4748D1DDF45F900AE68CE /* IGListAdapterProxyTests.m in Sources */,
@@ -2219,7 +2242,9 @@
22192242
885FE2431DC51B86009CE2B4 /* IGTestStoryboardViewController.m in Sources */,
22202243
F1ED68BC29E9B411003744F8 /* IGListDebuggerTests.m in Sources */,
22212244
885FE23A1DC51B86009CE2B4 /* IGListTestSection.m in Sources */,
2245+
22907AC52F2866160015F3D0 /* IGListUpdateCoalescerTests.m in Sources */,
22222246
29C579301DE0DA8A003A149B /* IGListTestStoryboardSection.m in Sources */,
2247+
22907AC22F2864450015F3D0 /* IGListItemUpdatesCollectorTests.m in Sources */,
22232248
885FE23E1DC51B86009CE2B4 /* IGTestDelegateDataSource.m in Sources */,
22242249
);
22252250
runOnlyForDeploymentPostprocessing = 0;
@@ -2314,6 +2339,7 @@
23142339
13DF01771FA1000E0092A320 /* IGTestReorderableSection.m in Sources */,
23152340
829D7BAA1DD1819000549816 /* IGListSectionMapTests.m in Sources */,
23162341
F1ED68BD29E9B415003744F8 /* IGListDebugDescriptionTests.m in Sources */,
2342+
22907ACB2F2870020015F3D0 /* IGListPerformDiffTests.m in Sources */,
23172343
E56B7B3420A9D7100071010C /* IGListCollectionScrollingTraitsTests.m in Sources */,
23182344
16B71CEB22B0A08400FE96ED /* IGTestInvalidateLayoutSectionController.m in Sources */,
23192345
29C5792E1DE0DA89003A149B /* IGTestNibSupplementaryView.m in Sources */,
@@ -2323,9 +2349,11 @@
23232349
821BC4D31DB981AB00172ED0 /* IGTestSingleStoryboardItemDataSource.m in Sources */,
23242350
298DDA3D1E3B170400F76F50 /* IGLayoutTestSection.m in Sources */,
23252351
5766613E2CB5A72500E20F73 /* IGListAdapterDelegateAnnouncerTests.m in Sources */,
2352+
22907ABE2F2862830015F3D0 /* IGListViewVisibilityTrackerTests.m in Sources */,
23262353
298DDA091E3AE31D00F76F50 /* IGTestDiffingSectionController.m in Sources */,
23272354
88144F151D870EDC007C7F66 /* IGListTestSection.m in Sources */,
23282355
82914C5B1E6E2DEC0066C2F8 /* IGListTestContainerSizeSection.m in Sources */,
2356+
22907AC82F28679B0015F3D0 /* UIViewControllerIGListAdapterTests.m in Sources */,
23292357
29DA5CA71EA7D37000113926 /* IGListTestCase.m in Sources */,
23302358
88144F1D1D870EDC007C7F66 /* IGTestSupplementarySource.m in Sources */,
23312359
F18CC76629EFBC3800DC3B9A /* IGListReloadDataUpdaterTests.m in Sources */,
@@ -2345,7 +2373,9 @@
23452373
F18CC75C29EFBB9400DC3B9A /* IGListCollectionViewTests.m in Sources */,
23462374
8240C7F81DC2F3FB00B3AAE7 /* IGListTestStoryboardSection.m in Sources */,
23472375
F18CC76329EFBBE200DC3B9A /* IGTestBindingSingleItemDataSource.m in Sources */,
2376+
22907AC42F2866160015F3D0 /* IGListUpdateCoalescerTests.m in Sources */,
23482377
26271C8A1DAE94E40073E116 /* IGTestSingleNibItemDataSource.m in Sources */,
2378+
22907AC12F2864450015F3D0 /* IGListItemUpdatesCollectorTests.m in Sources */,
23492379
6A9EB3611F841E5D0070C572 /* IGTestSingleWithoutDeselectionDelegate.m in Sources */,
23502380
);
23512381
runOnlyForDeploymentPostprocessing = 0;

IGListKit.xcodeproj/xcshareddata/xcschemes/IGListKit-macOS.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "2600"
3+
LastUpgradeVersion = "2620"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

IGListKit.xcodeproj/xcshareddata/xcschemes/IGListKit-tvOS.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "2600"
3+
LastUpgradeVersion = "2620"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

IGListKit.xcodeproj/xcshareddata/xcschemes/IGListKit.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "2600"
3+
LastUpgradeVersion = "2620"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Source/IGListKit/IGListAdapterUpdaterDelegate.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,16 @@ willPerformBatchUpdatesWithCollectionView:(UICollectionView *)collectionView
181181
diffResult:(IGListIndexSetResult *)diffResult
182182
updates:(IGListBatchUpdateData *)updates;
183183

184+
/**
185+
Notifies the delegate that the updater detected an imminent crash, such as when a section controller returns a nil cell.
186+
This provides an opportunity to log diagnostic information before the crash occurs.
187+
188+
@param listAdapterUpdater The adapter updater that detected the issue.
189+
@param collectionView The collection view involved in the crash.
190+
@param sectionControllerClass The class of the section controller that caused the issue, if available.
191+
*/
184192
- (void) listAdapterUpdater:(IGListAdapterUpdater *)listAdapterUpdater
185-
willCrashWithCollectionView:collectionView
193+
willCrashWithCollectionView:(UICollectionView *)collectionView
186194
sectionControllerClass:(nullable Class)sectionControllerClass;
187195

188196
/**

Source/IGListKit/IGListUpdatingDelegate.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ NS_SWIFT_NAME(ListUpdatingDelegate)
202202
*/
203203
- (BOOL)isInDataUpdateBlock;
204204

205+
/**
206+
Called when the updater detects an imminent crash, such as when a section controller returns a nil cell.
207+
This provides an opportunity to log diagnostic information before the crash occurs.
208+
209+
@param collectionView The collection view involved in the crash.
210+
@param sectionControllerClass The class of the section controller that caused the issue, if available.
211+
*/
205212
- (void)willCrashWithCollectionView:(UICollectionView *)collectionView
206213
sectionControllerClass:(nullable Class)sectionControllerClass;
207214

Tests/IGListAdapterDelegateAnnouncerTests.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,31 @@ - (void)test_whenRemovignOneItem_withTwoListeners_withOneAdapter_thatBothListene
137137
[self waitForExpectationsWithTimeout:30 handler:nil];
138138
}
139139

140+
#pragma mark - Remove listener
141+
142+
- (void)test_whenRemovingListener_thatListenerDoesNotReceiveCallbacks {
143+
[self setupAdapter1WithObjects:@[]];
144+
145+
IGTestObject *const object = genTestObject(@1, @1);
146+
self.dataSource1.objects = @[object];
147+
148+
id mockDisplayHandler = [OCMockObject mockForProtocol:@protocol(IGListAdapterDelegate)];
149+
[self.announcer addListener:mockDisplayHandler];
150+
[self.announcer removeListener:mockDisplayHandler];
151+
152+
// Listener was removed, so it should NOT receive any callbacks
153+
[[mockDisplayHandler reject] listAdapter:[OCMArg any] willDisplayObject:[OCMArg any] atIndex:0];
154+
[[mockDisplayHandler reject] listAdapter:[OCMArg any] willDisplayObject:[OCMArg any] cell:[OCMArg any] atIndexPath:[OCMArg any]];
155+
156+
XCTestExpectation *expectation = genExpectation;
157+
[self.adapter1 performUpdatesAnimated:NO completion:^(BOOL finished) {
158+
[mockDisplayHandler verify];
159+
XCTAssertTrue(finished);
160+
[expectation fulfill];
161+
}];
162+
[self waitForExpectationsWithTimeout:30 handler:nil];
163+
}
164+
140165
#pragma mark - Two adapters, single listener
141166

142167
- (void)test_whenShowingTwoItems_withOneListeners_withTwoAdapters_thatBothItemsSendWillDisplay {

Tests/IGListAdapterE2ETests.m

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,4 +2727,116 @@ - (void)test_whenPerformingUpdates_withAdaptiveCoalescing_thatCollectionViewCoun
27272727
[self waitForExpectationsWithTimeout:30 handler:nil];
27282728
}
27292729

2730+
- (void)test_whenPerformingUpdates_withAdaptiveDiffingHigherQOS_thatCollectionViewUpdates {
2731+
IGListAdapterUpdater *updater = (IGListAdapterUpdater *)self.updater;
2732+
updater.allowsBackgroundDiffing = YES;
2733+
updater.adaptiveDiffingExperimentConfig = (IGListAdaptiveDiffingExperimentConfig) {
2734+
.enabled = YES,
2735+
.higherQOSEnabled = YES,
2736+
.maxItemCountToRunOnMain = 0,
2737+
.lowerPriorityWhenViewNotVisible = NO
2738+
};
2739+
2740+
[self setupWithObjects:@[
2741+
genTestObject(@1, @1),
2742+
genTestObject(@2, @2),
2743+
]];
2744+
2745+
self.dataSource.objects = @[
2746+
genTestObject(@2, @2),
2747+
genTestObject(@3, @3),
2748+
];
2749+
2750+
XCTestExpectation *expectation = genExpectation;
2751+
[self.adapter performUpdatesAnimated:YES completion:^(BOOL finished) {
2752+
XCTAssertEqual([self.collectionView numberOfSections], 2);
2753+
[expectation fulfill];
2754+
}];
2755+
[self waitForExpectationsWithTimeout:30 handler:nil];
2756+
}
2757+
2758+
- (void)test_whenPerformingUpdates_withAdaptiveDiffingLowerPriorityWhenNotVisible_thatCollectionViewUpdates {
2759+
IGListAdapterUpdater *updater = (IGListAdapterUpdater *)self.updater;
2760+
updater.allowsBackgroundDiffing = YES;
2761+
updater.adaptiveDiffingExperimentConfig = (IGListAdaptiveDiffingExperimentConfig) {
2762+
.enabled = YES,
2763+
.higherQOSEnabled = NO,
2764+
.maxItemCountToRunOnMain = 0,
2765+
.lowerPriorityWhenViewNotVisible = YES
2766+
};
2767+
2768+
// Remove from window to make it "not visible"
2769+
[self.collectionView removeFromSuperview];
2770+
2771+
[self setupWithObjects:@[
2772+
genTestObject(@1, @1),
2773+
genTestObject(@2, @2),
2774+
]];
2775+
2776+
self.dataSource.objects = @[
2777+
genTestObject(@2, @2),
2778+
genTestObject(@3, @3),
2779+
];
2780+
2781+
XCTestExpectation *expectation = genExpectation;
2782+
[self.adapter performUpdatesAnimated:NO completion:^(BOOL finished) {
2783+
XCTAssertEqual([self.collectionView numberOfSections], 2);
2784+
[expectation fulfill];
2785+
}];
2786+
[self waitForExpectationsWithTimeout:30 handler:nil];
2787+
}
2788+
2789+
- (void)test_whenPerformingUpdates_withAdaptiveDiffingSmallItemCount_thatDiffRunsOnMain {
2790+
IGListAdapterUpdater *updater = (IGListAdapterUpdater *)self.updater;
2791+
updater.allowsBackgroundDiffing = YES;
2792+
updater.adaptiveDiffingExperimentConfig = (IGListAdaptiveDiffingExperimentConfig) {
2793+
.enabled = YES,
2794+
.higherQOSEnabled = NO,
2795+
.maxItemCountToRunOnMain = 100, // Item count is under this threshold
2796+
.lowerPriorityWhenViewNotVisible = NO
2797+
};
2798+
2799+
[self setupWithObjects:@[
2800+
genTestObject(@1, @1),
2801+
]];
2802+
2803+
self.dataSource.objects = @[
2804+
genTestObject(@1, @1),
2805+
genTestObject(@2, @2),
2806+
];
2807+
2808+
XCTestExpectation *expectation = genExpectation;
2809+
[self.adapter performUpdatesAnimated:YES completion:^(BOOL finished) {
2810+
XCTAssertEqual([self.collectionView numberOfSections], 2);
2811+
[expectation fulfill];
2812+
}];
2813+
[self waitForExpectationsWithTimeout:30 handler:nil];
2814+
}
2815+
2816+
- (void)test_whenPerformingUpdates_withAdaptiveDiffingBackgroundDisabled_thatDiffRunsOnMain {
2817+
IGListAdapterUpdater *updater = (IGListAdapterUpdater *)self.updater;
2818+
updater.allowsBackgroundDiffing = NO;
2819+
updater.adaptiveDiffingExperimentConfig = (IGListAdaptiveDiffingExperimentConfig) {
2820+
.enabled = YES,
2821+
.higherQOSEnabled = YES,
2822+
.maxItemCountToRunOnMain = 0,
2823+
.lowerPriorityWhenViewNotVisible = YES
2824+
};
2825+
2826+
[self setupWithObjects:@[
2827+
genTestObject(@1, @1),
2828+
]];
2829+
2830+
self.dataSource.objects = @[
2831+
genTestObject(@2, @2),
2832+
];
2833+
2834+
XCTestExpectation *expectation = genExpectation;
2835+
[self.adapter performUpdatesAnimated:YES completion:^(BOOL finished) {
2836+
XCTAssertEqual([self.collectionView numberOfSections], 1);
2837+
[expectation fulfill];
2838+
}];
2839+
[self waitForExpectationsWithTimeout:30 handler:nil];
2840+
}
2841+
27302842
@end

0 commit comments

Comments
 (0)