IGListKit/Tests/IGListPerformDiffTests.m
Tim Oliver 062b2f9f70 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: https://github.com/instagram/IGListKit/pull/1654

Reviewed By: jurmarcus

Differential Revision: D91551666

Pulled By: TimOliver

fbshipit-source-id: c89c7a45abebb44dbf50b252bfadc9a7c2928683
2026-01-27 21:10:09 -08:00

63 lines
2.3 KiB
Objective-C

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import <IGListKit/IGListKit.h>
#import "IGListPerformDiff.h"
#import "IGListTransitionData.h"
#import "IGListViewVisibilityTrackerInternal.h"
@interface IGListPerformDiffTests : XCTestCase
@end
@implementation IGListPerformDiffTests
- (void)test_whenPerformDiff_withNilCompletion_thatReturnsEarly {
IGListTransitionData *data = [[IGListTransitionData alloc] initFromObjects:@[@1] toObjects:@[@2] toSectionControllers:@[]];
IGListAdaptiveDiffingExperimentConfig config = {
.enabled = YES,
.higherQOSEnabled = NO,
.maxItemCountToRunOnMain = 0,
.lowerPriorityWhenViewNotVisible = NO
};
// Bypass nonnull check by using a variable
IGListDiffExecutorCompletion completion = nil;
// Should not crash when completion is nil
IGListPerformDiffWithData(data, nil, YES, config, completion);
}
- (void)test_whenPerformDiff_withViewNotVisibleState_thatUsesLowerPriorityQueue {
// Create a view not in any window
UIView *view = [[UIView alloc] init];
// Get the tracker and set it up so it returns NotVisible (not NotVisibleEarly)
IGListViewVisibilityTracker *tracker = IGListViewVisibilityTrackerAttachedOnView(view);
tracker.comparedDateOverride = [tracker.dateCreated dateByAddingTimeInterval:tracker.earlyTimeInterval + 1];
// Verify the tracker returns NotVisible
XCTAssertEqual(tracker.state, IGListViewVisibilityStateNotVisible);
IGListTransitionData *data = [[IGListTransitionData alloc] initFromObjects:@[@1, @2, @3, @4, @5, @6] toObjects:@[@2, @3, @4, @5, @6, @7] toSectionControllers:@[]];
IGListAdaptiveDiffingExperimentConfig config = {
.enabled = YES,
.higherQOSEnabled = NO,
.maxItemCountToRunOnMain = 0,
.lowerPriorityWhenViewNotVisible = YES
};
XCTestExpectation *expectation = [self expectationWithDescription:@"Diff completed"];
IGListPerformDiffWithData(data, view, YES, config, ^(IGListIndexSetResult *result, BOOL onBackground) {
XCTAssertNotNil(result);
XCTAssertTrue(onBackground);
[expectation fulfill];
});
[self waitForExpectationsWithTimeout:30 handler:nil];
}
@end