Skip to content

Commit 589e64a

Browse files
diogotkzaher
authored andcommitted
Add tests to reative wrapper of UINavigationController delegate
1 parent a31982d commit 589e64a

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

Rx.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,8 @@
13631363
D9080AD41EA05DE9002B433B /* UINavigationController+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9080AD21EA05DDF002B433B /* UINavigationController+Rx.swift */; };
13641364
D9080AD51EA05DEB002B433B /* UINavigationController+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9080AD21EA05DDF002B433B /* UINavigationController+Rx.swift */; };
13651365
D9080AD61EA05DEC002B433B /* UINavigationController+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9080AD21EA05DDF002B433B /* UINavigationController+Rx.swift */; };
1366+
D9080AD81EA06189002B433B /* UINavigationController+RxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9080AD71EA06189002B433B /* UINavigationController+RxTests.swift */; };
1367+
D9080AD91EA06189002B433B /* UINavigationController+RxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9080AD71EA06189002B433B /* UINavigationController+RxTests.swift */; };
13661368
EB15145D1DFFAACB00555E2C /* Optional.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB15145C1DFFAACB00555E2C /* Optional.swift */; };
13671369
EB15145E1DFFAACB00555E2C /* Optional.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB15145C1DFFAACB00555E2C /* Optional.swift */; };
13681370
EB15145F1DFFAACB00555E2C /* Optional.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB15145C1DFFAACB00555E2C /* Optional.swift */; };
@@ -2038,6 +2040,7 @@
20382040
D2EBEB811BB9B99D003A27DC /* RxBlocking.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RxBlocking.framework; sourceTree = BUILT_PRODUCTS_DIR; };
20392041
D9080ACD1EA05A16002B433B /* RxNavigationControllerDelegateProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxNavigationControllerDelegateProxy.swift; sourceTree = "<group>"; };
20402042
D9080AD21EA05DDF002B433B /* UINavigationController+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UINavigationController+Rx.swift"; sourceTree = "<group>"; };
2043+
D9080AD71EA06189002B433B /* UINavigationController+RxTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UINavigationController+RxTests.swift"; sourceTree = "<group>"; };
20412044
EB15145C1DFFAACB00555E2C /* Optional.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Optional.swift; sourceTree = "<group>"; };
20422045
ECBBA59A1DF8C0BA00DDDC2E /* UITabBarController+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UITabBarController+Rx.swift"; sourceTree = "<group>"; };
20432046
ECBBA59D1DF8C0D400DDDC2E /* RxTabBarControllerDelegateProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxTabBarControllerDelegateProxy.swift; sourceTree = "<group>"; };
@@ -2548,6 +2551,7 @@
25482551
C8C4F16C1DE9D4F400003FA7 /* UIDatePicker+RxTests.swift */,
25492552
C8C4F1641DE9D3FB00003FA7 /* UIGestureRecognizer+RxTests.swift */,
25502553
C8C4F1601DE9CD1600003FA7 /* UILabel+RxTests.swift */,
2554+
D9080AD71EA06189002B433B /* UINavigationController+RxTests.swift */,
25512555
54700C9E1CE37D1000EF3A8F /* UINavigationItem+RxTests.swift.swift */,
25522556
914FCD661CCDB82E0058B304 /* UIPageControl+RxTest.swift */,
25532557
844BC8B71CE5023200F5C7CB /* UIPickerView+RxTests.swift */,
@@ -4066,6 +4070,7 @@
40664070
C83509311C38706E0027C24C /* DelegateProxyTest+UIKit.swift in Sources */,
40674071
C83509481C38706E0027C24C /* TestConnectableObservable.swift in Sources */,
40684072
C8353CEC1DA19BC500BE3F5C /* XCTest+AllTests.swift in Sources */,
4073+
D9080AD81EA06189002B433B /* UINavigationController+RxTests.swift in Sources */,
40694074
C8353CE61DA19BC500BE3F5C /* Recorded+Timeless.swift in Sources */,
40704075
C83509371C38706E0027C24C /* NotificationCenterTests.swift in Sources */,
40714076
C835095C1C38706E0027C24C /* Observable+MultipleTest.swift in Sources */,
@@ -4184,6 +4189,7 @@
41844189
C8350A111C38756A0027C24C /* Observable+SingleTest.swift in Sources */,
41854190
C8E9E42C1D43B26C0049644E /* Observable+DebugTest.swift in Sources */,
41864191
C8350A2A1C3875B50027C24C /* RxMutableBox.swift in Sources */,
4192+
D9080AD91EA06189002B433B /* UINavigationController+RxTests.swift in Sources */,
41874193
C8C4F17A1DE9DF0200003FA7 /* UIBarButtonItem+RxTests.swift in Sources */,
41884194
C8350A151C38756A0027C24C /* ObserverTests.swift in Sources */,
41894195
1AF67DA71CED430100C310FA /* ReplaySubjectTest.swift in Sources */,

