Skip to content

Commit c85cb8f

Browse files
authored
Merge pull request #35 from MSWagner/miwagner/fix-tabbar-coo-init
Fix default init of Navigation- and TabBarCoordinator + add unit tests
2 parents 2aaad71 + 0072fee commit c85cb8f

4 files changed

Lines changed: 91 additions & 2 deletions

File tree

Sources/Toolbox/Coordinators/NavigationCoordinator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ open class NavigationCoordinator: Coordinator {
1515
self.pushedViewControllers = WeakArray([])
1616
self.navigationController = navigationController ?? UINavigationController()
1717

18-
super.init(rootViewController: navigationController)
18+
super.init(rootViewController: self.navigationController)
1919

2020
if self.navigationController.delegate == nil {
2121
self.navigationController.delegate = self

Sources/Toolbox/Coordinators/TabBarCoordinator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ open class TabBarCoordinator: Coordinator {
77

88
public init(tabBarController: UITabBarController? = nil) {
99
self.tabBarController = tabBarController ?? UITabBarController()
10-
super.init(rootViewController: tabBarController!)
10+
super.init(rootViewController: self.tabBarController)
1111
self.tabBarController.delegate = self
1212
}
1313

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
@testable import Toolbox
2+
import XCTest
3+
4+
final class NavigationCoordinatorTests: XCTestCase {
5+
6+
func testNavigationCoordinatorInitialization() async throws {
7+
let expectation = XCTestExpectation(description: "NavigationCoordinator initialization")
8+
9+
// Switch to the main actor context.
10+
await MainActor.run {
11+
let navCoordinator = NavigationCoordinator()
12+
13+
// Test your coordinator instance here, e.g.:
14+
XCTAssertNotNil(navCoordinator)
15+
16+
// Fulfill the expectation when the test is complete.
17+
expectation.fulfill()
18+
}
19+
20+
// Wait for the expectation to be fulfilled.
21+
wait(for: [expectation], timeout: 10)
22+
}
23+
24+
func testNavigationCoordinatorRootIsUINavigationController() async throws {
25+
let expectation = XCTestExpectation(description: "NavigationCoordinator initialization")
26+
27+
// Switch to the main actor context.
28+
await MainActor.run {
29+
let navCoordinator = NavigationCoordinator()
30+
31+
// Test your coordinator instance here, e.g.:
32+
XCTAssertNotNil(navCoordinator)
33+
34+
// Check if the rootViewController is of type UITabBarController
35+
XCTAssertTrue(navCoordinator.rootViewController is UINavigationController)
36+
37+
// Fulfill the expectation when the test is complete.
38+
expectation.fulfill()
39+
}
40+
41+
// Wait for the expectation to be fulfilled.
42+
wait(for: [expectation], timeout: 10)
43+
}
44+
45+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
@testable import Toolbox
2+
import XCTest
3+
4+
final class TabBarCoordinatorTests: XCTestCase {
5+
6+
func testTabBarCoordinatorInitialization() async throws {
7+
let expectation = XCTestExpectation(description: "TabBarCoordinator initialization")
8+
9+
// Switch to the main actor context.
10+
await MainActor.run {
11+
let mainCoordinator = TabBarCoordinator()
12+
13+
// Test your coordinator instance here, e.g.:
14+
XCTAssertNotNil(mainCoordinator)
15+
16+
// Fulfill the expectation when the test is complete.
17+
expectation.fulfill()
18+
}
19+
20+
// Wait for the expectation to be fulfilled.
21+
wait(for: [expectation], timeout: 10)
22+
}
23+
24+
func testTabBarCoordinatorRootIsUITabBarController() async throws {
25+
let expectation = XCTestExpectation(description: "TabBarCoordinator initialization")
26+
27+
// Switch to the main actor context.
28+
await MainActor.run {
29+
let tabBarCoordinator = TabBarCoordinator()
30+
31+
// Test your coordinator instance here, e.g.:
32+
XCTAssertNotNil(tabBarCoordinator)
33+
34+
// Check if the rootViewController is of type UITabBarController
35+
XCTAssertTrue(tabBarCoordinator.rootViewController is UITabBarController)
36+
37+
// Fulfill the expectation when the test is complete.
38+
expectation.fulfill()
39+
}
40+
41+
// Wait for the expectation to be fulfilled.
42+
wait(for: [expectation], timeout: 10)
43+
}
44+
}

0 commit comments

Comments
 (0)