mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-24 09:48:21 +00:00
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
71 lines
2.7 KiB
Objective-C
71 lines
2.7 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/IGListSectionController.h>
|
|
|
|
@interface IGListSectionControllerTests : XCTestCase
|
|
|
|
@end
|
|
|
|
@implementation IGListSectionControllerTests
|
|
|
|
- (void)test_withBaseSectionContoller_thatDefaultValuesAreCorrect {
|
|
NSObject *object = [NSObject new];
|
|
IGListSectionController *sectionController = [[IGListSectionController alloc] init];
|
|
XCTAssertNotNil(sectionController);
|
|
|
|
XCTAssertEqual([sectionController numberOfItems], 1);
|
|
XCTAssertTrue(CGSizeEqualToSize([sectionController sizeForItemAtIndex:0], CGSizeZero));
|
|
XCTAssertTrue([sectionController shouldSelectItemAtIndex:0]);
|
|
XCTAssertTrue([sectionController shouldDeselectItemAtIndex:0]);
|
|
XCTAssertFalse([sectionController canMoveItemAtIndex:0]);
|
|
|
|
[sectionController didUpdateToObject:object];
|
|
|
|
[sectionController didSelectItemAtIndex:0];
|
|
[sectionController didDeselectItemAtIndex:0];
|
|
[sectionController didHighlightItemAtIndex:0];
|
|
[sectionController didUnhighlightItemAtIndex:0];
|
|
|
|
@try {
|
|
[sectionController cellForItemAtIndex:0];
|
|
} @catch (NSException *exception) {}
|
|
|
|
@try {
|
|
[sectionController moveObjectFromIndex:0 toIndex:1];
|
|
} @catch (NSException *exception) {}
|
|
}
|
|
|
|
- (void)test_whenCreatedOutsideDataSource_thatCollectionContextIsNil {
|
|
// Creating a section controller directly (not through the data source) should result in
|
|
// a nil collectionContext since the thread context stack is empty. This covers line 61.
|
|
|
|
// Clear the thread context stack to ensure we're testing the "outside data source" path
|
|
// This is needed because other tests may have left context on the stack
|
|
NSMutableDictionary *threadDictionary = [[NSThread currentThread] threadDictionary];
|
|
[threadDictionary removeObjectForKey:@"kIGListSectionControllerThreadKey"];
|
|
|
|
IGListSectionController *sectionController = [[IGListSectionController alloc] init];
|
|
XCTAssertNil(sectionController.collectionContext);
|
|
XCTAssertNil(sectionController.viewController);
|
|
}
|
|
|
|
#if !TARGET_OS_TV
|
|
- (void)test_whenCallingContextMenuConfiguration_thatDefaultReturnsNil {
|
|
// The default implementation of contextMenuConfigurationForItemAtIndex:point: returns nil
|
|
// Context menus are not available on tvOS
|
|
IGListSectionController *sectionController = [[IGListSectionController alloc] init];
|
|
if (@available(iOS 13.0, *)) {
|
|
UIContextMenuConfiguration *config = [sectionController contextMenuConfigurationForItemAtIndex:0 point:CGPointZero];
|
|
XCTAssertNil(config);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
@end
|