Tests/RxCocoaTests/DelegateProxyTest+UIKit.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ extension DelegateProxyTest {
4141
}
4242
}
4343

44+
// MARK: UITabBarController
45+
46+
extension DelegateProxyTest {
47+
func test_UINavigationControllerDelegateExtension() {
48+
performDelegateTest(UINavigationControllerSubclass())
49+
}
50+
}
51+
4452
// MARK: UIScrollView
4553

4654
extension DelegateProxyTest {
@@ -467,7 +475,16 @@ final class NSTextStorageSubclass
467475
}
468476
}
469477

478+
final class ExtendNavigationControllerDelegateProxy
479+
: RxNavigationControllerDelegateProxy
480+
, TestDelegateProtocol {
481+
weak fileprivate(set) var control: UINavigationControllerSubclass?
470482

483+
required init(parentObject: AnyObject) {
484+
self.control = (parentObject as! UINavigationControllerSubclass)
485+
super.init(parentObject: parentObject)
486+
}
487+
}
471488

472489
final class ExtendTabBarControllerDelegateProxy
473490
: RxTabBarControllerDelegateProxy
@@ -491,6 +508,26 @@ final class ExtendTabBarDelegateProxy
491508
}
492509
}
493510

511+
final class UINavigationControllerSubclass: UINavigationController, TestDelegateControl {
512+
override func createRxDelegateProxy() -> RxNavigationControllerDelegateProxy {
513+
return ExtendNavigationControllerDelegateProxy(parentObject: self)
514+
}
515+
516+
func doThatTest(_ value: Int) {
517+
(delegate as! TestDelegateProtocol).testEventHappened?(value)
518+
}
519+
520+
var delegateProxy: DelegateProxy {
521+
return self.rx.delegate
522+
}
523+
524+
func setMineForwardDelegate(_ testDelegate: TestDelegateProtocol) -> Disposable {
525+
return RxNavigationControllerDelegateProxy.installForwardDelegate(testDelegate,
526+
retainDelegate: false,
527+
onProxyForObject: self)
528+
}
529+
}
530+
494531
final class UITabBarControllerSubclass
495532
: UITabBarController
496533
, TestDelegateControl {
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//
2+
// UINavigationController+RxTests.swift
3+
// Rx
4+
//
5+
// Created by Diogo on 13/04/17.
6+
// Copyright © 2017 Krunoslav Zaher. All rights reserved.
7+
//
8+
9+
#if os(iOS) || os(tvOS)
10+
11+
import RxSwift
12+
import RxCocoa
13+
import UIKit
14+
import XCTest
15+
16+
final class UINavigationControllerTests : RxTest {
17+
}
18+
19+
extension UINavigationControllerTests {
20+
21+
func testWillShow() {
22+
let navigationController = UINavigationController()
23+
24+
let viewController = UIViewController()
25+
var presentedViewController = UIViewController()
26+
27+
XCTAssertNotEqual(viewController, presentedViewController)
28+
29+
let animated = true
30+
var presentedAnimated = false
31+
32+
XCTAssertNotEqual(animated, presentedAnimated)
33+
34+
_ = navigationController.rx.willShow
35+
.subscribe(onNext: { (viewController, animated) in
36+
presentedViewController = viewController
37+
presentedAnimated = animated
38+
})
39+
40+
_ = navigationController.rx.didShow
41+
.subscribe(onNext: { _ in
42+
XCTFail("Should not be called")
43+
})
44+
45+
navigationController.delegate!.navigationController!(navigationController,
46+
willShow: viewController,
47+
animated: animated)
48+
49+
XCTAssertEqual(viewController, presentedViewController)
50+
XCTAssertEqual(animated, presentedAnimated)
51+
}
52+
53+
func testDidShow() {
54+
let navigationController = UINavigationController()
55+
56+
let viewController = UIViewController()
57+
var presentedViewController = UIViewController()
58+
59+
XCTAssertNotEqual(viewController, presentedViewController)
60+
61+
let animated = true
62+
var presentedAnimated = false
63+
64+
XCTAssertNotEqual(animated, presentedAnimated)
65+
66+
_ = navigationController.rx.willShow
67+
.subscribe(onNext: { _ in
68+
XCTFail("Should not be called")
69+
})
70+
71+
_ = navigationController.rx.didShow
72+
.subscribe(onNext: { (viewController, animated) in
73+
presentedViewController = viewController
74+
presentedAnimated = animated
75+
})
76+
77+
navigationController.delegate!.navigationController!(navigationController,
78+
didShow: viewController,
79+
animated: animated)
80+
81+
XCTAssertEqual(viewController, presentedViewController)
82+
XCTAssertEqual(animated, presentedAnimated)
83+
}
84+
85+
}
86+
87+
#endif

0 commit comments

Comments
 (0)