Skip to content

Commit

Permalink
added performAccessibilityActivateWithEpectedResult: to KIFUIViewTest…
Browse files Browse the repository at this point in the history
…Actor
  • Loading branch information
RoyalPineapple committed Sep 24, 2024
1 parent c36bb1f commit 4dac875
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 61 deletions.
8 changes: 8 additions & 0 deletions KIF.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
ACA242E42C3DA55400E6F1B6 /* CustomActionTests_ViewTestActor.m in Sources */ = {isa = PBXBuildFile; fileRef = ACA242E32C3DA55400E6F1B6 /* CustomActionTests_ViewTestActor.m */; };
ACA242E72C3DB47400E6F1B6 /* UIAccessibilityCustomAction+KIFAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = ACA242E52C3DB46A00E6F1B6 /* UIAccessibilityCustomAction+KIFAdditions.m */; };
ACA242E92C3DB4EA00E6F1B6 /* UIAccessibilityCustomAction+KIFAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = ACA242E82C3DB4B000E6F1B6 /* UIAccessibilityCustomAction+KIFAdditions.h */; settings = {ATTRIBUTES = (Private, ); }; };
ACDB72682CA3146B00D9796E /* AccessibilityViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ACDB72672CA3146B00D9796E /* AccessibilityViewController.m */; };
ACDB726A2CA314A800D9796E /* AccessibilityActivationTests_ViewTestActor.m in Sources */ = {isa = PBXBuildFile; fileRef = ACDB72692CA314A800D9796E /* AccessibilityActivationTests_ViewTestActor.m */; };
AE62FCD01A1D20E5002B10DA /* WebViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AE62FCCF1A1D20E5002B10DA /* WebViewTests.m */; };
AE62FCD61A1D2447002B10DA /* WebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AE62FCD51A1D2447002B10DA /* WebViewController.m */; };
AE62FCD81A1D2667002B10DA /* index.html in Resources */ = {isa = PBXBuildFile; fileRef = AE62FCD71A1D2667002B10DA /* index.html */; };
Expand Down Expand Up @@ -321,6 +323,8 @@
ACA242E32C3DA55400E6F1B6 /* CustomActionTests_ViewTestActor.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CustomActionTests_ViewTestActor.m; sourceTree = "<group>"; };
ACA242E52C3DB46A00E6F1B6 /* UIAccessibilityCustomAction+KIFAdditions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIAccessibilityCustomAction+KIFAdditions.m"; sourceTree = "<group>"; };
ACA242E82C3DB4B000E6F1B6 /* UIAccessibilityCustomAction+KIFAdditions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIAccessibilityCustomAction+KIFAdditions.h"; sourceTree = "<group>"; };
ACDB72672CA3146B00D9796E /* AccessibilityViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AccessibilityViewController.m; sourceTree = "<group>"; };
ACDB72692CA314A800D9796E /* AccessibilityActivationTests_ViewTestActor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AccessibilityActivationTests_ViewTestActor.m; sourceTree = "<group>"; };
AE62FCCF1A1D20E5002B10DA /* WebViewTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebViewTests.m; sourceTree = "<group>"; };
AE62FCD51A1D2447002B10DA /* WebViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebViewController.m; sourceTree = "<group>"; };
AE62FCD71A1D2667002B10DA /* index.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = index.html; sourceTree = "<group>"; };
Expand Down Expand Up @@ -633,6 +637,7 @@
EB60ECC6177F8C83005A041A /* TestHost */ = {
isa = PBXGroup;
children = (
ACDB72672CA3146B00D9796E /* AccessibilityViewController.m */,
3812FB601A1212A700335733 /* AnimationViewController.m */,
2CDEE1CA181DBED200DF6E63 /* PickerController.m */,
CD19A99E1F46482200BF0325 /* CustomPickerController.m */,
Expand Down Expand Up @@ -713,6 +718,7 @@
FA8DA74D1A77117A00E0C644 /* KIFUIViewTestActor Tests */ = {
isa = PBXGroup;
children = (
ACDB72692CA314A800D9796E /* AccessibilityActivationTests_ViewTestActor.m */,
FA4915641A7827D000A78E57 /* PickerTests_ViewTestActor.m */,
B66B1BF5202BCF2000D0E4B2 /* AutocorrectTests_ViewTestActor.m */,
CD4E91F11F479FF2005D530C /* CustomPickerTests_ViewTestActor.m */,
Expand Down Expand Up @@ -987,6 +993,7 @@
FA8A3C5D1A772CD100206350 /* WaitForAbscenceTests_ViewTestActor.m in Sources */,
FA8A3C5B1A77281900206350 /* WebViewTests_ViewTestActor.m in Sources */,
EABD46B11857A0F300A5F081 /* SearchFieldTests.m in Sources */,
ACDB726A2CA314A800D9796E /* AccessibilityActivationTests_ViewTestActor.m in Sources */,
EABD46B21857A0F300A5F081 /* CascadingFailureTests.m in Sources */,
EABD46B31857A0F300A5F081 /* CompositionTests.m in Sources */,
CD4E91F01F479A8C005D530C /* CustomPickerTests.m in Sources */,
Expand Down Expand Up @@ -1057,6 +1064,7 @@
EB60ED02177F9032005A041A /* TapViewController.m in Sources */,
2CDEE1CB181DBED200DF6E63 /* PickerController.m in Sources */,
EB60ED03177F9032005A041A /* TestSuiteViewController.m in Sources */,
ACDB72682CA3146B00D9796E /* AccessibilityViewController.m in Sources */,
D9EA274318F05A6700D87E57 /* ScrollViewController.m in Sources */,
8EAA1EE229D3AF7A008F6029 /* OffscreenViewController.m in Sources */,
3812FB611A1212A700335733 /* AnimationViewController.m in Sources */,
Expand Down
5 changes: 5 additions & 0 deletions Sources/KIF/Classes/KIFUIViewTestActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ extern NSString *const inputFieldTestString;
*/
- (void)activateCustomActionWithName:(NSString *)name expectedResult:(BOOL)expectedResult;

/*!
@abstract Activates a found element via `accessibilityActivate()`.
@param expectedResult The expected boolean return from activation of the element.
*/
- (void)performAccessibilityActivateWithExpectedResult:(BOOL)expectedResult;

#pragma mark Waiting & Finding

Expand Down
19 changes: 19 additions & 0 deletions Sources/KIF/Classes/KIFUIViewTestActor.m
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ - (void)swipeFromEdge:(UIRectEdge)edge
[self.actor swipeFromEdge:edge];
}

#pragma mark - Accesibility Actions

- (void)activateCustomActionWithName:(NSString *)name;{
[self activateCustomActionWithName:name expectedResult:YES];
}
Expand All @@ -414,12 +416,29 @@ - (void)activateCustomActionWithName:(NSString *)name expectedResult:(BOOL)expec

[self runBlock:^KIFTestStepResult(NSError **error) {
if([[found.element KIF_customActionWithName:name] KIF_activate] == expectedResult) {
[self waitForAnimationsToFinish];
return KIFTestStepResultSuccess;
}
[self waitForAnimationsToFinish];
return KIFTestStepResultFailure;
}];
}
}

- (void)performAccessibilityActivateWithExpectedResult:(BOOL)expectedResult;
{
@autoreleasepool {
KIFUIObject *found = [self _predicateSearchWithRequiresMatch:YES mustBeTappable:NO];

[self runBlock:^KIFTestStepResult(NSError **error) {
if([found.element accessibilityActivate] == expectedResult) {
[self waitForAnimationsToFinish];
return KIFTestStepResultSuccess;
}
[self waitForAnimationsToFinish];
return KIFTestStepResultFailure;
}];
}
}

#pragma mark - Scroll/Table/CollectionView Actions
Expand Down
149 changes: 149 additions & 0 deletions TestHost/AccessibilityViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
//
// AccessibilityViewController.m
// Test Host
//
// Created by Alex Odawa on 17/09/2024.
//

#import <UIKit/UIKit.h>

@interface AccessibilityViewController_AccessibilityView : UIView
@property (nonatomic, assign) BOOL activationReturnValue;
@property (nonatomic, assign) int activationCount;

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


@end


@implementation AccessibilityViewController_AccessibilityView

- (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.activationSwitch = [[UISwitch alloc] initWithFrame: CGRectZero];
[self addSubview: self.activationSwitch];

[self.activationSwitch setOn:self.activationReturnValue];
[self.activationSwitch addTarget: self action: @selector(toggleReturnValue) forControlEvents: UIControlEventValueChanged];
self.activationSwitch.accessibilityLabel = @"AccessibilitySwitch";

return self;
}

- (void)toggleReturnValue {
self.activationReturnValue = !self.activationReturnValue;

if (self.activationReturnValue == YES) {
self.backgroundColor = [UIColor systemTealColor];
self.label.text = @"Returns YES";
} else {
self.backgroundColor = [UIColor systemTealColor];
self.label.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.activationSwitch sizeToFit];
self.activationSwitch.frame = CGRectMake((self.frame.size.width - self.activationSwitch.frame.size.width) / 2,
CGRectGetMaxY(self.label.frame) + 10 ,
self.activationSwitch.frame.size.width,
self.activationSwitch.frame.size.width);
}

- (BOOL)accessibilityActivate {
self.activationCount += 1;
self.accessibilityValue = [NSString stringWithFormat:@"Activated: %i", self.activationCount];
return self.activationReturnValue;
}

@end

@interface AccessibilityViewController : UIViewController
@property (weak, nonatomic) IBOutlet AccessibilityViewController_AccessibilityView *accessibilityView;

@end

@implementation AccessibilityViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.accessibilityView.accessibilityCustomActions = [self customActions];
}


