Skip to content

Commit

Permalink
Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmdvs committed Feb 4, 2017
1 parent 43cd454 commit d2bbd66
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 3 deletions.
1 change: 1 addition & 0 deletions TDBadgedCell.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ DESC
s.homepage = 'https://github.com/tmdvs/TDBadgedCell'
s.screenshots = 'https://camo.githubusercontent.com/54d4b4ddb11bf82b2d4e8ad88016b38cfad86644/687474703a2f2f75702e746d6476732e6d652f684f6c772f64'
s.author = { 'Tim Davies' => 'hi@tmdvs.me' }
s.social_media_url = 'https://twitter.com/tmdvs'
s.source = { :git => 'https://github.com/tmdvs/TDBadgedCell.git', :tag => 'v' + s.version.to_s }
s.ios.deployment_target = '8.0'
s.source_files = 'TDBadgedCell/TDBadgedCell.swift'
Expand Down
126 changes: 125 additions & 1 deletion TDBadgedCell.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
22A9C1431E460E1B0001F026 /* TDBadgedCellTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22A9C1421E460E1B0001F026 /* TDBadgedCellTests.swift */; };
22A9C14A1E460E3E0001F026 /* TDBadgedCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22F678AA1D802BEB007D2FAE /* TDBadgedCell.swift */; };
22F6787D1D80288B007D2FAE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22F6787C1D80288B007D2FAE /* AppDelegate.swift */; };
22F6787F1D80288B007D2FAE /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22F6787E1D80288B007D2FAE /* ViewController.swift */; };
22F678821D80288B007D2FAE /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 22F678801D80288B007D2FAE /* Main.storyboard */; };
Expand All @@ -15,7 +17,20 @@
22F678AB1D802BEB007D2FAE /* TDBadgedCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22F678AA1D802BEB007D2FAE /* TDBadgedCell.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
22A9C1451E460E1B0001F026 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 22F678711D80288B007D2FAE /* Project object */;
proxyType = 1;
remoteGlobalIDString = 22F678781D80288B007D2FAE;
remoteInfo = TDBadgedCell;
};
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
22A9C1401E460E1A0001F026 /* TDBadgedCellTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TDBadgedCellTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
22A9C1421E460E1B0001F026 /* TDBadgedCellTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TDBadgedCellTests.swift; sourceTree = "<group>"; };
22A9C1441E460E1B0001F026 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
22F678791D80288B007D2FAE /* TDBadgedCell.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TDBadgedCell.app; sourceTree = BUILT_PRODUCTS_DIR; };
22F6787C1D80288B007D2FAE /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
22F6787E1D80288B007D2FAE /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand All @@ -27,6 +42,13 @@
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
22A9C13D1E460E1A0001F026 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
22F678761D80288B007D2FAE /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -37,10 +59,20 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
22A9C1411E460E1B0001F026 /* TDBadgedCellTests */ = {
isa = PBXGroup;
children = (
22A9C1421E460E1B0001F026 /* TDBadgedCellTests.swift */,
22A9C1441E460E1B0001F026 /* Info.plist */,
);
path = TDBadgedCellTests;
sourceTree = "<group>";
};
22F678701D80288B007D2FAE = {
isa = PBXGroup;
children = (
22F6787B1D80288B007D2FAE /* TDBadgedCell */,
22A9C1411E460E1B0001F026 /* TDBadgedCellTests */,
22F6787A1D80288B007D2FAE /* Products */,
);
sourceTree = "<group>";
Expand All @@ -49,6 +81,7 @@
isa = PBXGroup;
children = (
22F678791D80288B007D2FAE /* TDBadgedCell.app */,
22A9C1401E460E1A0001F026 /* TDBadgedCellTests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand All @@ -70,6 +103,24 @@
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
22A9C13F1E460E1A0001F026 /* TDBadgedCellTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 22A9C1491E460E1B0001F026 /* Build configuration list for PBXNativeTarget "TDBadgedCellTests" */;
buildPhases = (
22A9C13C1E460E1A0001F026 /* Sources */,
22A9C13D1E460E1A0001F026 /* Frameworks */,
22A9C13E1E460E1A0001F026 /* Resources */,
);
buildRules = (
);
dependencies = (
22A9C1461E460E1B0001F026 /* PBXTargetDependency */,
);
name = TDBadgedCellTests;
productName = TDBadgedCellTests;
productReference = 22A9C1401E460E1A0001F026 /* TDBadgedCellTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
22F678781D80288B007D2FAE /* TDBadgedCell */ = {
isa = PBXNativeTarget;
buildConfigurationList = 22F678A11D80288C007D2FAE /* Build configuration list for PBXNativeTarget "TDBadgedCell" */;
Expand All @@ -93,10 +144,15 @@
22F678711D80288B007D2FAE /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastSwiftUpdateCheck = 0830;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Tim Davies";
TargetAttributes = {
22A9C13F1E460E1A0001F026 = {
CreatedOnToolsVersion = 8.3;
ProvisioningStyle = Automatic;
TestTargetID = 22F678781D80288B007D2FAE;
};
22F678781D80288B007D2FAE = {
CreatedOnToolsVersion = 7.2;
DevelopmentTeam = W376QLUK5J;
Expand All @@ -118,11 +174,19 @@
projectRoot = "";
targets = (
22F678781D80288B007D2FAE /* TDBadgedCell */,
22A9C13F1E460E1A0001F026 /* TDBadgedCellTests */,
);
};
/* End PBXProject section */

/* Begin PBXResourcesBuildPhase section */
22A9C13E1E460E1A0001F026 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
22F678771D80288B007D2FAE /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -136,6 +200,15 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
22A9C13C1E460E1A0001F026 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
22A9C14A1E460E3E0001F026 /* TDBadgedCell.swift in Sources */,
22A9C1431E460E1B0001F026 /* TDBadgedCellTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
22F678751D80288B007D2FAE /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -148,6 +221,14 @@
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
22A9C1461E460E1B0001F026 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 22F678781D80288B007D2FAE /* TDBadgedCell */;
targetProxy = 22A9C1451E460E1B0001F026 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
22F678801D80288B007D2FAE /* Main.storyboard */ = {
isa = PBXVariantGroup;
Expand All @@ -168,6 +249,41 @@
/* End PBXVariantGroup section */

/* Begin XCBuildConfiguration section */
22A9C1471E460E1B0001F026 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
INFOPLIST_FILE = TDBadgedCellTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.tmdvs.TDBadgedCellTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TDBadgedCell.app/TDBadgedCell";
};
name = Debug;
};
22A9C1481E460E1B0001F026 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
INFOPLIST_FILE = TDBadgedCellTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.tmdvs.TDBadgedCellTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TDBadgedCell.app/TDBadgedCell";
};
name = Release;
};
22F6789F1D80288C007D2FAE /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
Expand Down Expand Up @@ -287,6 +403,14 @@
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
22A9C1491E460E1B0001F026 /* Build configuration list for PBXNativeTarget "TDBadgedCellTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
22A9C1471E460E1B0001F026 /* Debug */,
22A9C1481E460E1B0001F026 /* Release */,
);
defaultConfigurationIsVisible = 0;
};
22F678741D80288B007D2FAE /* Build configuration list for PBXProject "TDBadgedCell" */ = {
isa = XCConfigurationList;
buildConfigurations = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>22A9C13F1E460E1A0001F026</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>22F678781D80288B007D2FAE</key>
<dict>
<key>primary</key>
Expand Down
4 changes: 2 additions & 2 deletions TDBadgedCell/TDBadgedCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TDBadgedCell: UITableViewCell {
public var badgeOffset = CGPoint(x:10, y:0)

/// The Image view that the badge will be rendered into
private let badgeView = UIImageView()
internal let badgeView = UIImageView()

override func layoutSubviews() {
super.layoutSubviews()
Expand Down Expand Up @@ -74,7 +74,7 @@ class TDBadgedCell: UITableViewCell {
}

/// Generate the badge image
private func drawBadge() {
internal func drawBadge() {
// Calculate the size of our string
let textSize : CGSize = NSString(string: badgeString).size(attributes:[NSFontAttributeName:UIFont.boldSystemFont(ofSize:CGFloat(badgeFontSize))])

Expand Down
22 changes: 22 additions & 0 deletions TDBadgedCellTests/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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>$(PRODUCT_BUNDLE_IDENTIFIER)</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>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
41 changes: 41 additions & 0 deletions TDBadgedCellTests/TDBadgedCellTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// TDBadgedCellTests.swift
// TDBadgedCellTests
//
// Created by Tim Davies on 04/02/2017.
// Copyright © 2017 Tim Davies. All rights reserved.
//

import XCTest

class TDBadgedCellTests: XCTestCase {

var cell : TDBadgedCell?

override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
cell = TDBadgedCell(style: .default, reuseIdentifier: "Cell")
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}

func testSetBadgeString() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
cell?.badgeString = "Testing 1,2,3"
XCTAssert((cell?.badgeString == "Testing 1,2,3"))
}

func testBadgeDraws() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
cell?.badgeString = "Testing 1,2,3"
XCTAssert(cell?.badgeView != nil)
XCTAssert(cell!.badgeView.image != nil)
}

}

0 comments on commit d2bbd66

Please sign in to comment.