From 41374038b4fc65e2c24b65190c1d65a303332412 Mon Sep 17 00:00:00 2001 From: Brian Nickel Date: Wed, 31 Jul 2013 22:29:23 -0700 Subject: [PATCH] Added special behavior for scrolling to the end of table views. > For cases where you may need to work from the end of a table view rather than the beginning, negative sections count back from the end of the table view (-1 is the last section) and negative rows count back from the end of the section (-1 is the last row for that section). --- Classes/KIFUITestActor.h | 2 ++ Classes/KIFUITestActor.m | 10 ++++++++++ KIF Tests/TableViewTests.m | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/Classes/KIFUITestActor.h b/Classes/KIFUITestActor.h index 41d437e9d..7d8e032d4 100644 --- a/Classes/KIFUITestActor.h +++ b/Classes/KIFUITestActor.h @@ -282,6 +282,8 @@ static inline KIFDisplacement KIFDisplacementForSwipingInDirection(KIFSwipeDirec /*! @abstract Taps the row at IndexPath in a view with the given label. @discussion This step will get the view with the specified accessibility label and tap the row at indexPath. + + For cases where you may need to work from the end of a table view rather than the beginning, negative sections count back from the end of the table view (-1 is the last section) and negative rows count back from the end of the section (-1 is the last row for that section). @param tableViewLabel Accessibility label of the table view. @param indexPath Index path of the row to tap. */ diff --git a/Classes/KIFUITestActor.m b/Classes/KIFUITestActor.m index c92d02185..c5a676465 100644 --- a/Classes/KIFUITestActor.m +++ b/Classes/KIFUITestActor.m @@ -455,6 +455,16 @@ - (void)tapRowInTableViewWithAccessibilityLabel:(NSString*)tableViewLabel atInde } UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; + + // If section < 0, search from the end of the table. + if (indexPath.section < 0) { + indexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:tableView.numberOfSections + indexPath.section]; + } + + // If row < 0, search from the end of the section. + if (indexPath.row < 0) { + indexPath = [NSIndexPath indexPathForRow:[tableView numberOfRowsInSection:indexPath.section] + indexPath.row inSection:indexPath.section]; + } if (!cell) { if (indexPath.section >= tableView.numberOfSections) { diff --git a/KIF Tests/TableViewTests.m b/KIF Tests/TableViewTests.m index 3c0c17c14..b3c2938dc 100644 --- a/KIF Tests/TableViewTests.m +++ b/KIF Tests/TableViewTests.m @@ -32,6 +32,12 @@ - (void)testTappingRows [tester waitForViewWithAccessibilityLabel:@"First Cell" traits:UIAccessibilityTraitSelected]; } +- (void)testTappingLastRowAndSection +{ + [tester tapRowInTableViewWithAccessibilityLabel:@"TableView Tests Table" atIndexPath:[NSIndexPath indexPathForRow:-1 inSection:-1]]; + [tester waitForViewWithAccessibilityLabel:@"Last Cell" traits:UIAccessibilityTraitSelected]; +} + - (void)testOutOfBounds { KIFExpectFailure([tester tapRowInTableViewWithAccessibilityLabel:@"TableView Tests Table" atIndexPath:[NSIndexPath indexPathForRow:0 inSection:99]]);