Skip to content

Commit

Permalink
Stabilize the pull to refresh tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Martin committed Sep 7, 2024
1 parent c3cc4cc commit a776837
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 85 deletions.
32 changes: 14 additions & 18 deletions KIF Tests/AccessibilityIdentifierPullToRefreshTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,27 @@ @interface AccessibilityIdentifierPullToRefreshTests : KIFTestCase

@implementation AccessibilityIdentifierPullToRefreshTests

-(void) testPullToRefreshByAccessibilityIdentifier
- (void)afterEach
{
UITableView *tableView;
[tester waitForAccessibilityElement:NULL view:&tableView withIdentifier:@"Test Suite TableView" tappable:NO];

[tester tapViewWithAccessibilityLabel:@"Reset Refresh Control"];
[tester pullToRefreshViewWithAccessibilityIdentifier:@"Test Suite TableView"];
[tester waitForViewWithAccessibilityLabel:@"Bingo!"];
[tester waitForAbsenceOfViewWithAccessibilityLabel:@"Bingo!"];
// For some reason, the pull to refresh is ending before we call endRefreshing.
// For more context, see the comment in the PullToRefreshTests class.
[tester waitForTimeInterval:3.0];
}

-(void) testPullToRefreshByAccessibilityIdentifierWithDuration
- (void)testPullToRefreshByAccessibilityIdentifier
{
UITableView *tableView;
[tester waitForAccessibilityElement:NULL view:&tableView withIdentifier:@"Test Suite TableView" tappable:NO];

[tester tapViewWithAccessibilityLabel:@"Reset Refresh Control"];
[tester pullToRefreshViewWithAccessibilityIdentifier:@"Test Suite TableView" pullDownDuration:KIFPullToRefreshInAboutThreeSeconds];
[tester waitForViewWithAccessibilityLabel:@"Bingo!"];
[tester waitForAbsenceOfViewWithAccessibilityLabel:@"Bingo!"];
[tester waitForViewWithAccessibilityIdentifier:@"Test Suite TableView"];
[tester pullToRefreshViewWithAccessibilityIdentifier:@"Test Suite TableView"];
[tester waitForViewWithAccessibilityLabel:@"Bingo!"];
[tester waitForAbsenceOfViewWithAccessibilityLabel:@"Bingo!"];
}

- (void)afterEach
- (void)testPullToRefreshByAccessibilityIdentifierWithDuration
{
[tester waitForAnimationsToFinish];
[tester waitForViewWithAccessibilityIdentifier:@"Test Suite TableView"];
[tester pullToRefreshViewWithAccessibilityIdentifier:@"Test Suite TableView" pullDownDuration:KIFPullToRefreshInAboutAHalfSecond];
[tester waitForViewWithAccessibilityLabel:@"Bingo!"];
[tester waitForAbsenceOfViewWithAccessibilityLabel:@"Bingo!"];
}

@end
35 changes: 24 additions & 11 deletions KIF Tests/PullToRefreshTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,43 @@ @interface PullToRefreshTests : KIFTestCase

@implementation PullToRefreshTests

-(void) testPullToRefreshByAccessibilityLabelWithDuration
- (void)afterEach
{
UITableView *tableView;
[tester waitForAccessibilityElement:NULL view:&tableView withIdentifier:@"Test Suite TableView" tappable:NO];

[tester pullToRefreshViewWithAccessibilityLabel:@"Table View" pullDownDuration:KIFPullToRefreshInAboutThreeSeconds];
[tester waitForViewWithAccessibilityLabel:@"Bingo!"];
[tester waitForAbsenceOfViewWithAccessibilityLabel:@"Bingo!"];
// For some reason, on iOS 16.4 w/ Xcode 14.3.1, the pull to refresh is ending before
// we call endRefreshing from `-[TestSuiteViewController pullToRefreshHandler].
//
// It seems like there is some difference in how we're synthesizing the touch events
// compared to what happens when a user sends the touch events. Set a symbolic breakpoint
// in "-[_UIRefreshControlModernContentView didTransitionFromState:toState:]" to see this
// in action. The register $x2 contains the `fromState` and $x3 contains the `toState`.
//
// KIF: 3 -> 1 (many times), 3 -> 2, 3 -> 3, 3 -> 0
// User: 0 -> 1, 1 -> 1 (many times), 1 -> 2, 2 -> 3, 3 -> 4, 4 -> 0
//
// So it seems like something is going wrong in translating the HID events in the
// `kif_IOHIDEventWithTouches` phases to appropriate UIResfrashControl states.
[tester waitForTimeInterval:3.0];
}

