diff --git a/Tests/IGListCollectionViewTests.m b/Tests/IGListCollectionViewTests.m index badebc058..8f7ba1b90 100644 --- a/Tests/IGListCollectionViewTests.m +++ b/Tests/IGListCollectionViewTests.m @@ -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 @@ @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]; } @@ -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))]) ]; @@ -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))]) @@ -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))]) @@ -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))]), @@ -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 { @@ -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))]), @@ -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) {