Skip to content

Commit

Permalink
Merge pull request #639 from kdlogen/kd-pan-test
Browse files Browse the repository at this point in the history
UIPanGestureRecognizer velocity test cases
  • Loading branch information
phatmann committed Apr 30, 2015
2 parents 47ceab9 + 16b7e77 commit f05f095
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 26 deletions.
83 changes: 83 additions & 0 deletions KIF Tests/GestureTests.m
Expand Up @@ -9,6 +9,16 @@
#import <KIF/KIF.h>
#import <KIF/KIFTestStepValidation.h>
#import <KIF/KIFUITestActor-IdentifierTests.h>
#import <KIF/UIView-KIFAdditions.h>

#define kPanMeAccessibilityString @"Pan Me"
#define kVelocityValueLabelAccessibilityString @"velocityValueLabel"

#define kPanLeftRegex @"^X:-[0-9\\.]+ Y:0.00$"
#define kPanUpRegex @"^X:0.00 Y:-[0-9\\.]+$"
#define kPanRightRegex @"^X:[0-9\\.]+ Y:0.00$"
#define kPanDownRegex @"^X:0.00 Y:[0-9\\.]+$"
#define KPanNoVelocityValue @"^X:0.00 Y:0.00$"

@interface GestureTests : KIFTestCase
@end
Expand Down Expand Up @@ -49,6 +59,79 @@ - (void)testSwipingDown
[tester waitForViewWithAccessibilityLabel:@"Down"];
}

- (void)testPanningLeft
{
NSString* regexPattern = kPanLeftRegex;
NSPredicate *resultTestPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regexPattern];
NSPredicate *noVelocityPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", KPanNoVelocityValue];

UIView* velocityResultView = [tester waitForViewWithAccessibilityLabel:kVelocityValueLabelAccessibilityString];
XCTAssertTrue([velocityResultView isKindOfClass:[UILabel class]], @"Found view is not a UILabel instance!");
UILabel* velocityLabel = (UILabel*)velocityResultView;

UIView* panLabel = [tester waitForTappableViewWithAccessibilityLabel:kPanMeAccessibilityString];
CGPoint centerInView = CGPointMake(panLabel.frame.size.width / 2.0, panLabel.frame.size.height / 2.0);

[panLabel dragFromPoint:centerInView toPoint:CGPointMake(centerInView.x - 30, centerInView.y)];
XCTAssertFalse([noVelocityPredicate evaluateWithObject:velocityLabel.text], @"No valocity value found!");
XCTAssertTrue([resultTestPredicate evaluateWithObject:velocityLabel.text], @"The result doesn`t match the %@ regex pattern", regexPattern);
}

- (void)testPanningRight
{
NSString* regexPattern = kPanRightRegex;
NSPredicate *resultTestPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regexPattern];
NSPredicate *noVelocityPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", KPanNoVelocityValue];

UIView* velocityResultView = [tester waitForViewWithAccessibilityLabel:kVelocityValueLabelAccessibilityString];
XCTAssertTrue([velocityResultView isKindOfClass:[UILabel class]], @"Found view is not a UILabel instance!");
UILabel* velocityLabel = (UILabel*)velocityResultView;

UIView* panLabel = [tester waitForTappableViewWithAccessibilityLabel:kPanMeAccessibilityString];
CGPoint centerInView = CGPointMake(panLabel.frame.size.width / 2.0, panLabel.frame.size.height / 2.0);

[panLabel dragFromPoint:centerInView toPoint:CGPointMake(centerInView.x + 30, centerInView.y)];
XCTAssertFalse([noVelocityPredicate evaluateWithObject:velocityLabel.text], @"No valocity value found!");
XCTAssertTrue([resultTestPredicate evaluateWithObject:velocityLabel.text], @"The result doesn`t match the %@ regex pattern", regexPattern);
}

- (void)testPanningUp
{
NSString* regexPattern = kPanUpRegex;
NSPredicate *resultTestPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regexPattern];
NSPredicate *noVelocityPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", KPanNoVelocityValue];

