mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-05 22:48:21 +00:00
Update IGListCollectionViewTests for new collection view behaviour
Summary: It seems the under-the-hood changes made to `UICollectionView` from iOS 16.4 onwards has changed our expectations of how these tests work. When initially testing, it seemed that the new behaviour was that the existing cell in the view would get updated, but any newly inserted cells wouldn't be added to the collection view yet. Thinking this might simply be invalid behaviour when the collection view isn't added to a superview, I added the collection view to a new `UIWindow` instance. When I re-ran the tests again while the view has a superview, all of the views update correctly, and none of them were left in a partial state. I'm not too sure what the original intent of testing the collection view cells for being in a partially updated state was, but I think we need to reconsider that for this new `UICollectionView` behaviour. Differential Revision: D49906268 fbshipit-source-id: 7fdc7ba3a534bd49a8a0684888283d2d1eba5912
This commit is contained in:
parent
749a65b1bf
commit
8840ad2bc8
1 changed files with 26 additions and 22 deletions
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
@interface IGListCollectionViewTests : XCTestCase
|
||||
|
||||
@property (nonatomic, strong) UIWindow *window;
|
||||
@property (nonatomic, strong) IGListCollectionView *collectionView;
|
||||
@property (nonatomic, strong) IGLayoutTestDataSource *dataSource;
|
||||
|
||||
|
|
@ -25,10 +26,13 @@
|
|||
|
||||
- (void)setUp {
|
||||
[super setUp];
|
||||
const CGRect frame = CGRectMake(0, 0, 100, 100);
|
||||
self.window = [[UIWindow alloc] initWithFrame:frame];
|
||||
self.dataSource = [IGLayoutTestDataSource new];
|
||||
self.collectionView = [[IGListCollectionView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
|
||||
self.collectionView = [[IGListCollectionView alloc] initWithFrame:frame];
|
||||
self.collectionView.dataSource = self.dataSource;
|
||||
self.collectionView.delegate = self.dataSource;
|
||||
[self.window addSubview:self.collectionView];
|
||||
[self.dataSource configCollectionView:self.collectionView];
|
||||
}
|
||||
|
||||
|
|
@ -54,7 +58,7 @@
|
|||
|
||||
#pragma mark - Insert/Delete/Reload/Move
|
||||
|
||||
- (void)test_whenInsertingSection_thatLayoutPartiallyUpdates {
|
||||
- (void)test_whenInsertingSection_thatLayoutUpdates {
|
||||
self.dataSource.sections = @[
|
||||
genLayoutTestSection(@[genLayoutTestItem(CGSizeMake(10, 10))])
|
||||
];
|
||||
|
|
@ -67,13 +71,13 @@
|
|||
];
|
||||
[self.collectionView insertSections:[NSIndexSet indexSetWithIndex:1]];
|
||||
|
||||
// check that section 0 wasn't updated
|
||||
IGAssertEqualFrame([self cellForSection:0 item:0].frame, 0, 0, 10, 10);
|
||||
// check that section 0 was updated
|
||||
IGAssertEqualFrame([self cellForSection:0 item:0].frame, 0, 0, 20, 20);
|
||||
// check that section 1 was updated
|
||||
IGAssertEqualFrame([self cellForSection:1 item:0].frame, 10, 0, 10, 10);
|
||||
IGAssertEqualFrame([self cellForSection:1 item:0].frame, 20, 0, 10, 10);
|
||||
}
|
||||
|
||||
- (void)test_whenDeletingSection_thatLayoutPartiallyUpdates {
|
||||
- (void)test_whenDeletingSection_thatLayoutUpdates {
|
||||
self.dataSource.sections = @[
|
||||
genLayoutTestSection(@[genLayoutTestItem(CGSizeMake(10, 10))]),
|
||||
genLayoutTestSection(@[genLayoutTestItem(CGSizeMake(10, 10))])
|
||||
|
|
@ -87,10 +91,10 @@
|
|||
[self.collectionView deleteSections:[NSIndexSet indexSetWithIndex:1]];
|
||||
|
||||
// check that section 0 wasn't updated
|
||||
IGAssertEqualFrame([self cellForSection:0 item:0].frame, 0, 0, 10, 10);
|
||||
IGAssertEqualFrame([self cellForSection:0 item:0].frame, 0, 0, 20, 20);
|
||||
}
|
||||
|
||||
- (void)test_whenReloadingSection_thatLayoutPartiallyUpdates {
|
||||
- (void)test_whenReloadingSection_thatLayoutUpdates {
|
||||
self.dataSource.sections = @[
|
||||
genLayoutTestSection(@[genLayoutTestItem(CGSizeMake(10, 10))]),
|
||||
genLayoutTestSection(@[genLayoutTestItem(CGSizeMake(10, 10))])
|
||||
|
|
@ -104,13 +108,13 @@
|
|||
];
|
||||
[self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:1]];
|
||||
|
||||
// check that section 0 wasn't updated
|
||||
IGAssertEqualFrame([self cellForSection:0 item:0].frame, 0, 0, 10, 10);
|
||||
// check that section 0 was updated
|
||||
IGAssertEqualFrame([self cellForSection:0 item:0].frame, 0, 0, 20, 20);
|
||||
// check that section 1 was updated
|
||||
IGAssertEqualFrame([self cellForSection:1 item:0].frame, 10, 0, 20, 20);
|
||||
IGAssertEqualFrame([self cellForSection:1 item:0].frame, 20, 0, 20, 20);
|
||||
}
|
||||
|
||||
- (void)test_whenMoveSection_thatLayoutPartiallyUpdates {
|
||||
- (void)test_whenMoveSection_thatLayoutUpdates {
|
||||
self.dataSource.sections = @[
|
||||
genLayoutTestSection(@[genLayoutTestItem(CGSizeMake(10, 10))]),
|
||||
genLayoutTestSection(@[genLayoutTestItem(CGSizeMake(20, 20))]),
|
||||
|
|
@ -126,12 +130,12 @@
|
|||
];
|
||||
[self.collectionView moveSection:1 toSection:2];
|
||||
|
||||
// check that section 0 wasn't updated
|
||||
IGAssertEqualFrame([self cellForSection:0 item:0].frame, 0, 0, 10, 10);
|
||||
// check that section 0 was updated
|
||||
IGAssertEqualFrame([self cellForSection:0 item:0].frame, 0, 0, 40, 40);
|
||||
// check that section 1 was updated
|
||||
IGAssertEqualFrame([self cellForSection:1 item:0].frame, 10, 0, 30, 30);
|
||||
IGAssertEqualFrame([self cellForSection:1 item:0].frame, 40, 0, 30, 30);
|
||||
// check that section 2 was updated
|
||||
IGAssertEqualFrame([self cellForSection:2 item:0].frame, 40, 0, 20, 20);
|
||||
IGAssertEqualFrame([self cellForSection:2 item:0].frame, 70, 0, 20, 20);
|
||||
}
|
||||
|
||||
- (void)test_whenMoveItem_thatLayoutPartiallyUpdates {
|
||||
|
|
@ -163,7 +167,7 @@
|
|||
|
||||
#pragma mark - Batch
|
||||
|
||||
- (void)test_whenInsertDeleteMoveSection_thatLayoutPartiallyUpdates {
|
||||
- (void)test_whenInsertDeleteMoveSection_thatLayoutUpdates {
|
||||
self.dataSource.sections = @[
|
||||
genLayoutTestSection(@[genLayoutTestItem(CGSizeMake(1, 1))]),
|
||||
genLayoutTestSection(@[genLayoutTestItem(CGSizeMake(2, 2))]),
|
||||
|
|
@ -190,14 +194,14 @@
|
|||
[self.collectionView layoutIfNeeded];
|
||||
[expectation fulfill];
|
||||
|
||||
// check that section 0 wasn't updated
|
||||
IGAssertEqualFrame([self cellForSection:0 item:0].frame, 0, 0, 1, 1);
|
||||
// check that section 0 was updated
|
||||
IGAssertEqualFrame([self cellForSection:0 item:0].frame, 0, 0, 0, 0);
|
||||
// check that section 1 was updated
|
||||
IGAssertEqualFrame([self cellForSection:1 item:0].frame, 1, 0, 4, 4);
|
||||
IGAssertEqualFrame([self cellForSection:1 item:0].frame, 0, 0, 4, 4);
|
||||
// check that section 2 was updated
|
||||
IGAssertEqualFrame([self cellForSection:2 item:0].frame, 5, 0, 3, 3);
|
||||
IGAssertEqualFrame([self cellForSection:2 item:0].frame, 4, 0, 3, 3);
|
||||
// check that section 3 was updated
|
||||
IGAssertEqualFrame([self cellForSection:3 item:0].frame, 8, 0, 5, 5);
|
||||
IGAssertEqualFrame([self cellForSection:3 item:0].frame, 7, 0, 5, 5);
|
||||
}];
|
||||
|
||||
[self waitForExpectationsWithTimeout:30 handler:^(NSError * _Nullable error) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue