Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.

Commit fe3e030

Browse files
author
andrewlloyd100
authored
Merge pull request #13 from nodes-ios/Testing
Testing
2 parents ee27739 + 33579b8 commit fe3e030

File tree

4 files changed

+205
-11
lines changed

4 files changed

+205
-11
lines changed

Spinner.xcodeproj/project.pbxproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
275BCA291C57C50A00FF3647 /* Spinner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Spinner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2828
275BCA2C1C57C50A00FF3647 /* Spinner.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Spinner.h; sourceTree = "<group>"; };
2929
275BCA2E1C57C50A00FF3647 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
30-
275BCA331C57C50A00FF3647 /* Spinner.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Spinner.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
30+
275BCA331C57C50A00FF3647 /* SpinnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SpinnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
3131
275BCA381C57C50A00FF3647 /* SpinnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpinnerTests.swift; sourceTree = "<group>"; };
3232
275BCA3A1C57C50A00FF3647 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3333
275BCA431C57C56900FF3647 /* Spinner.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Spinner.swift; sourceTree = "<group>"; };
@@ -65,7 +65,7 @@
6565
isa = PBXGroup;
6666
children = (
6767
275BCA291C57C50A00FF3647 /* Spinner.framework */,
68-
275BCA331C57C50A00FF3647 /* Spinner.xctest */,
68+
275BCA331C57C50A00FF3647 /* SpinnerTests.xctest */,
6969
);
7070
name = Products;
7171
sourceTree = "<group>";
@@ -136,7 +136,7 @@
136136
);
137137
name = SpinnerTests;
138138
productName = ActivityIndicatorTests;
139-
productReference = 275BCA331C57C50A00FF3647 /* Spinner.xctest */;
139+
productReference = 275BCA331C57C50A00FF3647 /* SpinnerTests.xctest */;
140140
productType = "com.apple.product-type.bundle.unit-test";
141141
};
142142
/* End PBXNativeTarget section */
@@ -354,7 +354,7 @@
354354
INFOPLIST_FILE = SpinnerTests/Info.plist;
355355
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
356356
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.SpinnerTests;
357-
PRODUCT_NAME = Spinner;
357+
PRODUCT_NAME = SpinnerTests;
358358
SWIFT_VERSION = 2.3;
359359
};
360360
name = Debug;
@@ -365,7 +365,7 @@
365365
INFOPLIST_FILE = SpinnerTests/Info.plist;
366366
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
367367
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.SpinnerTests;
368-
PRODUCT_NAME = Spinner;
368+
PRODUCT_NAME = SpinnerTests;
369369
SWIFT_VERSION = 2.3;
370370
};
371371
name = Release;

Spinner.xcodeproj/xcshareddata/xcschemes/Spinner.xcscheme

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29-
shouldUseLaunchSchemeArgsEnv = "YES">
29+
shouldUseLaunchSchemeArgsEnv = "YES"
30+
codeCoverageEnabled = "YES">
3031
<Testables>
3132
<TestableReference
3233
skipped = "NO">
3334
<BuildableReference
3435
BuildableIdentifier = "primary"
3536
BlueprintIdentifier = "275BCA321C57C50A00FF3647"
36-
BuildableName = "Spinner.xctest"
37+
BuildableName = "SpinnerTests.xctest"
3738
BlueprintName = "SpinnerTests"
3839
ReferencedContainer = "container:Spinner.xcodeproj">
3940
</BuildableReference>

