Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "atPosition:" variations to UICollectionView waitForCellAtIndexPath methods #1061

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions Classes/KIFUITestActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -752,19 +752,33 @@ typedef NS_ENUM(NSUInteger, KIFPullToRefreshTiming) {
@abstract Scrolls a collection view while waiting for the cell at the given indexPath to appear.
@discussion This step will get the cell at the 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).
By default, scrolls to the vertical and horizontal middle of the cell. If you need to scroll to custom positions, use the @c atPosition: variation.
For cases where you may need to work from the end of a collection view rather than the beginning, negative sections count back from the end of the collection 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 indexPath Index path of the cell.
@param collectionView UICollectionView containing the cell.
@result Collection view cell at index path
*/
- (UICollectionViewCell *)waitForCellAtIndexPath:(NSIndexPath *)indexPath inCollectionView:(UICollectionView *)collectionView;

/*!
@abstract Scrolls a collection view while waiting for the cell at the given indexPath to appear.
@discussion This step will get the cell at the indexPath.

For cases where you may need to work from the end of a collection view rather than the beginning, negative sections count back from the end of the collection 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 indexPath Index path of the cell.
@param collectionView UICollectionView containing the cell.
@param position Collection View scroll position to scroll to. Useful for custom-sized cells when the content needed is in a specific location.
@result Collection view cell at index path
*/
- (UICollectionViewCell *)waitForCellAtIndexPath:(NSIndexPath *)indexPath inCollectionView:(UICollectionView *)collectionView atPosition:(UICollectionViewScrollPosition)position;

/*!
@abstract Scrolls a given collection view while waiting for the item at the given indexPath to appear.
@abstract Scrolls a collection view with the given identifier while waiting for the item at the given indexPath to appear.
@discussion This step will get the view with the specified accessibility identifier and then get the cell at indexPath.

By default, scrolls to the vertical and horizontal middle of the cell. If you need to scroll to custom positions, use the @c atPosition: variation.
For cases where you may need to work from the end of a collection view rather than the beginning, negative sections count back from the end of the collection view (-1 is the last section) and negative items count back from the end of the section (-1 is the last item for that section).

@param indexPath Index path of the item to tap.
Expand All @@ -773,6 +787,19 @@ typedef NS_ENUM(NSUInteger, KIFPullToRefreshTiming) {
*/
- (UICollectionViewCell *)waitForCellAtIndexPath:(NSIndexPath *)indexPath inCollectionViewWithAccessibilityIdentifier:(NSString *)identifier;

/*!
@abstract Scrolls a collection view with the given identifier while waiting for the item at the given indexPath to appear.
@discussion This step will get the view with the specified accessibility identifier and then get the cell at indexPath.

For cases where you may need to work from the end of a collection view rather than the beginning, negative sections count back from the end of the collection 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 indexPath Index path of the cell.
@param identifier Accessibility identifier of the table view.
@param position Collection View scroll position to scroll to. Useful for custom-sized cells when the content needed is in a specific location.
@result Table view cell at index path
*/
- (UICollectionViewCell *)waitForCellAtIndexPath:(NSIndexPath *)indexPath inCollectionViewWithAccessibilityIdentifier:(NSString *)identifier atPosition:(UICollectionViewScrollPosition)position;

/*!
@abstract Moves the row at sourceIndexPath to destinationIndexPath in a table view with the given identifier.
@discussion This step will get the view with the specified accessibility identifier and move the row at sourceIndexPath to destinationIndexPath.
Expand Down
16 changes: 14 additions & 2 deletions Classes/KIFUITestActor.m
Original file line number Diff line number Diff line change
Expand Up @@ -1229,13 +1229,25 @@ - (UITableViewCell *)waitForCellAtIndexPath:(NSIndexPath *)indexPath inTableView
}

- (UICollectionViewCell *)waitForCellAtIndexPath:(NSIndexPath *)indexPath inCollectionViewWithAccessibilityIdentifier:(NSString *)identifier
{
return [self waitForCellAtIndexPath:indexPath inCollectionViewWithAccessibilityIdentifier:identifier atPosition:UICollectionViewScrollPositionCenteredHorizontally |
UICollectionViewScrollPositionCenteredVertically];
}

- (UICollectionViewCell *)waitForCellAtIndexPath:(NSIndexPath *)indexPath inCollectionViewWithAccessibilityIdentifier:(NSString *)identifier atPosition:(UICollectionViewScrollPosition)position;
{
UICollectionView *collectionView;
[self waitForAccessibilityElement:NULL view:&collectionView withIdentifier:identifier tappable:NO];
return [self waitForCellAtIndexPath:indexPath inCollectionView:collectionView];
return [self waitForCellAtIndexPath:indexPath inCollectionView:collectionView atPosition:position];
}

- (UICollectionViewCell *)waitForCellAtIndexPath:(NSIndexPath *)indexPath inCollectionView:(UICollectionView *)collectionView
{
return [self waitForCellAtIndexPath:indexPath inCollectionView:collectionView atPosition:UICollectionViewScrollPositionCenteredHorizontally |
UICollectionViewScrollPositionCenteredVertically];
}

- (UICollectionViewCell *)waitForCellAtIndexPath:(NSIndexPath *)indexPath inCollectionView:(UICollectionView *)collectionView atPosition:(UICollectionViewScrollPosition)position
{
if (![collectionView isKindOfClass:[UICollectionView class]]) {
[self failWithError:[NSError KIFErrorWithFormat:@"View is not a collection view"] stopTest:YES];
Expand Down Expand Up @@ -1266,7 +1278,7 @@ - (UICollectionViewCell *)waitForCellAtIndexPath:(NSIndexPath *)indexPath inColl
}];

[collectionView scrollToItemAtIndexPath:indexPath
atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally | UICollectionViewScrollPositionCenteredVertically
atScrollPosition:position
animated:[[self class] testActorAnimationsEnabled]];

// waitForAnimationsToFinish doesn't allow collection view to settle when animations are sped up
Expand Down