-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from erikdrobne/feature/add-unit-tests
Feature/add unit tests
- Loading branch information
Showing
2 changed files
with
81 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// NavigatorTests.swift | ||
// | ||
// | ||
// Created by Erik Drobne on 24. 10. 23. | ||
// | ||
|
||
import XCTest | ||
import Foundation | ||
@testable import SwiftUICoordinator | ||
|
||
@MainActor | ||
final class NavigatorTests: XCTestCase { | ||
|
||
func test_showRouteThrowsError() { | ||
let sut = MockCoordinator(parent: nil, startRoute: .circle, navigationController: NavigationController()) | ||
XCTAssertNoThrow(try sut.start()) | ||
|
||
XCTAssertThrowsError(try sut.show(route: .square)) { error in | ||
guard let error = error as? NavigatorError else { | ||
XCTFail("Cannot cast to NavigatorError: \(error)") | ||
return | ||
} | ||
|
||
switch error { | ||
case .cannotShow(let route as MockRoute): | ||
XCTAssertEqual(route, .square) | ||
default: | ||
XCTFail("Unexpected error type: \(error)") | ||
} | ||
} | ||
} | ||
|
||
func test_showRouteNoThrow() { | ||
let sut = MockCoordinator(parent: nil, startRoute: .circle, navigationController: NavigationController()) | ||
XCTAssertNoThrow(try sut.start()) | ||
} | ||
|
||
func test_setRoutes() { | ||
let sut = MockCoordinator(parent: nil, startRoute: .circle, navigationController: NavigationController()) | ||
sut.set(routes: [.rectangle, .rectangle]) | ||
XCTAssertEqual(sut.viewControllers.count, 2) | ||
} | ||
|
||
func test_appendRoutes() { | ||
let sut = MockCoordinator(parent: nil, startRoute: .circle, navigationController: NavigationController()) | ||
sut.append(routes: [.rectangle, .circle]) | ||
XCTAssertEqual(sut.viewControllers.count, 2) | ||
} | ||
|
||
func test_popToRoot() { | ||
let sut = MockCoordinator(parent: nil, startRoute: .circle, navigationController: NavigationController()) | ||
sut.append(routes: [.rectangle, .circle]) | ||
XCTAssertEqual(sut.viewControllers.count, 2) | ||
sut.popToRoot(animated: false) | ||
XCTAssertEqual(sut.viewControllers.count, 1) | ||
} | ||
} |