|
import XCTest |
|
|
|
final class NavigationRouterTests: XCTestCase { |
|
private enum TestRoute: Hashable { |
|
case home, detail, settings, profile |
|
} |
|
|
|
private var router: NavigationRouter<TestRoute>! |
|
|
|
override func setUp() { |
|
super.setUp() |
|
router = NavigationRouter<TestRoute>() |
|
} |
|
|
|
override func tearDown() { |
|
router = nil |
|
super.tearDown() |
|
} |
|
|
|
func testPush_addsRouteToStack() { |
|
router.push(.home) |
|
XCTAssertEqual(router.navigationPath, [.home]) |
|
|
|
router.push(.detail) |
|
XCTAssertEqual(router.navigationPath, [.home, .detail]) |
|
} |
|
|
|
func testPop_removesLastRouteFromStack() { |
|
router.push(.home) |
|
router.push(.detail) |
|
router.pop() |
|
XCTAssertEqual(router.navigationPath, [.home]) |
|
} |
|
|
|
func testPop_onEmptyStack_doesNothing() { |
|
// Should not crash |
|
router.pop() |
|
XCTAssertTrue(router.navigationPath.isEmpty) |
|
} |
|
|
|
func testPopToRoot_clearsNavigationStack() { |
|
router.push(.home) |
|
router.push(.detail) |
|
router.push(.settings) |
|
|
|
router.popToRoot() |
|
XCTAssertTrue(router.navigationPath.isEmpty) |
|
} |
|
|
|
func testPopTo_validRoute_popsCorrectly() { |
|
router.push(.home) |
|
router.push(.detail) |
|
router.push(.settings) |
|
router.push(.profile) |
|
|
|
router.pop(to: .detail) |
|
XCTAssertEqual(router.navigationPath, [.home, .detail]) |
|
} |
|
|
|
func testPopTo_nonExistingRoute_doesNothing() { |
|
router.push(.home) |
|
router.push(.detail) |
|
|
|
router.pop(to: .profile) // .profile was never pushed |
|
XCTAssertEqual(router.navigationPath, [.home, .detail]) |
|
} |
|
|
|
func testDebugDescription_emptyPath() { |
|
XCTAssertEqual(router.pathDebugDescription, "Navigation Path: []") |
|
} |
|
|
|
func testDebugDescription_singleRoute() { |
|
router.push(.home) |
|
XCTAssertEqual(router.pathDebugDescription, "Navigation Path: [home]") |
|
} |
|
|
|
func testDebugDescription_multipleRoutes() { |
|
router.push(.home) |
|
router.push(.detail) |
|
router.push(.settings) |
|
XCTAssertEqual(router.pathDebugDescription, "Navigation Path: [home > detail > settings]") |
|
} |
|
|
|
func testDebugDescription_afterPop() { |
|
router.push(.home) |
|
router.push(.detail) |
|
router.push(.settings) |
|
router.pop() |
|
XCTAssertEqual(router.pathDebugDescription, "Navigation Path: [home > detail]") |
|
} |
|
|
|
func testDebugDescription_afterPopToRoot() { |
|
router.push(.home) |
|
router.push(.detail) |
|
router.popToRoot() |
|
XCTAssertEqual(router.pathDebugDescription, "Navigation Path: []") |
|
} |
|
|
|
func testDebugDescription_afterPopToSpecificRoute() { |
|
router.push(.home) |
|
router.push(.detail) |
|
router.push(.settings) |
|
router.pop(to: .home) |
|
XCTAssertEqual(router.pathDebugDescription, "Navigation Path: [home]") |
|
} |
|
} |