Skip to content

Commit

Permalink
[Tests] Added test target with simple snapshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jhersh committed Dec 6, 2014
1 parent 733368d commit df44def
Show file tree
Hide file tree
Showing 15 changed files with 511 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ podfile: Example/Podfile
script:
- export LC_CTYPE=en_US.UTF-8
- export LANG=en_US.UTF-8
- set -o pipefail && xcodebuild -workspace 'Example/Espressos.xcworkspace' -scheme 'Espressos' -sdk iphonesimulator clean build | xcpretty -c
- set -o pipefail && xcodebuild -workspace 'Example/Espressos.xcworkspace' -scheme 'Espressos' -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone 6" clean test | xcpretty -c
232 changes: 219 additions & 13 deletions Example/Espressos.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
ReferencedContainer = "container:Espressos.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E9B3C6E61A32C2DB00D43DF9"
BuildableName = "TTTAttributedLabelTests.xctest"
BlueprintName = "TTTAttributedLabelTests"
ReferencedContainer = "container:Espressos.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand All @@ -28,6 +42,16 @@
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E9B3C6E61A32C2DB00D43DF9"
BuildableName = "TTTAttributedLabelTests.xctest"
BlueprintName = "TTTAttributedLabelTests"
ReferencedContainer = "container:Espressos.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
Expand Down
43 changes: 43 additions & 0 deletions Example/Espressos/Images.xcassets/AppIcon.appiconset/Contents.json
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"
}
}
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions Example/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIcons~ipad</key>
<dict/>
<key>CFBundleIdentifier</key>
<string>com.mattt.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
Expand Down
12 changes: 11 additions & 1 deletion Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,15 @@ xcodeproj 'Espressos'

deployment_target = '6.0'

pod 'TTTAttributedLabel', :path => '../'
def install_pods
pod 'TTTAttributedLabel', :path => '../'
end

target :Espressos do
install_pods
end

target :TTTAttributedLabelTests, :exclusive => true do
install_pods
pod 'FBSnapshotTestCase'
end
3 changes: 3 additions & 0 deletions Example/Podfile.lock
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
24 changes: 24 additions & 0 deletions Example/TTTAttributedLabelTests/Info.plist
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 Example/TTTAttributedLabelTests/TTTAttributedLabelTests.m
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

0 comments on commit df44def

Please sign in to comment.