Skip to content

Commit

Permalink
Add PeopleListNavigator unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dogo committed Mar 1, 2024
1 parent b48d926 commit f325396
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ protocol UpdateTableDataDelegate: AnyObject {
}

final class PeopleListViewController: UIViewController, UpdateTableDataDelegate {

private lazy var peopleListView = PeopleListTableView(delegate: self)
private lazy var navigator = PeopleListNavigator(self.navigationController)
private lazy var navigator = PeopleListNavigator(self)
private let database: DatabaseProtocol?

// MARK: - Life Cycle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@
import UIKit

final class PeopleListNavigator: Navigator {

enum Destination {
case loanDetail(database: DatabaseProtocol?, with: PersonDTO)
case newPerson(with: UpdateTableDataDelegate)
}

private weak var navigationController: UINavigationController?
private weak var viewController: UIViewController?

// MARK: - Initializer

init(_ navigationController: UINavigationController?) {
self.navigationController = navigationController
init(_ viewController: UIViewController?) {
self.viewController = viewController
}

// MARK: - Navigator

func navigate(to destination: Destination) {
let viewController = makeViewController(for: destination)
navigationController?.pushViewController(viewController, animated: true)
viewController?.navigationController?.pushViewController(makeViewController(for: destination), animated: true)
}

// MARK: - Private
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// PeopleListNavigatorTests.swift
// SWDestinyTradesTests
//
// Created by Diogo Autilio on 01/03/24.
// Copyright © 2024 Diogo Autilio. All rights reserved.
//

import UIKit
import XCTest

@testable import SWDestinyTrades

final class PeopleListNavigatorTests: XCTestCase {

private var sut: PeopleListNavigator!
private var navigationController: UINavigationControllerMock!

override func setUp() {
super.setUp()
let controller = UIViewController()
navigationController = UINavigationControllerMock(rootViewController: controller)
sut = PeopleListNavigator(controller)
}

override func tearDown() {
navigationController = nil
sut = nil
super.tearDown()
}

func test_navigate_to_loansDetailViewController() {
sut.navigate(to: .loanDetail(database: nil, with: .stub()))

XCTAssertTrue(navigationController.currentPushedViewController is LoansDetailViewController)
}

func test_navigate_to_newPersonViewController() {
sut.navigate(to: .newPerson(with: UpdateTableDataDelegateSpy()))

XCTAssertTrue(navigationController.currentPushedViewController is NewPersonViewController)
}
}

0 comments on commit f325396

Please sign in to comment.