Skip to content

Commit

Permalink
Add UserCollectionNavigator unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dogo committed Mar 21, 2024
1 parent ae25608 commit a090773
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import FTPopOverMenu
import UIKit

final class UserCollectionViewController: UIViewController {

private var currentSortIndex = 0
private lazy var userCollectionView = UserCollectionTableView(delegate: self)
private lazy var navigator = UserCollectionNavigator(self.navigationController)
private lazy var navigator = UserCollectionNavigator(self)
private let database: DatabaseProtocol?

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

final class UserCollectionNavigator: Navigator {

enum Destination {
case cardDetail(database: DatabaseProtocol?, with: [CardDTO], card: CardDTO)
case addCard(database: DatabaseProtocol?, with: UserCollectionDTO)
}

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

private func makeViewController(for destination: Destination) -> UIViewController {
switch destination {
case let .cardDetail(database, cardList, card):
return CardDetailViewControllerFactory(database: database, cardList: cardList, card: card).createViewController()
return CardDetailViewControllerFactory(database: database,
cardList: cardList,
card: card)
.createViewController()
case let .addCard(database, userCollection):
return AddCardViewControllerFactory(database: database,
addCardType: .collection,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// UserCollectionNavigatorTests.swift
// SWDestinyTradesTests
//
// Created by Diogo Autilio on 21/03/24.
// Copyright © 2024 Diogo Autilio. All rights reserved.
//

import UIKit
import XCTest

@testable import SWDestinyTrades

final class UserCollectionNavigatorTests: XCTestCase {

private var sut: UserCollectionNavigator!
private var navigationController: UINavigationControllerMock!

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

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

func test_navigate_to_cardDetailViewController() {
sut.navigate(to: .cardDetail(database: nil, with: [.stub()], card: .stub()))

XCTAssertTrue(navigationController.currentPushedViewController is CardDetailViewController)
}

func test_navigate_to_addCardViewController() {
sut.navigate(to: .addCard(database: nil, with: .stub()))

XCTAssertTrue(navigationController.currentPushedViewController is AddCardViewController)
}
}

0 comments on commit a090773

Please sign in to comment.