forked from fachrifaul/Texture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASButtonNodeTests.mm
78 lines (68 loc) · 3.41 KB
/
ASButtonNodeTests.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// ASButtonNodeTests.mm
// 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>
#import <AsyncDisplayKit/ASTextNode.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);
}
/// Test the accessbility label consistency for buttons that do not have a title
/// In this test case, the button is empty but its titleNode is not nil.
/// If we give this button an accessibility label and then change its state,
/// we still want the accessbility unchanged, instead of going back to the default accessibility label.
- (void)testAccessibilityWithoutATitle
{
ASButtonNode *buttonNode = [[ASButtonNode alloc] init];
buttonNode.accessibilityLabel = @"My Test";
// Make sure the title node is not nil.
buttonNode.titleNode.placeholderColor = [UIColor whiteColor];
buttonNode.selected = YES;
XCTAssertTrue([buttonNode.accessibilityLabel isEqualToString:@"My Test"]);
}
- (void)testUpdateTitle
{
NSAttributedString *title = [[NSAttributedString alloc] initWithString:@"MyTitle"];
ASButtonNode *buttonNode = [[ASButtonNode alloc] init];
[buttonNode setAttributedTitle:title forState:UIControlStateNormal];
XCTAssertTrue([[buttonNode attributedTitleForState:UIControlStateNormal] isEqualToAttributedString:title]);
XCTAssert([buttonNode.titleNode.attributedText isEqualToAttributedString:title]);
}
@end