Skip to content

Commit

Permalink
Update IGListCollectionViewTests for new collection view behaviour
Browse files Browse the repository at this point in the history
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
  • Loading branch information
TimOliver authored and facebook-github-bot committed Oct 6, 2023
1 parent 749a65b commit 8840ad2
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions Tests/IGListCollectionViewTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

@interface IGListCollectionViewTests : XCTestCase

@property (nonatomic, strong) UIWindow *window;
@property (nonatomic, strong) IGListCollectionView *collectionView;
@property (nonatomic, strong) IGLayoutTestDataSource *dataSource;

Expand All @@ -25,10 +26,13 @@ @implementation IGListCollectionViewTests

- (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];
}

Expand All @@ -54,7 +58,7 @@ - (void)test_whenReloadData_thatEntireLayoutUpdates {

#pragma mark - Insert/Delete/Reload/Move

- (void)test_whenInsertingSection_thatLayoutPartiallyUpdates {
- (void)test_whenInsertingSection_thatLayoutUpdates {
self.dataSource.sections = @[
genLayoutTestSection(@[genLayoutTestItem(CGSizeMake(10, 10))])
];
Expand All @@ -67,13 +71,13 @@ - (void)test_whenInsertingSection_thatLayoutPartiallyUpdates {
];
[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))])
Expand All @@ -87,10 +91,10 @@ - (void)test_whenDeletingSection_thatLayoutPartiallyUpdates {
[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))])
Expand All @@ -104,13 +108,13 @@ - (void)test_whenReloadingSection_thatLayoutPartiallyUpdates {
];
[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))]),
Expand All @@ -126,12 +130,12 @@ - (void)test_whenMoveSection_thatLayoutPartiallyUpdates {
];
[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 {
Expand Down Expand Up @@ -163,7 +167,7 @@ - (void)test_whenMoveItem_thatLayoutPartiallyUpdates {

#pragma mark - Batch

- (void)test_whenInsertDeleteMoveSection_thatLayoutPartiallyUpdates {
- (void)test_whenInsertDeleteMoveSection_thatLayoutUpdates {
self.dataSource.sections = @[
genLayoutTestSection(@[genLayoutTestItem(CGSizeMake(1, 1))]),
genLayoutTestSection(@[genLayoutTestItem(CGSizeMake(2, 2))]),
Expand All @@ -190,14 +194,14 @@ - (void)test_whenInsertDeleteMoveSection_thatLayoutPartiallyUpdates {
[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) {
Expand Down

0 comments on commit 8840ad2

Please sign in to comment.