[tester waitForTimeInterval:5.0f]; //make sure the PTR is finished.
- (void)testPullToRefreshByAccessibilityLabelWithDuration
{
[tester waitForViewWithAccessibilityIdentifier:@"Test Suite TableView"];
[tester pullToRefreshViewWithAccessibilityLabel:@"Table View" pullDownDuration:KIFPullToRefreshInAboutAHalfSecond];
[tester waitForViewWithAccessibilityLabel:@"Bingo!"];
[tester waitForAbsenceOfViewWithAccessibilityLabel:@"Bingo!"];
}

-(void) testPullToRefreshWithBigContentSize
- (void)testPullToRefreshWithBigContentSize
{
UITableView *tableView;
[tester waitForAccessibilityElement:NULL view:&tableView withIdentifier:@"Test Suite TableView" tappable:NO];
CGSize originalSize = tableView.contentSize;
tableView.contentSize = CGSizeMake(1000, 10000);

[tester pullToRefreshViewWithAccessibilityLabel:@"Table View" pullDownDuration:KIFPullToRefreshInAboutThreeSeconds];
[tester pullToRefreshViewWithAccessibilityLabel:@"Table View" pullDownDuration:KIFPullToRefreshInAboutAHalfSecond];
[tester waitForViewWithAccessibilityLabel:@"Bingo!"];
[tester waitForAbsenceOfViewWithAccessibilityLabel:@"Bingo!"];

[tester waitForTimeInterval:5.0f]; //make sure the PTR is finished.
tableView.contentSize = originalSize;
}

Expand Down
17 changes: 11 additions & 6 deletions KIF Tests/PullToRefreshTests_ViewTestActor.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,31 @@ @interface PullToRefreshTests_ViewTestActor : KIFTestCase

@implementation PullToRefreshTests_ViewTestActor

-(void) testPullToRefreshByAccessibilityLabelWithDuration
- (void)afterEach
{
// For some reason, the pull to refresh is ending before we call endRefreshing.
// For more context, see the comment in the PullToRefreshTests class.
[tester waitForTimeInterval:3.0];
}

- (void)testPullToRefreshByAccessibilityLabelWithDuration
{
[[viewTester usingIdentifier:@"Test Suite TableView"] waitForView];
[[viewTester usingLabel:@"Table View"] pullToRefreshWithDuration:KIFPullToRefreshInAboutOneSecond];
[[viewTester usingLabel:@"Table View"] pullToRefreshWithDuration:KIFPullToRefreshInAboutAHalfSecond];
[[viewTester usingLabel:@"Bingo!"] waitForView];
[[viewTester usingLabel:@"Bingo!"] waitForAbsenceOfView];
[viewTester waitForTimeInterval:1.0f];
}

-(void) testPullToRefreshWithBigContentSize
- (void)testPullToRefreshWithBigContentSize
{

UITableView *tableView = (id)[[viewTester usingIdentifier:@"Test Suite TableView"] waitForView];
CGSize originalSize = tableView.contentSize;
tableView.contentSize = CGSizeMake(1000, 10000);

[[viewTester usingLabel:@"Table View"] pullToRefreshWithDuration:KIFPullToRefreshInAboutOneSecond];
[[viewTester usingLabel:@"Table View"] pullToRefreshWithDuration:KIFPullToRefreshInAboutAHalfSecond];
[[viewTester usingLabel:@"Bingo!"] waitForView];
[[viewTester usingLabel:@"Bingo!"] waitForAbsenceOfView];
[viewTester waitForTimeInterval:1.0f];

tableView.contentSize = originalSize;
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/KIF/Classes/KIFUITestActor.m
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,8 @@ - (void)pullToRefreshAccessibilityElement:(UIAccessibilityElement *)element inVi
// Can handle only the touchable space.
CGRect elementFrame = [viewToSwipe convertRect:viewToSwipe.bounds toView:[UIApplication sharedApplication].keyWindow.rootViewController.view];
CGPoint swipeStart = CGPointCenteredInRect(elementFrame);
CGPoint swipeDisplacement = CGPointMake(CGRectGetMidX(elementFrame), CGRectGetMaxY(elementFrame));
swipeStart.y = swipeStart.y - CGRectGetMaxY(elementFrame) / 4.0;
CGPoint swipeDisplacement = CGPointMake(0, CGRectGetMaxY(elementFrame) / 2.0);

[viewToSwipe dragFromPoint:swipeStart displacement:swipeDisplacement steps:kNumberOfPointsInSwipePath];
}
Expand Down
Loading

0 comments on commit a776837

Please sign in to comment.