forked from TextureGroup/Texture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASTextNode2Tests.mm
94 lines (77 loc) · 4 KB
/
ASTextNode2Tests.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// ASTextNode2Tests.mm
// 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 <XCTest/XCTest.h>
#import <AsyncDisplayKit/ASDisplayNode+Beta.h>
#import <AsyncDisplayKit/ASTextNode2.h>
#import <AsyncDisplayKit/ASTextNode+Beta.h>
#import "ASTestCase.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)testTruncation
{
XCTAssertTrue([(ASTextNode *)_textNode shouldTruncateForConstrainedSize:ASSizeRangeMake(CGSizeMake(100, 100))], @"Text Node should truncate");
_textNode.frame = CGRectMake(0, 0, 100, 100);
XCTAssertTrue(_textNode.isTruncated, @"Text Node should be truncated");
}
- (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