UIView* velocityResultView = [tester waitForViewWithAccessibilityLabel:kVelocityValueLabelAccessibilityString];
XCTAssertTrue([velocityResultView isKindOfClass:[UILabel class]], @"Found view is not a UILabel instance!");
UILabel* velocityLabel = (UILabel*)velocityResultView;

UIView* panLabel = [tester waitForTappableViewWithAccessibilityLabel:kPanMeAccessibilityString];
CGPoint centerInView = CGPointMake(panLabel.frame.size.width / 2.0, panLabel.frame.size.height / 2.0);

[panLabel dragFromPoint:centerInView toPoint:CGPointMake(centerInView.x, centerInView.y - 30)];
XCTAssertFalse([noVelocityPredicate evaluateWithObject:velocityLabel.text], @"No valocity value found!");
XCTAssertTrue([resultTestPredicate evaluateWithObject:velocityLabel.text], @"The result doesn`t match the %@ regex pattern", regexPattern);
}


- (void)testPanningDown
{
NSString* regexPattern = kPanDownRegex;
NSPredicate *resultTestPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regexPattern];
NSPredicate *noVelocityPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", KPanNoVelocityValue];

UIView* velocityResultView = [tester waitForViewWithAccessibilityLabel:kVelocityValueLabelAccessibilityString];
XCTAssertTrue([velocityResultView isKindOfClass:[UILabel class]], @"Found view is not a UILabel instance!");
UILabel* velocityLabel = (UILabel*)velocityResultView;

UIView* panLabel = [tester waitForTappableViewWithAccessibilityLabel:kPanMeAccessibilityString];
CGPoint centerInView = CGPointMake(panLabel.frame.size.width / 2.0, panLabel.frame.size.height / 2.0);

[panLabel dragFromPoint:centerInView toPoint:CGPointMake(centerInView.x, centerInView.y + 30)];
XCTAssertFalse([noVelocityPredicate evaluateWithObject:velocityLabel.text], @"No valocity value found!");
XCTAssertTrue([resultTestPredicate evaluateWithObject:velocityLabel.text], @"The result doesn`t match the %@ regex pattern", regexPattern);
}

- (void)testMissingSwipeableElement
{
KIFExpectFailure([[tester usingTimeout:0.25] swipeViewWithAccessibilityLabel:@"Unknown" inDirection:KIFSwipeDirectionDown]);
Expand Down
11 changes: 11 additions & 0 deletions Test Host/GestureViewController.m
Expand Up @@ -10,8 +10,10 @@

@interface GestureViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *lastSwipeDescriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel *lastVelocityVeluesLabel;
@property (weak, nonatomic) IBOutlet UILabel *bottomRightLabel;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UILabel *panAreaLabel;

@end

Expand Down Expand Up @@ -44,5 +46,14 @@ - (IBAction)swipedRight:(id)sender
self.lastSwipeDescriptionLabel.text = @"Right";
}

- (IBAction)hadlePanGestureRecognizer:(UIPanGestureRecognizer *)sender
{
self.lastVelocityVeluesLabel.text = [self formattedVelocityValues:[sender velocityInView:self.panAreaLabel]];
}

- (NSString*)formattedVelocityValues:(CGPoint)velocity
{
return [NSString stringWithFormat:@"X:%.2f Y:%.2f", velocity.x, velocity.y];
}

