Skip to content

Commit

Permalink
Add AddToDeckCardDelegate unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dogo committed Jan 4, 2024
1 parent 4d7e73c commit ee8f232
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@ final class AddCardDatasourceTests: XCTestCase {
sut.doingSearch("Phasma")

XCTAssertTrue(sut.searchIsActive)
XCTAssertEqual(sut.filtered.count, 1)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//
// AddToDeckCardDatasourceTests.swift
// SWDestinyTradesTests
//
// Created by Diogo Autilio on 04/01/24.
// Copyright © 2024 Diogo Autilio. All rights reserved.
//

import XCTest

@testable import SWDestinyTrades

final class AddToDeckCardDatasourceTests: XCTestCase {

private var sut: AddToDeckCardDatasource!
private var tableView: UITableView!
private var delegate: UITableViewDelegate!

override func setUp() {
super.setUp()
tableView = UITableView()
sut = AddToDeckCardDatasource(cards: [.stub()],
tableView: tableView,
delegate: AddToDeckCardDelegate())
}

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

func test_cellForRowAt() {
let cell = sut.tableView(tableView, cellForRowAt: IndexPath(row: 0, section: 0))

XCTAssertTrue(cell is AddCardCell)
}

func test_numberOfRowsInSection_not_searching() {
let rows = sut.tableView(tableView, numberOfRowsInSection: 0)

XCTAssertEqual(rows, 1)
}

func test_numberOfRowsInSection_searching() {
sut.doingSearch("text")

let rows = sut.tableView(tableView, numberOfRowsInSection: 0)

XCTAssertEqual(rows, 0)
}

func test_updateSearchList() {
sut.updateSearchList([
.stub(),
.stub()
])

XCTAssertEqual(sut.cardsData.count, 2)
XCTAssertEqual(sut.filtered.count, 2)
}

func test_getCard_not_searching() {
let card = sut.getCard(at: IndexPath(row: 0, section: 0))

XCTAssertNotNil(card)
}

func test_getCard_searching() {
sut.doingSearch("Phasma")

let card = sut.getCard(at: IndexPath(row: 0, section: 0))

XCTAssertNotNil(card)
}

func test_doingSearch() {
sut.doingSearch("Phasma")

XCTAssertTrue(sut.searchIsActive)
XCTAssertEqual(sut.filtered.count, 1)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// AddToDeckCardDelegateTests.swift
// SWDestinyTradesTests
//
// Created by Diogo Autilio on 04/01/24.
// Copyright © 2024 Diogo Autilio. All rights reserved.
//

import Foundation
import UIKit
import XCTest

@testable import SWDestinyTrades

final class AddToDeckCardDelegateTests: XCTestCase {

private var sut: AddToDeckCardDelegate!
private var delegate: SearchDelegateSpy!
private var tableView: UITableView!

override func setUp() {
super.setUp()
delegate = SearchDelegateSpy()
tableView = UITableView()
sut = AddToDeckCardDelegate()
sut.delegate = delegate
}

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

func test_heightForRowAt() {
let height = sut.tableView(tableView, heightForRowAt: IndexPath(row: 0, section: 0))

XCTAssertEqual(height, 53)
}

func test_didSelectRowAt() {
sut.tableView(tableView, didSelectRowAt: IndexPath(row: 0, section: 0))

XCTAssertEqual(delegate.didCallDidSelectRow.count, 1)
}

func test_accessoryButtonTappedForRowWith() {
sut.tableView(tableView, accessoryButtonTappedForRowWith: IndexPath(row: 0, section: 0))

XCTAssertEqual(delegate.didCallDidSelectAccessory.count, 1)
}

func test_viewForHeaderInSection_zero_is_not_nil() {
tableView.register(headerFooterViewType: AddToDeckHeaderView.self)

let header = sut.tableView(tableView, viewForHeaderInSection: 0)

XCTAssertNotNil(header)
}

func test_viewForHeaderInSection_non_zero_is_nil() {
tableView.register(headerFooterViewType: AddToDeckHeaderView.self)

let header = sut.tableView(tableView, viewForHeaderInSection: 1)

XCTAssertNil(header)
}

func test_heightForHeaderInSection() {
let height = sut.tableView(tableView, heightForHeaderInSection: 0)

XCTAssertEqual(height, 45)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// AddToDeckCardDatasource+Mirror.swift
// SWDestinyTradesTests
//
// Created by Diogo Autilio on 04/01/24.
// Copyright © 2024 Diogo Autilio. All rights reserved.
//

import Foundation
import UIKit

@testable import SWDestinyTrades

extension AddToDeckCardDatasource {

var searchIsActive: Bool {
Mirror.extract(variable: "searchIsActive", from: self)!
}

var cardsData: [CardDTO] {
Mirror.extract(variable: "cardsData", from: self)!
}

var filtered: [CardDTO] {
Mirror.extract(variable: "filtered", from: self)!
}
}

0 comments on commit ee8f232

Please sign in to comment.