Spinner/Spinner.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,17 @@ public extension SpinnerView {
129129
- Parameter duration: The animation duration.
130130
*/
131131
public static func setCustomImages(images: [UIImage], duration: NSTimeInterval) {
132-
let image = UIImageView(frame: CGRectMake(0, 0, images[0].size.width, images[0].size.height))
133-
image.animationImages = images
134-
image.animationDuration = duration
135-
animationImage = image
132+
133+
if images.count == 0 {
134+
animationImage?.removeFromSuperview()
135+
animationImage = nil
136+
}
137+
else {
138+
let image = UIImageView(frame: CGRectMake(0, 0, images[0].size.width, images[0].size.height))
139+
image.animationImages = images
140+
image.animationDuration = duration
141+
animationImage = image
142+
}
136143
}
137144

138145
/**

SpinnerTests/SpinnerTests.swift

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ import XCTest
1111

1212
class SpinnerTests: XCTestCase {
1313

14+
let baseView = UIView()
15+
1416
override func setUp() {
1517
super.setUp()
1618
// Put setup code here. This method is called before the invocation of each test method in the class.
19+
1720
}
1821

1922
override func tearDown() {
@@ -33,4 +36,187 @@ class SpinnerTests: XCTestCase {
3336
}
3437
}
3538

39+
//MARK: Standard Spinner
40+
41+
func testShowSpinnerInViewAndAnimating() {
42+
43+
_ = SpinnerView.showSpinnerInView(baseView)
44+
45+
XCTAssert(baseView.subviews.count == 1) //baseview should now have a subview
46+
47+
if baseView.subviews.count == 1 {
48+
let spinnerView = baseView.subviews[0] as! UIActivityIndicatorView
49+
XCTAssert(spinnerView.isKindOfClass(UIActivityIndicatorView))
50+
XCTAssert(spinnerView.isAnimating())
51+
}
52+
else {
53+
XCTFail()
54+
}
55+
}
56+
57+
func testShowSpinnerInViewWithDisabledUserInteraction() {
58+
59+
_ = SpinnerView.showSpinnerInView(baseView, disablesUserInteraction: true)
60+
61+
XCTAssert(baseView.subviews.count == 1) //baseview should now have a subview
62+
63+
if baseView.subviews.count == 1 {
64+
_ = baseView.subviews[0] as! UIActivityIndicatorView
65+
XCTAssertFalse(baseView.userInteractionEnabled)
66+
}
67+
else {
68+
XCTFail()
69+
}
70+
}
71+
72+
func testShowSpinnerInViewWithColor() {
73+
74+
_ = SpinnerView.showSpinnerInView(baseView, color: UIColor.redColor(), disablesUserInteraction: true)
75+
76+
XCTAssert(baseView.subviews.count == 1) //baseview should now have a subview
77+
78+
if baseView.subviews.count == 1 {
79+
let spinnerView = baseView.subviews[0] as! UIActivityIndicatorView
80+
XCTAssertTrue(spinnerView.color == UIColor.redColor())
81+
}
82+
else {
83+
XCTFail()
84+
}
85+
}
86+
87+
func testShowSpinnerInViewWithGrayStyle() {
88+
89+
_ = SpinnerView.showSpinnerInView(baseView, style: .Gray, disablesUserInteraction: true)
90+
91+
XCTAssert(baseView.subviews.count == 1) //baseview should now have a subview
92+
93+
if baseView.subviews.count == 1 {
94+
let spinnerView = baseView.subviews[0] as! UIActivityIndicatorView
95+
XCTAssertTrue(spinnerView.activityIndicatorViewStyle == .Gray)
96+
}
97+
else {
98+
XCTFail()
99+
}
100+
}
101+
102+
func testDismissSpinnerInViewWithUserInteraction() {
103+
104+
let spinner = SpinnerView.showSpinnerInView(baseView, style: .Gray, disablesUserInteraction: true)
105+
106+
spinner.dismiss(enablesUserInteraction: true)
107+
}
108+
109+
//MARK: Button Spinner
110+
111+
func testShowSpinnerInButton() {
112+
let button = UIButton()
113+
button.setTitle("ButtonTitle", forState: .Normal)
114+
button.setTitleColor(UIColor.blueColor(), forState: .Normal)
115+
baseView.addSubview(button)
116+
117+
XCTAssertTrue(button.titleLabel?.textColor == UIColor.blueColor())
118+
119+
let spinner: SpinnerView = SpinnerView.showSpinnerInButton(button) as! SpinnerView
120+
121+
XCTAssertTrue(button.currentTitleColor == UIColor.clearColor())
122+
123+
spinner.dismiss()
124+
125+
XCTAssertTrue(button.currentTitleColor == UIColor.blueColor())
126+
}
127+
128+
func testShowSpinnerInButtonWithUserInteraction() {
129+
let button = UIButton()
130+
button.setTitle("ButtonTitle", forState: .Normal)
131+
button.setTitleColor(UIColor.blueColor(), forState: .Normal)
132+
baseView.addSubview(button)
133+
134+
XCTAssertTrue(button.titleLabel?.textColor == UIColor.blueColor())
135+
136+
let spinner: SpinnerView = SpinnerView.showSpinnerInButton(button) as! SpinnerView
137+
138+
XCTAssertTrue(button.currentTitleColor == UIColor.clearColor())
139+
140+
spinner.dismiss(true)
141+
142+
XCTAssertTrue(button.currentTitleColor == UIColor.blueColor())
143+
}
144+
145+
//MARK: Custom Spinner
146+
147+
func testShowCustomSpinnerWithoutImagesSet() {
148+
149+
SpinnerView.setCustomImages([], duration: 0.2)
150+
_ = SpinnerView.showCustomSpinnerInView(baseView)
151+
152+
XCTAssert(baseView.subviews.count == 1) //baseview should now have a subview
153+
154+
if baseView.subviews.count == 1 {
155+
let spinnerView = baseView.subviews[0] as! UIActivityIndicatorView
156+
XCTAssert(spinnerView.isKindOfClass(UIActivityIndicatorView))
157+
XCTAssert(spinnerView.isAnimating())
158+
}
159+
else {
160+
XCTFail()
161+
}
162+
}
163+
164+
func testShowCustomSpinnerWithImagesSet() {
165+
let redImage = getImageWithColor(UIColor.redColor())
166+
let blueImage = getImageWithColor(UIColor.blueColor())
167+
168+
SpinnerView.setCustomImages([redImage, blueImage], duration: 0.2)
169+
SpinnerView.showCustomSpinnerInView(baseView)
170+
171+
XCTAssert(baseView.subviews.count == 1) //baseview should now have a subview
172+
173+
if baseView.subviews.count == 1 {
174+
let spinnerView = baseView.subviews[0]
175+
XCTAssert(spinnerView.isKindOfClass(UIImageView))
176+
}
177+
else {
178+
XCTFail()
179+
}
180+
}
181+
182+
func testCustomSpinnerInButton() {
183+
184+
let button = UIButton()
185+
button.setTitle("ButtonTitle", forState: .Normal)
186+
button.setTitleColor(UIColor.blueColor(), forState: .Normal)
187+
baseView.addSubview(button)
188+
189+
let redImage = getImageWithColor(UIColor.redColor())
190+
let blueImage = getImageWithColor(UIColor.blueColor())
191+
192+
SpinnerView.setCustomImages([redImage, blueImage], duration: 0.2)
193+
let spinner: SpinnerView = SpinnerView.showCustomSpinnerInButton(button) as! SpinnerView
194+
195+
XCTAssert(button.subviews.count == 1) //button should now have a subview (spinner)
196+
197+
if button.subviews.count == 1 {
198+
let spinnerView = button.subviews[0]
199+
XCTAssert(spinnerView.isKindOfClass(UIImageView))
200+
201+
}
202+
else {
203+
XCTFail()
204+
}
205+
206+
spinner.dismiss()
207+
208+
}
209+
210+
//MARK: helper methods
211+
212+
func getImageWithColor(color: UIColor) -> UIImage {
213+
let rect = CGRectMake(0, 0, 10, 10)
214+
let size = CGSize(width: 10, height: 10)
215+
UIGraphicsBeginImageContextWithOptions(size, false, 0)
216+
color.setFill()
217+
UIRectFill(rect)
218+
let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()
219+
UIGraphicsEndImageContext()
220+
return image
221+
}
36222
}

0 commit comments

Comments
 (0)