@@ -234,9 +234,7 @@ - (void)testRelayoutAllRowsWithNonZeroSizeInitially
234234 tableView.asyncDelegate = dataSource;
235235 tableView.asyncDataSource = dataSource;
236236
237- // Trigger layout measurement on all nodes
238- [tableView reloadData ];
239-
237+ [self triggerFirstLayoutMeasurementForTableView: tableView];
240238 [self triggerSizeChangeAndAssertRelayoutAllRowsForTableView: tableView newSize: tableViewFinalSize];
241239}
242240
@@ -264,36 +262,6 @@ - (void)testRelayoutAllRowsWithZeroSizeInitially
264262 [self triggerSizeChangeAndAssertRelayoutAllRowsForTableView: tableView newSize: tableViewFinalSize];
265263}
266264
267- - (void )triggerSizeChangeAndAssertRelayoutAllRowsForTableView : (ASTableView *)tableView newSize : (CGSize)newSize
268- {
269- XCTestExpectation *nodesMeasuredUsingNewConstrainedSizeExpectation = [self expectationWithDescription: @" nodesMeasuredUsingNewConstrainedSize" ];
270-
271- [tableView beginUpdates ];
272-
273- CGRect frame = tableView.frame ;
274- frame.size = newSize;
275- tableView.frame = frame;
276- [tableView layoutIfNeeded ];
277-
278- [tableView endUpdatesAnimated: NO completion: ^(BOOL completed) {
279- for (int section = 0 ; section < NumberOfSections; section++) {
280- for (int row = 0 ; row < NumberOfRowsPerSection; row++) {
281- NSIndexPath *indexPath = [NSIndexPath indexPathForRow: row inSection: section];
282- ASTestTextCellNode *node = (ASTestTextCellNode *)[tableView nodeForRowAtIndexPath: indexPath];
283- XCTAssertEqual (node.numberOfLayoutsOnMainThread , 1 );
284- XCTAssertEqual (node.constrainedSizeForCalculatedLayout .max .width , newSize.width );
285- }
286- }
287- [nodesMeasuredUsingNewConstrainedSizeExpectation fulfill ];
288- }];
289-
290- [self waitForExpectationsWithTimeout: 5 handler: ^(NSError *error) {
291- if (error) {
292- XCTFail (@" Expectation failed: %@ " , error);
293- }
294- }];
295- }
296-
297265- (void )testRelayoutVisibleRowsWhenEditingModeIsChanged
298266{
299267 CGSize tableViewSize = CGSizeMake (100 , 500 );
@@ -304,24 +272,8 @@ - (void)testRelayoutVisibleRowsWhenEditingModeIsChanged
304272
305273 tableView.asyncDelegate = dataSource;
306274 tableView.asyncDataSource = dataSource;
307-
308- XCTestExpectation *reloadDataExpectation = [self expectationWithDescription: @" reloadData" ];
309- [tableView reloadDataWithCompletion: ^{
310- for (int section = 0 ; section < NumberOfSections; section++) {
311- for (int row = 0 ; row < NumberOfRowsPerSection; row++) {
312- NSIndexPath *indexPath = [NSIndexPath indexPathForRow: row inSection: section];
313- ASTestTextCellNode *node = (ASTestTextCellNode *)[tableView nodeForRowAtIndexPath: indexPath];
314- XCTAssertEqual (node.numberOfLayoutsOnMainThread , 0 );
315- XCTAssertEqual (node.constrainedSizeForCalculatedLayout .max .width , tableViewSize.width );
316- }
317- }
318- [reloadDataExpectation fulfill ];
319- }];
320- [self waitForExpectationsWithTimeout: 5 handler: ^(NSError *error) {
321- if (error) {
322- XCTFail (@" Expectation failed: %@ " , error);
323- }
324- }];
275+
276+ [self triggerFirstLayoutMeasurementForTableView: tableView];
325277
326278 NSArray *visibleNodes = [tableView visibleNodes ];
327279 XCTAssertGreaterThan (visibleNodes.count , 0 );
@@ -390,23 +342,7 @@ - (void)DISABLED_testRelayoutRowsAfterEditingModeIsChangedAndTheyBecomeVisible
390342 tableView.asyncDelegate = dataSource;
391343 tableView.asyncDataSource = dataSource;
392344
393- XCTestExpectation *reloadDataExpectation = [self expectationWithDescription: @" reloadData" ];
394- [tableView reloadDataWithCompletion: ^{
395- for (int section = 0 ; section < NumberOfSections; section++) {
396- for (int row = 0 ; row < NumberOfRowsPerSection; row++) {
397- NSIndexPath *indexPath = [NSIndexPath indexPathForRow: row inSection: section];
398- ASTestTextCellNode *node = (ASTestTextCellNode *)[tableView nodeForRowAtIndexPath: indexPath];
399- XCTAssertEqual (node.numberOfLayoutsOnMainThread , 0 );
400- XCTAssertEqual (node.constrainedSizeForCalculatedLayout .max .width , tableViewSize.width );
401- }
402- }
403- [reloadDataExpectation fulfill ];
404- }];
405- [self waitForExpectationsWithTimeout: 5 handler: ^(NSError *error) {
406- if (error) {
407- XCTFail (@" Expectation failed: %@ " , error);
408- }
409- }];
345+ [self triggerFirstLayoutMeasurementForTableView: tableView];
410346
411347 // Cause table view to enter editing mode and then scroll to the bottom.
412348 // The last node should be re-measured on main thread with the new (smaller) content view width.
@@ -451,4 +387,53 @@ - (void)testIndexPathForNode
451387 }];
452388}
453389
390+ - (void )triggerFirstLayoutMeasurementForTableView : (ASTableView *)tableView {
391+ XCTestExpectation *reloadDataExpectation = [self expectationWithDescription: @" reloadData" ];
392+ [tableView reloadDataWithCompletion: ^{
393+ for (int section = 0 ; section < NumberOfSections; section++) {
394+ for (int row = 0 ; row < NumberOfRowsPerSection; row++) {
395+ NSIndexPath *indexPath = [NSIndexPath indexPathForRow: row inSection: section];
396+ ASTestTextCellNode *node = (ASTestTextCellNode *)[tableView nodeForRowAtIndexPath: indexPath];
397+ XCTAssertEqual (node.numberOfLayoutsOnMainThread , 0 );
398+ XCTAssertEqual (node.constrainedSizeForCalculatedLayout .max .width , tableView.frame .size .width );
399+ }
400+ }
401+ [reloadDataExpectation fulfill ];
402+ }];
403+ [self waitForExpectationsWithTimeout: 5 handler: ^(NSError *error) {
404+ if (error) {
405+ XCTFail (@" Expectation failed: %@ " , error);
406+ }
407+ }];
408+ }
409+
410+ - (void )triggerSizeChangeAndAssertRelayoutAllRowsForTableView : (ASTableView *)tableView newSize : (CGSize)newSize
411+ {
412+ XCTestExpectation *nodesMeasuredUsingNewConstrainedSizeExpectation = [self expectationWithDescription: @" nodesMeasuredUsingNewConstrainedSize" ];
413+
414+ [tableView beginUpdates ];
415+
416+ CGRect frame = tableView.frame ;
417+ frame.size = newSize;
418+ tableView.frame = frame;
419+ [tableView layoutIfNeeded ];
420+
421+ [tableView endUpdatesAnimated: NO completion: ^(BOOL completed) {
422+ for (int section = 0 ; section < NumberOfSections; section++) {
423+ for (int row = 0 ; row < NumberOfRowsPerSection; row++) {
424+ NSIndexPath *indexPath = [NSIndexPath indexPathForRow: row inSection: section];
425+ ASTestTextCellNode *node = (ASTestTextCellNode *)[tableView nodeForRowAtIndexPath: indexPath];
426+ XCTAssertEqual (node.numberOfLayoutsOnMainThread , 1 );
427+ XCTAssertEqual (node.constrainedSizeForCalculatedLayout .max .width , newSize.width );
428+ }
429+ }
430+ [nodesMeasuredUsingNewConstrainedSizeExpectation fulfill ];
431+ }];
432+ [self waitForExpectationsWithTimeout: 5 handler: ^(NSError *error) {
433+ if (error) {
434+ XCTFail (@" Expectation failed: %@ " , error);
435+ }
436+ }];
437+ }
438+
454439@end
0 commit comments