Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kopiev.ivan committed Oct 17, 2024
1 parent e88c575 commit f14acf7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Sources/DeeplinkRouter/BaseNavigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ private extension BaseNavigator {
}
}

// Проверяем дочерние контроллеры
for child in rootViewController.children {
if let found = findController(in: child, ofType: type) {
return found
}
}

// Проверяем представленный контроллер
if let presented = rootViewController.presentedViewController {
return findController(in: presented, ofType: type)
Expand Down
21 changes: 20 additions & 1 deletion Tests/DeeplinkRouterTests/BaseNavigatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import XCTest

final class BaseNavigatorTests: XCTestCase {

class TargetViewController: UIViewController {}

var navigator: BaseNavigator!
var window: UIWindow!

Expand All @@ -30,6 +32,23 @@ final class BaseNavigatorTests: XCTestCase {
XCTAssertEqual(returnedWindow, window)
}

func testFindControllerReturnsCorrectController() {
// Given
let rootVC = UIViewController()
let targetVC = TargetViewController()
let navController = UINavigationController(rootViewController: targetVC)
rootVC.addChild(navController)

window.rootViewController = rootVC
window.makeKeyAndVisible()

// When
let foundVC = navigator.findController(type: TargetViewController.self)

// Then
XCTAssertEqual(foundVC, targetVC)
}

func testTopVcReturnsCorrectViewController() {
// Given
let rootViewController = UIViewController()
Expand Down Expand Up @@ -71,7 +90,7 @@ final class BaseNavigatorTests: XCTestCase {
XCTAssertEqual(tabbar, tabBarController)
}

@MainActor
@MainActor
func testSetLoadingShowsAndHidesLoader() {
// Given
window.makeKeyAndVisible()
Expand Down

0 comments on commit f14acf7

Please sign in to comment.