-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AddToDeckCardDelegate unit tests
- Loading branch information
Showing
4 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
SWDestinyTradesTests/Screens/AddToDeck/Datasource/AddToDeckCardDatasourceTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
SWDestinyTradesTests/Screens/AddToDeck/Datasource/AddToDeckCardDelegateTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
SWDestinyTradesTests/Screens/AddToDeck/Mirror/AddToDeckCardDatasource+Mirror.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)! | ||
} | ||
} |