forked from TTTAttributedLabel/TTTAttributedLabel
-
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.
[Tests] Added test target with simple snapshot tests
- Loading branch information
Showing
15 changed files
with
511 additions
and
17 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
43 changes: 43 additions & 0 deletions
43
Example/Espressos/Images.xcassets/AppIcon.appiconset/Contents.json
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,43 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "29x29", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "29x29", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "40x40", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "57x57", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "57x57", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "60x60", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "60x60", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
Example/Espressos/Images.xcassets/LaunchImage.launchimage/Contents.json
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,61 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"orientation" : "portrait", | ||
"idiom" : "iphone", | ||
"extent" : "full-screen", | ||
"minimum-system-version" : "8.0", | ||
"subtype" : "736h", | ||
"scale" : "3x" | ||
}, | ||
{ | ||
"extent" : "full-screen", | ||
"idiom" : "iphone", | ||
"subtype" : "667h", | ||
"filename" : "[email protected]", | ||
"minimum-system-version" : "8.0", | ||
"orientation" : "portrait", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"orientation" : "portrait", | ||
"idiom" : "iphone", | ||
"extent" : "full-screen", | ||
"minimum-system-version" : "7.0", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"extent" : "full-screen", | ||
"idiom" : "iphone", | ||
"subtype" : "retina4", | ||
"filename" : "[email protected]", | ||
"minimum-system-version" : "7.0", | ||
"orientation" : "portrait", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"orientation" : "portrait", | ||
"idiom" : "iphone", | ||
"extent" : "full-screen", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"orientation" : "portrait", | ||
"idiom" : "iphone", | ||
"extent" : "full-screen", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"orientation" : "portrait", | ||
"idiom" : "iphone", | ||
"extent" : "full-screen", | ||
"filename" : "[email protected]", | ||
"subtype" : "retina4", | ||
"scale" : "2x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
File renamed without changes
Binary file added
BIN
+14.8 KB
Example/Espressos/Images.xcassets/LaunchImage.launchimage/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,14 +1,17 @@ | ||
PODS: | ||
- FBSnapshotTestCase (1.4) | ||
- TTTAttributedLabel (1.12.0) | ||
|
||
DEPENDENCIES: | ||
- FBSnapshotTestCase | ||
- TTTAttributedLabel (from `../`) | ||
|
||
EXTERNAL SOURCES: | ||
TTTAttributedLabel: | ||
:path: ../ | ||
|
||
SPEC CHECKSUMS: | ||
FBSnapshotTestCase: f9f225b5ba11c8d8c09075590490df16314e4d62 | ||
TTTAttributedLabel: ea3b165c9f9f7eb599bc26902f897199c9d73aef | ||
|
||
COCOAPODS: 0.35.0 |
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,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>en</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>TTTAttributedLabel.$(PRODUCT_NAME:rfc1034identifier)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>BNDL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
</dict> | ||
</plist> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.4 KB
...abelTests/ReferenceImages/TTTAttributedLabelTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.2 KB
...abelTests/ReferenceImages/TTTAttributedLabelTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
123 changes: 123 additions & 0 deletions
123
Example/TTTAttributedLabelTests/TTTAttributedLabelTests.m
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,123 @@ | ||
// | ||
// TTTAttributedLabelTests.m | ||
// TTTAttributedLabelTests | ||
// | ||
// Created by Jonathan Hersh on 12/5/14. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import <XCTest/XCTest.h> | ||
#import <TTTAttributedLabel.h> | ||
#import <FBSnapshotTestCase.h> | ||
|
||
static NSString * const kTestLabelText = @"Pallando, Merlyn, and Melisandre were walking one day..."; | ||
static CGSize const kTestLabelSize = (CGSize) { 90, CGFLOAT_MAX }; | ||
|
||
static inline NSAttributedString * TTTAttributedTestString() { | ||
return [[NSAttributedString alloc] initWithString:kTestLabelText | ||
attributes:@{ | ||
NSForegroundColorAttributeName : [UIColor redColor], | ||
NSFontAttributeName : [UIFont boldSystemFontOfSize:16.f], | ||
}]; | ||
} | ||
|
||
static inline void TTTSizeAttributedLabel(TTTAttributedLabel *label) { | ||
CGSize size = [TTTAttributedLabel sizeThatFitsAttributedString:label.attributedText | ||
withConstraints:kTestLabelSize | ||
limitedToNumberOfLines:0]; | ||
|
||
[label setFrame:CGRectMake(0, 0, size.width, size.height)]; | ||
}; | ||
|
||
@interface TTTAttributedLabelTests : FBSnapshotTestCase | ||
|
||
@end | ||
|
||
@implementation TTTAttributedLabelTests | ||
{ | ||
TTTAttributedLabel *label; // system under test | ||
NSURL *testURL; | ||
} | ||
|
||
- (void)setUp { | ||
[super setUp]; | ||
|
||
label = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(0, 0, 300, 100)]; | ||
label.numberOfLines = 0; | ||
label.textColor = [UIColor redColor]; | ||
label.font = [UIFont boldSystemFontOfSize:16.f]; | ||
|
||
testURL = [NSURL URLWithString:@"http://helios.io"]; | ||
|
||
// Compatibility fix for intermittently non-rendering images | ||
self.renderAsLayer = YES; | ||
|
||
// Enable recording mode to record and save reference images for tests | ||
// self.recordMode = YES; | ||
} | ||
|
||
- (void)tearDown { | ||
[super tearDown]; | ||
} | ||
|
||
- (void)testInitializable { | ||
XCTAssertNotNil(label, @"Label should be initializable"); | ||
} | ||
|
||
- (void)testAttributedTextAccess { | ||
label.text = TTTAttributedTestString(); | ||
XCTAssertTrue([label.attributedText isEqualToAttributedString:TTTAttributedTestString()], @"Attributed strings should match"); | ||
} | ||
|
||
- (void)testMultilineLabelSizing { | ||
NSAttributedString *testString = TTTAttributedTestString(); | ||
|
||
CGSize size = [TTTAttributedLabel sizeThatFitsAttributedString:testString | ||
withConstraints:kTestLabelSize | ||
limitedToNumberOfLines:0]; | ||
|
||
UIFont *font = [testString attribute:NSFontAttributeName atIndex:0 effectiveRange:NULL]; | ||
XCTAssertGreaterThan(size.height, font.pointSize, @"Text should size to more than one line"); | ||
} | ||
|
||
- (void)testContainsLinkAtPoint { | ||
label.text = TTTAttributedTestString(); | ||
[label addLinkToURL:testURL withRange:NSMakeRange(0, 4)]; | ||
TTTSizeAttributedLabel(label); | ||
XCTAssertTrue([label containslinkAtPoint:CGPointMake(5, 5)], @"Label should contain a link at the start of the string"); | ||
} | ||
|
||
- (void)testLinkArray { | ||
label.text = TTTAttributedTestString(); | ||
[label addLinkToURL:testURL withRange:NSMakeRange(0, 1)]; | ||
|
||
XCTAssertNotNil(label.links, @"Label should have a links array"); | ||
|
||
NSTextCheckingResult *result = label.links[0]; | ||
XCTAssertEqual(result.resultType, NSTextCheckingTypeLink, @"Should be a link checking result"); | ||
XCTAssertTrue(result.range.location == 0 && result.range.length == 1, @"Link range should match"); | ||
XCTAssertEqualObjects(result.URL, testURL, @"Should set and retrieve test URL"); | ||
} | ||
|
||
- (void)testMultilineLabelView { | ||
label.text = TTTAttributedTestString(); | ||
TTTSizeAttributedLabel(label); | ||
FBSnapshotVerifyView(label, nil); | ||
} | ||
|
||
- (void)testLinkifiedLabelView { | ||
label.text = TTTAttributedTestString(); | ||
[label addLinkToURL:testURL withRange:NSMakeRange(1, 3)]; | ||
TTTSizeAttributedLabel(label); | ||
FBSnapshotVerifyView(label, nil); | ||
} | ||
|
||
- (void)testLinkAttributeLabelView { | ||
label.linkAttributes = @{ kTTTBackgroundFillColorAttributeName : (id)[UIColor greenColor].CGColor }; | ||
label.text = TTTAttributedTestString(); | ||
[label addLinkToURL:testURL withRange:NSMakeRange(10, 6)]; | ||
TTTSizeAttributedLabel(label); | ||
FBSnapshotVerifyView(label, nil); | ||
} | ||
|
||
@end |