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 19, 2024
1 parent 8757ba8 commit eaa3168
Show file tree
Hide file tree
Showing 8 changed files with 288 additions and 72 deletions.
36 changes: 36 additions & 0 deletions KIF Tests/AccessibilityActivationTests_ViewTestActor.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// AccessibilityActivateTests_ViewTestActor.m
// KIF Tests
//
// Created by Alex Odawa on 09/07/2024.
//

#import <KIF/KIF.h>

@interface AccessibilityActivateTests_ViewTestActor : KIFTestCase
@end


@implementation AccessibilityActivateTests_ViewTestActor

- (void)beforeEach
{
[[viewTester usingLabel:@"Accessibility"] tap];
}

- (void)afterEach
{
[[[viewTester usingLabel:@"Test Suite"] usingTraits:UIAccessibilityTraitButton] tap];
}

- (void)testAccessibilityActivate
{
[[viewTester usingLabel:@"AccessibilityView"] performAccessibilityActivateWithExpectedResult: YES];
[[viewTester usingValue:@"Activated: 1"] waitForView];

[[viewTester usingLabel:@"AccessibilitySwitch"] setSwitchOn:false];
[[viewTester usingLabel:@"AccessibilityView"] performAccessibilityActivateWithExpectedResult: NO];
[[viewTester usingValue:@"Activated: 2"] waitForView];
}

@end
8 changes: 4 additions & 4 deletions KIF Tests/CustomActionTests_ViewTestActor.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ @implementation CustomActionTests_ViewTestActor

- (void)beforeEach
{
[[viewTester usingLabel:@"Tapping"] tap];
[[viewTester usingLabel:@"Accessibility"] tap];
}

- (void)afterEach
Expand All @@ -26,14 +26,14 @@ - (void)afterEach
- (void)testCustomActions
{
if (@available(iOS 13.0, *)) {
[[viewTester usingLabel:@"theStepper"] activateCustomActionWithName:@"Action With block handler"];
[[viewTester usingLabel:@"AccessibilityView"] activateCustomActionWithName:@"Action With block handler"];
}

for (NSString *name in @[@"Action without argument", @"Action with argument"]) {
[[viewTester usingLabel:@"theStepper"] activateCustomActionWithName:name];
[[viewTester usingLabel:@"AccessibilityView"] activateCustomActionWithName:name];
}

[[viewTester usingLabel:@"theStepper"] activateCustomActionWithName:@"Action that fails" expectedResult:NO];
[[viewTester usingLabel:@"AccessibilityView"] activateCustomActionWithName:@"Action that fails" expectedResult:NO];
}

@end
8 changes: 8 additions & 0 deletions KIF.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@
9CC881AC1AD4CE4B002CD34C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AAB0726B139719AC008AF393 /* Foundation.framework */; };
9CC881AD1AD4CE50002CD34C /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9CC881A21AD4CAAC002CD34C /* CoreFoundation.framework */; };
9CC967401AD4B1B600576D13 /* KIF.h in Headers */ = {isa = PBXBuildFile; fileRef = 9CC9673F1AD4B1B600576D13 /* KIF.h */; settings = {ATTRIBUTES = (Public, ); }; };
AC2EB99A2C9A04F90082A170 /* AccessibilityActivationTests_ViewTestActor.m in Sources */ = {isa = PBXBuildFile; fileRef = AC2EB9992C9A04F90082A170 /* AccessibilityActivationTests_ViewTestActor.m */; };
AC2EB99D2C9A09790082A170 /* AccessibilityViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AC2EB99C2C9A09790082A170 /* AccessibilityViewController.m */; };
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, ); }; };
Expand Down Expand Up @@ -432,6 +434,8 @@
9CC9673F1AD4B1B600576D13 /* KIF.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KIF.h; sourceTree = "<group>"; };
AAB0726B139719AC008AF393 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
AAB072B413971AEA008AF393 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
AC2EB9992C9A04F90082A170 /* AccessibilityActivationTests_ViewTestActor.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AccessibilityActivationTests_ViewTestActor.m; sourceTree = "<group>"; };
AC2EB99C2C9A09790082A170 /* AccessibilityViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AccessibilityViewController.m; sourceTree = "<group>"; };
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>"; };
Expand Down Expand Up @@ -824,6 +828,7 @@
EB60ECFC177F9031005A041A /* AppDelegate.m */,
EB60ECFD177F9031005A041A /* ShowHideViewController.m */,
EB9FB42617A5BACB00DDF160 /* GestureViewController.m */,
AC2EB99C2C9A09790082A170 /* AccessibilityViewController.m */,
EB60ECFE177F9032005A041A /* TapViewController.m */,
EB60ECFF177F9032005A041A /* TestSuiteViewController.m */,
EA0F25491829839E006FF825 /* CollectionViewController.m */,
Expand Down Expand Up @@ -933,6 +938,7 @@
FA8A3C601A77320000206350 /* SystemAlertTests_ViewTestActor.m */,
8E654FC329D79BD8007F7811 /* OffscreenTests_ViewTestActor.m */,
ACA242E32C3DA55400E6F1B6 /* CustomActionTests_ViewTestActor.m */,
AC2EB9992C9A04F90082A170 /* AccessibilityActivationTests_ViewTestActor.m */,
);
name = "KIFUIViewTestActor Tests";
sourceTree = "<group>";
Expand Down Expand Up @@ -1405,6 +1411,7 @@
FA8A3C5D1A772CD100206350 /* WaitForAbscenceTests_ViewTestActor.m in Sources */,
FA8A3C5B1A77281900206350 /* WebViewTests_ViewTestActor.m in Sources */,
EABD46B11857A0F300A5F081 /* SearchFieldTests.m in Sources */,
AC2EB99A2C9A04F90082A170 /* AccessibilityActivationTests_ViewTestActor.m in Sources */,
EABD46B21857A0F300A5F081 /* CascadingFailureTests.m in Sources */,
EABD46B31857A0F300A5F081 /* CompositionTests.m in Sources */,
CD4E91F01F479A8C005D530C /* CustomPickerTests.m in Sources */,
Expand Down Expand Up @@ -1475,6 +1482,7 @@
EB60ED02177F9032005A041A /* TapViewController.m in Sources */,
2CDEE1CB181DBED200DF6E63 /* PickerController.m in Sources */,
EB60ED03177F9032005A041A /* TestSuiteViewController.m in Sources */,
AC2EB99D2C9A09790082A170 /* 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 @@ -192,6 +192,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 @@ -395,6 +395,8 @@ - (void)swipeFromEdge:(UIRectEdge)edge
[self.actor swipeFromEdge:edge];
}

#pragma mark - Accesibility Actions

- (void)activateCustomActionWithName:(NSString *)name;{
[self activateCustomActionWithName:name expectedResult:YES];
}
Expand All @@ -406,12 +408,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 Test Host/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 eaa3168

Please sign in to comment.