Skip to content

Commit

Permalink
Added special behavior for scrolling to the end of table views.
Browse files Browse the repository at this point in the history
> 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).
  • Loading branch information
bnickel committed Aug 1, 2013
1 parent e2ff5a4 commit 4137403
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Classes/KIFUITestActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
10 changes: 10 additions & 0 deletions Classes/KIFUITestActor.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions KIF Tests/TableViewTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]]);
Expand Down

0 comments on commit 4137403

Please sign in to comment.