From 604dc2bcc78e5db51e2ed14ebefcc34bd95ad18a Mon Sep 17 00:00:00 2001 From: Derek Ostrander Date: Thu, 18 Feb 2021 12:46:43 -0500 Subject: [PATCH] Add inset on drag and tests --- .github/workflows/build.yml | 5 ++--- KIF Tests/ScrollViewTests_ViewTestActor.m | 11 ++++++++++ Sources/KIF/Classes/KIFUITestActor.m | 19 ++++++++++++++++++ .../Base.lproj/MainStoryboard.storyboard | 7 ++++++- Test Host/ScrollViewController.m | 20 +++++++++++++++++++ 5 files changed, 58 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1f9901fc3..ceaf06bb1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,10 +20,9 @@ jobs: strategy: matrix: run-config: - - { xcode_version: '10.3', simulator: 'name=iPad (5th generation),OS=12.4' } - { xcode_version: '10.3', simulator: 'name=iPhone 8,OS=12.4' } - - { xcode_version: '11.7', simulator: 'name=iPhone SE (2nd generation),OS=13.7' } - - { xcode_version: '12.2', simulator: 'name=iPhone SE (2nd generation),OS=14.2' } + - { xcode_version: '11.7', simulator: 'name=iPhone 8,OS=13.7' } + - { xcode_version: '12.2', simulator: 'name=iPad Pro (12.9-inch) (4th generation),OS=14.2' } steps: - name: Checkout Project diff --git a/KIF Tests/ScrollViewTests_ViewTestActor.m b/KIF Tests/ScrollViewTests_ViewTestActor.m index 9a5eb90a5..0519c5ce9 100644 --- a/KIF Tests/ScrollViewTests_ViewTestActor.m +++ b/KIF Tests/ScrollViewTests_ViewTestActor.m @@ -8,6 +8,8 @@ #import #import "KIFTestStepValidation.h" +#import "UIAccessibilityElement-KIFAdditions.h" +#import "UIView-KIFAdditions.h" @interface ScrollViewTests_ViewTestActor : KIFTestCase @end @@ -37,4 +39,13 @@ - (void)testScrollingToTapOffscreenTextView [[viewTester usingLabel:@"TextView"] tap]; } +- (void)testScrollingDownAndUp +{ + [[viewTester usingLabel:@"Long Scroll View"] scrollByFractionOfSizeHorizontal:0 vertical:-1]; + [[viewTester usingLabel:@"Bottom Label"] waitForView]; + + [[viewTester usingLabel:@"Long Scroll View"] scrollByFractionOfSizeHorizontal:0 vertical:1]; + [[viewTester usingLabel:@"Top Label"] waitForView]; +} + @end diff --git a/Sources/KIF/Classes/KIFUITestActor.m b/Sources/KIF/Classes/KIFUITestActor.m index 54cdfae82..29a30e358 100644 --- a/Sources/KIF/Classes/KIFUITestActor.m +++ b/Sources/KIF/Classes/KIFUITestActor.m @@ -1311,6 +1311,25 @@ - (void)scrollAccessibilityElement:(UIAccessibilityElement *)element inView:(UIV scrollStart.x -= scrollDisplacement.x / 2; scrollStart.y -= scrollDisplacement.y / 2; + // Scrolling does not work if we are at the end of the view + // So if our scroll start is equal to the heigh, inset 5 + if (scrollStart.x == CGRectGetWidth(elementFrame)) { + if (scrollDisplacement.x < 0) { + scrollStart.x -= CGRectGetWidth(elementFrame) * 0.05; + } else { + scrollStart.x += CGRectGetWidth(elementFrame) * 0.05; + } + + } + + if (scrollStart.y == CGRectGetHeight(elementFrame)) { + if (scrollDisplacement.y < 0) { + scrollStart.y -= CGRectGetHeight(elementFrame) * 0.05; + } else { + scrollStart.y += CGRectGetHeight(elementFrame) * 0.05; + } + } + [viewToScroll dragFromPoint:scrollStart displacement:scrollDisplacement steps:kNumberOfPointsInScrollPath]; [self waitForAnimationsToFinish]; diff --git a/Test Host/Base.lproj/MainStoryboard.storyboard b/Test Host/Base.lproj/MainStoryboard.storyboard index d019907f4..7fde44855 100644 --- a/Test Host/Base.lproj/MainStoryboard.storyboard +++ b/Test Host/Base.lproj/MainStoryboard.storyboard @@ -1683,8 +1683,12 @@ Line Break + + + + - + @@ -1692,6 +1696,7 @@ Line Break + diff --git a/Test Host/ScrollViewController.m b/Test Host/ScrollViewController.m index 60e315c5b..1d4ad88e9 100644 --- a/Test Host/ScrollViewController.m +++ b/Test Host/ScrollViewController.m @@ -9,6 +9,7 @@ #import @interface ScrollViewController : UIViewController +@property (weak, nonatomic) IBOutlet UIScrollView *longScrollview; @property (weak, nonatomic) IBOutlet UIScrollView *scrollView; @end @@ -23,6 +24,25 @@ - (void)viewDidLoad self.scrollView.contentSize = CGSizeMake(2000, 2000); self.scrollView.delegate = self; + self.longScrollview.accessibilityLabel = @"Long Scroll View"; + CGFloat longScrollViewHeight = CGRectGetHeight(self.longScrollview.bounds) * 2; + self.longScrollview.contentSize = CGSizeMake(CGRectGetWidth(self.longScrollview.bounds), longScrollViewHeight); + self.longScrollview.backgroundColor = UIColor.redColor; + + UILabel *topLabel = [[UILabel alloc] init]; + topLabel.text = @"THIS IS THE TOP"; + topLabel.accessibilityLabel = @"Top Label"; + topLabel.textAlignment = UITextAlignmentCenter; + [self.longScrollview addSubview:topLabel]; + topLabel.frame = CGRectMake(0, 0, CGRectGetWidth(self.longScrollview.bounds), 40); + + UILabel *bottomLabel = [[UILabel alloc] init]; + bottomLabel.text = @"THIS IS THE BOTTOM"; + bottomLabel.accessibilityLabel = @"Bottom Label"; + bottomLabel.textAlignment = UITextAlignmentCenter; + [self.longScrollview addSubview:bottomLabel]; + bottomLabel.frame = CGRectMake(0, longScrollViewHeight - 40, CGRectGetWidth(self.longScrollview.bounds), 40); + UIButton *bottomButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [bottomButton setTitle:@"Down" forState:UIControlStateNormal]; bottomButton.backgroundColor = [UIColor greenColor];