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

Conversation

gaperlinski
Copy link

Allows the consumers to specify custom UICollectionViewScrollPosition of the cell they want to scroll to. UICollectionViewScrollPositionCenteredHorizontally | UICollectionViewScrollPositionCenteredVertically remains to the default value.

@justinseanmartin
Copy link
Contributor

justinseanmartin commented Apr 3, 2018

Thanks for the contribution!

Please add a test to the test suite to ensure that it is behaving as expected and I'll happily merge this change. You could maybe check the returned cell's frame relative to the window?

This will help to ensure that we don't regress the behavior and Apple doesn't change it behind the scenes.

@justinseanmartin
Copy link
Contributor

@gaperlinski - Any chance that you'd have time to add a test showing that this works and ensuring that we (or Apple) don't break the functionality in the future? Sad to see this go to waste. Thanks!

@gaperlinski
Copy link
Author

@justinseanmartin I'm back from the dead. Sorry! Will try to cook something up over the weekend.

@harleyjcooper
Copy link
Contributor

If you need any assistance, please let me know. This will help me out with a bug I'm facing. I'll be around to assist through next Wednesday if need be.

@harleyjcooper
Copy link
Contributor

Would something like this do the trick?

diff --git a/KIF Tests/CollectionViewTests.m b/KIF Tests/CollectionViewTests.m
index 47102d1..c5eb214 100644
--- a/KIF Tests/CollectionViewTests.m   
+++ b/KIF Tests/CollectionViewTests.m   
@@ -59,6 +59,27 @@
 }
 
 
+- (void)testTappingLastAndFirstRowAtPositionWithAccessiblityIdentifier
+{
+    UICollectionViewCell *lastCell = [tester waitForCellAtIndexPath:[NSIndexPath indexPathForRow:-1 inSection:-1] inCollectionViewWithAccessibilityIdentifier:@"CollectionView Tests CollectionView" atPosition:UICollectionViewScrollPositionBottom];
+    CGPoint lastPosition = [lastCell.superview convertPoint:lastCell.frame.origin toView:nil];
+    XCTAssertEqual(lastCell.frame.origin.x, lastPosition.x);
+    UICollectionViewCell *firstCell = [tester waitForCellAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] inCollectionViewWithAccessibilityIdentifier:@"CollectionView Tests CollectionView" atPosition:UICollectionViewScrollPositionTop];
+    CGPoint firstPosition = [firstCell.superview convertPoint:firstCell.frame.origin toView:nil];
+    XCTAssertEqual(0, firstPosition.x);
+}
+
+- (void)testTappingLastAndFirstRowAtPositionWithView
+{
+    UICollectionView *collectionView = (UICollectionView *)[[viewTester usingIdentifier:@"CollectionView Tests CollectionView"] waitForView];
+    UICollectionViewCell *lastCell = [tester waitForCellAtIndexPath:[NSIndexPath indexPathForRow:-1 inSection:-1] inCollectionView:collectionView atPosition:UICollectionViewScrollPositionBottom];
+    CGPoint lastPosition = [lastCell.superview convertPoint:lastCell.frame.origin toView:nil];
+    XCTAssertEqual(lastCell.frame.origin.x, lastPosition.x);
+    UICollectionViewCell *firstCell = [tester waitForCellAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] inCollectionView:collectionView atPosition:UICollectionViewScrollPositionTop];
+    CGPoint firstPosition = [firstCell.superview convertPoint:firstCell.frame.origin toView:nil];
+    XCTAssertEqual(0, firstPosition.x);
+}
+
 - (void)testOutOfBounds
 {
     KIFExpectFailure([[tester usingTimeout:1] tapItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:99] inCollectionViewWithAccessibilityIdentifier:@"CollectionView Tests CollectionView"]);```

@harleyjcooper
Copy link
Contributor

@gaperlinski I can't really make any changes so I opened up #1109

@gaperlinski
Copy link
Author

@harleyjcooper, sorry for leaving you hanging. For some reason, I didn't get any notifications about these messages. It LGMT but it looks like Travis CI is not loving the iPad Pro simulator...

@justinseanmartin
Copy link
Contributor

Going to close this in favor of #1109. Feel free to reopen if you take this back over from @harleyjcooper .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants