Skip to content

Commit

Permalink
Merge pull request #1041 from zadr/master
Browse files Browse the repository at this point in the history
Add -[KIFUIViewTestActor usingAbsenceOfTraits:]
  • Loading branch information
justinseanmartin committed Jan 19, 2018
2 parents 759aff2 + f20a3be commit 4c71c0e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
27 changes: 23 additions & 4 deletions Classes/KIFUIViewTestActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,50 @@ extern NSString *const inputFieldTestString;
*/

/*!
@abstract Adds a check for an accessibility label to the tester's search pedicate.
@abstract Adds a check for an accessibility label to the tester's search predicate.
@discussion The tester will evaluate accessibility elements looking for a matching accessibility label.
@param accessibilityLabel The accessibility label of an element to match.
@return The message reciever, these methods are intended to be chained together.
*/
- (instancetype)usingLabel:(NSString *)accessibilityLabel;

/*!
@abstract Adds a check for an accessibility identifier to the tester's search pedicate.
@abstract Adds a check for an accessibility identifier to the tester's search predicate.
@discussion The tester will evaluate accessibility elements looking for a matching accessibility identifier.
@param accessibilityIdentifier The accessibility identifier of an element to match.
@return The message reciever, these methods are intended to be chained together.
*/
- (instancetype)usingIdentifier:(NSString *)accessibilityIdentifier;

/*!
@abstract Adds a check for accessibility traits to the tester's search pedicate.
@abstract Adds a check for accessibility traits to the tester's search predicate.
@discussion The tester will evaluate accessibility elements looking for matching accessibility traits.
Note: You cannot assert the lack of accessibility traits by passing in UIAccessibilityTraitsNone.
@param accessibilityTraits The accessibility traits of an element to match.
@return The message reciever, these methods are intended to be chained together.
*/
- (instancetype)usingTraits:(UIAccessibilityTraits)accessibilityTraits;

/*!
@abstract Adds a check for an accessibility value to the tester's search pedicate.
@abstract Adds a check to avoid views with accessibility traits to the tester's search predicate.
@discussion The tester will evaluate accessibility elements for the purposes of excluding accessibility traits.
If more than one trait is supplied in the bitmask, none of them may be present in order for this to be true.
Note: You cannot assert the presence of accessibility traits by passing in UIAccessibilityTraitsNone.
Example:
Given a view with the accessibility traits .Button | .Selected, and we request the absence of .KeyboardCommand, this will match.
Given a view with the accessibility traits .Button | .Selected, and we request the absence of .KeyboardCommand | .PlaysSound, this will match.
Given a view with the accessibility traits .Button | .Selected, and we request the absence of .Selected, this will not match.
Given a view with the accessibility traits .Button | .Selected, and we request the absence of .Button | .Selected, this will not match.
Given a view with the accessibility traits .Button | .Selected, and we request the absence of .KeyboardCommand | .Button, this will not match.
@return The message reciever, these methods are intended to be chained together.
*/
- (instancetype)usingAbsenceOfTraits:(UIAccessibilityTraits)accessibilityTraits;

/*!
@abstract Adds a check for an accessibility value to the tester's search predicate.
@discussion The tester will evaluate accessibility elements looking for a matching accessibility value.
@param accessibilityValue The accessibility value of an element to match.
@return The message reciever, these methods are intended to be chained together.
Expand Down
8 changes: 8 additions & 0 deletions Classes/KIFUIViewTestActor.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ - (instancetype)usingTraits:(UIAccessibilityTraits)accessibilityTraits;
return [self usingPredicate:predicate];
}

- (instancetype)usingAbsenceOfTraits:(UIAccessibilityTraits)accessibilityTraits;
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(accessibilityTraits & %@) != %@", @(accessibilityTraits), @(accessibilityTraits)];
predicate.kifPredicateDescription = [NSString stringWithFormat:@"Accessibility traits excluding \"%@\"", [UIAccessibilityElement stringFromAccessibilityTraits:accessibilityTraits]];

return [self usingPredicate:predicate];
}

- (instancetype)usingValue:(NSString *)accessibilityValue;
{
NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
Expand Down
2 changes: 1 addition & 1 deletion KIF Tests/TappingTests_ViewTestActor.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ - (void)beforeEach

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

- (void)testTappingViewWithAccessibilityLabel
Expand Down
8 changes: 8 additions & 0 deletions Test Host/en.lproj/MainStoryboard.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,14 @@ Line Break
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="gtk-te-yLC">
<rect key="frame" x="285" y="205" width="68" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<accessibility key="accessibilityConfiguration">
<accessibilityTraits key="traits" keyboardKey="YES"/>
</accessibility>
<state key="normal" title="Test Suite"/>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</view>
Expand Down

0 comments on commit 4c71c0e

Please sign in to comment.