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
justinseanmartin committed Sep 18, 2024
1 parent d1cff7d commit 5d1aa9f
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 85 deletions.
34 changes: 16 additions & 18 deletions KIF Tests/AccessibilityIdentifierPullToRefreshTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,29 @@ @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!"];
// Once #1296 is landed, use that on the `waitForView...` calls below.
// The issue is that implicit scrolling the table view when searching for label is causing "Bingo!" to immediately disappear.
[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 waitForTimeInterval:1.0];
[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 waitForTimeInterval:1.0];
[tester waitForViewWithAccessibilityLabel:@"Bingo!"];
[tester waitForAbsenceOfViewWithAccessibilityLabel:@"Bingo!"];
}

@end
26 changes: 15 additions & 11 deletions KIF Tests/PullToRefreshTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,34 @@ @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!"];
// Once #1296 is landed, use that on the `waitForView...` calls below.
// The issue is that implicit scrolling the table view when searching for label is causing "Bingo!" to immediately disappear.
[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 waitForTimeInterval:1.0];
[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 waitForTimeInterval:1.0];
[tester waitForViewWithAccessibilityLabel:@"Bingo!"];
[tester waitForAbsenceOfViewWithAccessibilityLabel:@"Bingo!"];

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

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

@implementation PullToRefreshTests_ViewTestActor

-(void) testPullToRefreshByAccessibilityLabelWithDuration
- (void)afterEach
{
// Once #1296 is landed, use that on the `waitForView...` calls below.
// The issue is that implicit scrolling the table view when searching for label is causing "Bingo!" to immediately disappear.
[tester waitForTimeInterval:3.0];
}

- (void)testPullToRefreshByAccessibilityLabelWithDuration
{
[[viewTester usingIdentifier:@"Test Suite TableView"] waitForView];
[[viewTester usingLabel:@"Table View"] pullToRefreshWithDuration:KIFPullToRefreshInAboutOneSecond];
[[viewTester usingLabel:@"Table View"] pullToRefreshWithDuration:KIFPullToRefreshInAboutAHalfSecond];
[tester waitForTimeInterval:1.0];
[[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];
[tester waitForTimeInterval:1.0];
[[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 5d1aa9f

Please sign in to comment.