@end
81 changes: 55 additions & 26 deletions Test Host/en.lproj/MainStoryboard.storyboard
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="6254" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" variant="6xAndEarlier" propertyAccessControl="none" initialViewController="3">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="7531" systemVersion="14D131" targetRuntime="iOS.CocoaTouch" variant="6xAndEarlier" propertyAccessControl="none" initialViewController="3">
<dependencies>
<deployment identifier="iOS"/>
<development version="4600" identifier="xcode"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6246"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7520"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
Expand Down Expand Up @@ -1190,30 +1190,6 @@
<rect key="frame" x="0.0" y="64" width="320" height="504"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Swipe Me" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="u9Q-wh-6hh">
<rect key="frame" x="0.0" y="196" width="320" height="100"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<color key="backgroundColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<gestureRecognizers/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="accessibilityIdentifier" value="gestures.swipeMe"/>
</userDefinedRuntimeAttributes>
<connections>
<outletCollection property="gestureRecognizers" destination="sWb-g6-Zbn" appends="YES" id="MEn-RE-WeD"/>
<outletCollection property="gestureRecognizers" destination="lsG-Xj-9Cs" appends="YES" id="pne-b0-ZJx"/>
<outletCollection property="gestureRecognizers" destination="IsH-lh-JEM" appends="YES" id="pWB-4u-UBN"/>
<outletCollection property="gestureRecognizers" destination="gMt-Dj-sxh" appends="YES" id="h0b-Ta-LY6"/>
</connections>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="FMd-oP-yPf">
<rect key="frame" x="0.0" y="168" width="320" height="20"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" id="5Pa-Id-GPM">
<rect key="frame" x="0.0" y="304" width="320" height="200"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
Expand Down Expand Up @@ -1243,6 +1219,52 @@
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
<label opaque="NO" clipsSubviews="YES" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Pan Me" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="QqM-lB-aCp">
<rect key="frame" x="0.0" y="196" width="320" height="100"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<color key="backgroundColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="accessibilityIdentifier" value="gestures.panMe"/>
</userDefinedRuntimeAttributes>
<connections>
<outletCollection property="gestureRecognizers" destination="F0s-aj-f1p" appends="YES" id="zOl-rL-278"/>
</connections>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="2Rr-zq-WBn">
<rect key="frame" x="0.0" y="167" width="320" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
<accessibility key="accessibilityConfiguration" label="velocityValueLabel"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Swipe Me" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="u9Q-wh-6hh">
<rect key="frame" x="0.0" y="48" width="320" height="100"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<color key="backgroundColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<gestureRecognizers/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="accessibilityIdentifier" value="gestures.swipeMe"/>
</userDefinedRuntimeAttributes>
<connections>
<outletCollection property="gestureRecognizers" destination="sWb-g6-Zbn" appends="YES" id="MEn-RE-WeD"/>
<outletCollection property="gestureRecognizers" destination="lsG-Xj-9Cs" appends="YES" id="pne-b0-ZJx"/>
<outletCollection property="gestureRecognizers" destination="IsH-lh-JEM" appends="YES" id="pWB-4u-UBN"/>
<outletCollection property="gestureRecognizers" destination="gMt-Dj-sxh" appends="YES" id="h0b-Ta-LY6"/>
</connections>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="FMd-oP-yPf">
<rect key="frame" x="0.0" y="20" width="320" height="20"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
Expand All @@ -1251,6 +1273,8 @@
<connections>
<outlet property="bottomRightLabel" destination="UYz-K1-bMw" id="KqH-vC-x7j"/>
<outlet property="lastSwipeDescriptionLabel" destination="FMd-oP-yPf" id="nDk-Fo-wrx"/>
<outlet property="lastVelocityVeluesLabel" destination="2Rr-zq-WBn" id="V8r-FS-Eh7"/>
<outlet property="panAreaLabel" destination="QqM-lB-aCp" id="jiO-2d-0LW"/>
<outlet property="scrollView" destination="7cv-bk-ApT" id="9kI-14-6y4"/>
</connections>
</viewController>
Expand All @@ -1275,6 +1299,11 @@
<action selector="swipedRight:" destination="ubg-mt-ea6" id="Wz2-dy-cSh"/>
</connections>
</swipeGestureRecognizer>
<panGestureRecognizer minimumNumberOfTouches="1" id="F0s-aj-f1p">
<connections>
<action selector="hadlePanGestureRecognizer:" destination="ubg-mt-ea6" id="cOQ-Xc-3Pe"/>
</connections>
</panGestureRecognizer>
</objects>
<point key="canvasLocation" x="459" y="754"/>
</scene>
Expand Down

0 comments on commit f05f095

Please sign in to comment.