Skip to content

Commit

Permalink
Adding test
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyalPineapple committed Sep 24, 2024
1 parent b3367d3 commit 7457790
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 26 deletions.
56 changes: 37 additions & 19 deletions TestHost/AccessibilityViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ @interface AccessibilityViewController_AccessibilityView : UIView
@property (nonatomic, assign) BOOL activationReturnValue;
@property (nonatomic, assign) int activationCount;

@property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) UILabel *tapLabel;
@property (nonatomic, strong) UILabel *swtichLabel;
@property (nonatomic, strong) UISwitch *activationSwitch;


@end


Expand All @@ -24,16 +24,16 @@ - (instancetype)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
self.isAccessibilityElement = YES;
self.accessibilityLabel = @"AccessibilityView";



self.activationReturnValue = YES;

self.label = [[UILabel alloc] initWithFrame: CGRectZero];
[self addSubview:self.label];

self.backgroundColor = [UIColor systemTealColor];
self.label.text = @"Returns YES";

self.tapLabel = [[UILabel alloc] initWithFrame: CGRectZero];
self.tapLabel.text = @"Awaiting tap";
[self addSubview:self.tapLabel];

self.swtichLabel = [[UILabel alloc] initWithFrame: CGRectZero];
self.swtichLabel.text = @"Returns YES";
[self addSubview:self.swtichLabel];

self.activationSwitch = [[UISwitch alloc] initWithFrame: CGRectZero];
[self addSubview: self.activationSwitch];
Expand All @@ -50,27 +50,38 @@ - (void)toggleReturnValue {

if (self.activationReturnValue == YES) {
self.backgroundColor = [UIColor systemTealColor];
self.label.text = @"Returns YES";
self.swtichLabel.text = @"Returns YES";
} else {
self.backgroundColor = [UIColor systemTealColor];
self.label.text = @"Returns NO";
self.swtichLabel.text = @"Returns NO";
}
[self setNeedsLayout];
}

-(void)layoutSubviews {
[super layoutSubviews];
[self.label sizeToFit];
self.label.frame = CGRectMake((self.frame.size.width - self.label.frame.size.width) / 2,
(self.frame.size.height - self.label.frame.size.height) / 2,
self.label.frame.size.width,
self.label.frame.size.height);
[self.tapLabel sizeToFit];
self.tapLabel.frame = CGRectMake(20,
20,
self.tapLabel.frame.size.width,
self.tapLabel.frame.size.height);

[self.swtichLabel sizeToFit];
self.swtichLabel.frame = CGRectMake(20,
CGRectGetMaxY(self.tapLabel.frame) + 40,
self.swtichLabel.frame.size.width,
self.swtichLabel.frame.size.height);

[self.activationSwitch sizeToFit];
self.activationSwitch.frame = CGRectMake((self.frame.size.width - self.activationSwitch.frame.size.width) / 2,
CGRectGetMaxY(self.label.frame) + 10 ,
self.activationSwitch.frame = CGRectMake(20,
CGRectGetMaxY(self.swtichLabel.frame) + 10 ,
self.activationSwitch.frame.size.width,
self.activationSwitch.frame.size.width);

}

- (NSString *)accessibilityValue {
return self.tapLabel.text;
}

- (BOOL)accessibilityActivate {
Expand All @@ -79,6 +90,13 @@ - (BOOL)accessibilityActivate {
return self.activationReturnValue;
}


- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
CGPoint location = [[touches anyObject] locationInView: self];
self.tapLabel.text = [NSString stringWithFormat:@"Tapped - x:%.04f, y:%.04f", location.x, location.y];
[self setNeedsLayout];
}

@end

@interface AccessibilityViewController : UIViewController
Expand Down
14 changes: 7 additions & 7 deletions TestHost/Base.lproj/MainStoryboard.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -2170,26 +2170,26 @@ Line Break
<viewControllerLayoutGuide type="top" id="shx-5S-eMw"/>
<viewControllerLayoutGuide type="bottom" id="u8z-PF-PIc"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="HtV-3z-P6p" customClass="AccessibilityViewController_AccessibilityView">
<view key="view" contentMode="scaleToFill" id="HtV-3z-P6p">
<rect key="frame" x="0.0" y="0.0" width="414" height="804"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES" flexibleMaxY="YES"/>
<subviews>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="1Qj-vC-6qF">
<rect key="frame" x="72" y="367" width="240" height="128"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="1Qj-vC-6qF" customClass="AccessibilityViewController_AccessibilityView">
<rect key="frame" x="20" y="76" width="374" height="657"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemPurpleColor"/>
</view>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
<navigationItem key="navigationItem" id="4hs-zD-BI5"/>
<connections>
<outlet property="accessibilityView" destination="HtV-3z-P6p" id="fRH-1a-uNU"/>
<outlet property="accessibilityView" destination="1Qj-vC-6qF" id="YDb-m4-vKE"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="N4E-Ay-Je9" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1967" y="1449"/>
<point key="canvasLocation" x="1966.6666666666667" y="1448.4375"/>
</scene>
<!--Animation View Controller-->
<scene sceneID="odg-A0-FBB">
Expand Down
14 changes: 14 additions & 0 deletions Tests/AccessibilityActivationTests_ViewTestActor.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

#import <KIF/KIF.h>
#import <UIKit/UIAccessibility.h>

@interface AccessibilityActivateTests_ViewTestActor : KIFTestCase
@end
Expand Down Expand Up @@ -33,4 +34,17 @@ - (void)testAccessibilityActivate
[[viewTester usingValue:@"Activated: 2"] waitForView];
}

- (void)testAccessibilityActiationPoint
{
UIView *view = [[viewTester usingValue: @"Awaiting tap"] waitForView];

[view setAccessibilityActivationPoint: [view.window convertPoint:CGPointMake(25.0, 50.0) fromView:view]];
[[viewTester usingLabel: @"AccessibilityView"] tap];
[[viewTester usingValue:@"Tapped - x:25.0000, y:50.0000"] waitForView];

[view setAccessibilityActivationPoint: [view.window convertPoint:CGPointMake(50.0, 25.0) fromView:view]];
[[viewTester usingLabel: @"AccessibilityView"] tap];
[[viewTester usingValue:@"Tapped - x:50.0000, y:25.0000"] waitForView];
}

@end

0 comments on commit 7457790

Please sign in to comment.