- (NSArray *)customActions
{
NSArray *actions = @[self.customActionWithoutArgument, self.customActionWithArgument, self.customActionThatFails];
if (@available(iOS 13.0, *)) {
return [actions arrayByAddingObject: self.customActionWithBlock];
}
return actions;
}

- (UIAccessibilityCustomAction *)customActionWithBlock
{
if (@available(iOS 13.0, *)) {
return [[UIAccessibilityCustomAction alloc] initWithName: @"Action With block handler"
actionHandler:^BOOL(UIAccessibilityCustomAction * _Nonnull customAction) {
return YES;
}];
} else {
return nil;
}
}

- (UIAccessibilityCustomAction *)customActionWithoutArgument
{
return [[UIAccessibilityCustomAction alloc] initWithName:@"Action without argument" target:self selector:@selector(customActionHandlerWithoutArgument)];
}

- (UIAccessibilityCustomAction *)customActionWithArgument
{
return [[UIAccessibilityCustomAction alloc] initWithName:@"Action with argument" target:self selector:@selector(customActionHandlerWithArgument:)];
}

- (UIAccessibilityCustomAction *)customActionThatFails
{
return [[UIAccessibilityCustomAction alloc] initWithName:@"Action that fails" target:self selector:@selector(customActionThatFails)];
}

- (BOOL)customActionHandlerWithoutArgument
{
return YES;
}

- (BOOL)customActionHandlerWithArgument:(UIAccessibilityCustomAction *)action
{
return YES;
}

- (BOOL)customActionHandlerThatFails
{
return NO;
}

@end
Loading

0 comments on commit 4dac875

Please sign in to comment.