forked from TextureGroup/Texture
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ASDisplayNode] Expose default Texture-set accessibility values as pr…
…operties (TextureGroup#1170) * Expose default Texture-set accessibility values as properties in ASDisplayNode. Added relevant overrides and tests. * Quick style fixes & add default a11y overrides to ASTextNode too.
- Loading branch information
1 parent
8b70abd
commit 2e58577
Showing
9 changed files
with
226 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// ASButtonNodeTests.m | ||
// Texture | ||
// | ||
// Copyright (c) Pinterest, Inc. All rights reserved. | ||
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
#import <AsyncDisplayKit/ASButtonNode.h> | ||
#import <AsyncDisplayKit/ASDisplayNode+Beta.h> | ||
|
||
@interface ASButtonNodeTests : XCTestCase | ||
@end | ||
|
||
@implementation ASButtonNodeTests | ||
|
||
- (void)testAccessibility | ||
{ | ||
// Setup a button with some title. | ||
ASButtonNode *buttonNode = nil; | ||
buttonNode = [[ASButtonNode alloc] init]; | ||
NSString *title = @"foo"; | ||
[buttonNode setTitle:title withFont:nil withColor:nil forState:UIControlStateNormal]; | ||
|
||
// Verify accessibility properties. | ||
XCTAssertTrue(buttonNode.accessibilityTraits == UIAccessibilityTraitButton, | ||
@"Should have button accessibility trait, instead has %llu", | ||
buttonNode.accessibilityTraits); | ||
XCTAssertTrue(buttonNode.defaultAccessibilityTraits == UIAccessibilityTraitButton, | ||
@"Default accessibility traits should return button accessibility trait, instead " | ||
@"returns %llu", | ||
buttonNode.defaultAccessibilityTraits); | ||
XCTAssertTrue([buttonNode.accessibilityLabel isEqualToString:title], | ||
@"Accessibility label is incorrectly set to \n%@\n when it should be \n%@\n", | ||
buttonNode.accessibilityLabel, title); | ||
XCTAssertTrue([buttonNode.defaultAccessibilityLabel isEqualToString:title], | ||
@"Default accessibility label incorrectly returns \n%@\n when it should be \n%@\n", | ||
buttonNode.defaultAccessibilityLabel, title); | ||
|
||
// Disable the button and verify that accessibility traits has been updated correctly. | ||
buttonNode.enabled = NO; | ||
UIAccessibilityTraits disabledButtonTrait = | ||
UIAccessibilityTraitButton | UIAccessibilityTraitNotEnabled; | ||
XCTAssertTrue(buttonNode.accessibilityTraits == disabledButtonTrait, | ||
@"Should have disabled button accessibility trait, instead has %llu", | ||
buttonNode.accessibilityTraits); | ||
XCTAssertTrue(buttonNode.defaultAccessibilityTraits == disabledButtonTrait, | ||
@"Default accessibility traits should return disabled button accessibility trait, " | ||
@"instead returns %llu", | ||
buttonNode.defaultAccessibilityTraits); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// | ||
// ASTextNode2Tests.m | ||
// TextureTests | ||
// | ||
// Copyright (c) Pinterest, Inc. All rights reserved. | ||
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
|
||
#import <CoreText/CoreText.h> | ||
|
||
#import "ASTestCase.h" | ||
|
||
#import <AsyncDisplayKit/ASDisplayNode+Beta.h> | ||
#import <AsyncDisplayKit/ASTextNode2.h> | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
@interface ASTextNode2Tests : XCTestCase | ||
|
||
@property(nonatomic) ASTextNode2 *textNode; | ||
@property(nonatomic, copy) NSAttributedString *attributedText; | ||
|
||
@end | ||
|
||
@implementation ASTextNode2Tests | ||
|
||
- (void)setUp | ||
{ | ||
[super setUp]; | ||
_textNode = [[ASTextNode2 alloc] init]; | ||
|
||
UIFontDescriptor *desc = [UIFontDescriptor fontDescriptorWithName:@"Didot" size:18]; | ||
NSArray *arr = @[ @{ | ||
UIFontFeatureTypeIdentifierKey : @(kLetterCaseType), | ||
UIFontFeatureSelectorIdentifierKey : @(kSmallCapsSelector) | ||
} ]; | ||
desc = [desc fontDescriptorByAddingAttributes:@{UIFontDescriptorFeatureSettingsAttribute : arr}]; | ||
UIFont *f = [UIFont fontWithDescriptor:desc size:0]; | ||
NSDictionary *d = @{NSFontAttributeName : f}; | ||
NSMutableAttributedString *mas = [[NSMutableAttributedString alloc] | ||
initWithString: | ||
@"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor " | ||
@"incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud " | ||
@"exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure " | ||
@"dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. " | ||
@"Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt " | ||
@"mollit anim id est laborum." | ||
attributes:d]; | ||
NSMutableParagraphStyle *para = [NSMutableParagraphStyle new]; | ||
para.alignment = NSTextAlignmentCenter; | ||
para.lineSpacing = 1.0; | ||
[mas addAttribute:NSParagraphStyleAttributeName value:para range:NSMakeRange(0, mas.length - 1)]; | ||
|
||
// Vary the linespacing on the last line | ||
NSMutableParagraphStyle *lastLinePara = [NSMutableParagraphStyle new]; | ||
lastLinePara.alignment = para.alignment; | ||
lastLinePara.lineSpacing = 5.0; | ||
[mas addAttribute:NSParagraphStyleAttributeName | ||
value:lastLinePara | ||
range:NSMakeRange(mas.length - 1, 1)]; | ||
|
||
_attributedText = mas; | ||
_textNode.attributedText = _attributedText; | ||
} | ||
|
||
- (void)testAccessibility | ||
{ | ||
XCTAssertTrue(_textNode.isAccessibilityElement, @"Should be an accessibility element"); | ||
XCTAssertTrue(_textNode.accessibilityTraits == UIAccessibilityTraitStaticText, | ||
@"Should have static text accessibility trait, instead has %llu", | ||
_textNode.accessibilityTraits); | ||
XCTAssertTrue(_textNode.defaultAccessibilityTraits == UIAccessibilityTraitStaticText, | ||
@"Default accessibility traits should return static text accessibility trait, " | ||
@"instead returns %llu", | ||
_textNode.defaultAccessibilityTraits); | ||
|
||
XCTAssertTrue([_textNode.accessibilityLabel isEqualToString:_attributedText.string], | ||
@"Accessibility label is incorrectly set to \n%@\n when it should be \n%@\n", | ||
_textNode.accessibilityLabel, _attributedText.string); | ||
XCTAssertTrue([_textNode.defaultAccessibilityLabel isEqualToString:_attributedText.string], | ||
@"Default accessibility label incorrectly returns \n%@\n when it should be \n%@\n", | ||
_textNode.defaultAccessibilityLabel, _attributedText.string); | ||
} | ||
|
||
@end |