-
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.
- Loading branch information
Showing
1 changed file
with
154 additions
and
0 deletions.
There are no files selected for viewing
154 changes: 154 additions & 0 deletions
154
SWDestinyTradesTests/Screens/AddToDeck/View/AddToDeckTableViewTests.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,154 @@ | ||
// | ||
// AddToDeckTableViewTests.swift | ||
// SWDestinyTradesTests | ||
// | ||
// Created by Diogo Autilio on 05/01/24. | ||
// Copyright © 2024 Diogo Autilio. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import XCTest | ||
|
||
@testable import SWDestinyTrades | ||
|
||
final class AddToDeckTableViewTests: XCTestCase { | ||
|
||
private var sut: AddToDeckTableView! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
sut = AddToDeckTableView(frame: .testDevice) | ||
} | ||
|
||
override func tearDown() { | ||
sut = nil | ||
super.tearDown() | ||
} | ||
|
||
func testUpdateSearchList() { | ||
sut.updateSearchList([.stub()]) | ||
|
||
let datasourceCount = sut.tableDatasource.tableView(sut, numberOfRowsInSection: 0) | ||
|
||
XCTAssertEqual(datasourceCount, 1) | ||
} | ||
|
||
func testDoingSearch() { | ||
sut.doingSearch("Narf") | ||
|
||
let datasource = sut.tableDatasource as AddToDeckCardDatasource | ||
XCTAssertTrue(datasource.searchIsActive) | ||
} | ||
|
||
func test_didSelectRow() { | ||
|
||
sut.updateSearchList([.stub()]) | ||
|
||
var didCallDidSelectCard = 0 | ||
var didSelectCardValue: CardDTO? | ||
sut.didSelectCard = { card in | ||
didCallDidSelectCard += 1 | ||
didSelectCardValue = card | ||
} | ||
|
||
sut.didSelectRow(at: IndexPath(row: 0, section: 0)) | ||
|
||
XCTAssertEqual(didCallDidSelectCard, 1) | ||
XCTAssertNotNil(didSelectCardValue) | ||
} | ||
|
||
func test_didSelectAccessory() { | ||
|
||
sut.updateSearchList([.stub()]) | ||
|
||
var didCallDidSelectAccessory = 0 | ||
var didSelectCardValue: CardDTO? | ||
sut.didSelectAccessory = { card in | ||
didCallDidSelectAccessory += 1 | ||
didSelectCardValue = card | ||
} | ||
|
||
sut.didSelectAccessory(at: IndexPath(row: 0, section: 0)) | ||
|
||
XCTAssertEqual(didCallDidSelectAccessory, 1) | ||
XCTAssertNotNil(didSelectCardValue) | ||
} | ||
|
||
func test_didSelectSegment_index_zero() { | ||
|
||
sut.updateSearchList([.stub()]) | ||
|
||
var didCallDidSelectRemote = 0 | ||
sut.didSelectRemote = { | ||
didCallDidSelectRemote += 1 | ||
} | ||
|
||
sut.didSelectSegment(index: 0) | ||
|
||
let datasourceCount = sut.tableDatasource.tableView(sut, numberOfRowsInSection: 0) | ||
|
||
XCTAssertEqual(didCallDidSelectRemote, 1) | ||
XCTAssertEqual(datasourceCount, 0) | ||
} | ||
|
||
func test_didSelectSegment_index_one() { | ||
|
||
sut.updateSearchList([.stub()]) | ||
|
||
var didCallDidSelectLocal = 0 | ||
sut.didSelectLocal = { | ||
didCallDidSelectLocal += 1 | ||
} | ||
|
||
sut.didSelectSegment(index: 1) | ||
|
||
let datasourceCount = sut.tableDatasource.tableView(sut, numberOfRowsInSection: 0) | ||
|
||
XCTAssertEqual(didCallDidSelectLocal, 1) | ||
XCTAssertEqual(datasourceCount, 0) | ||
} | ||
|
||
func test_didSelectSegment_index_not_found() { | ||
|
||
sut.updateSearchList([.stub()]) | ||
|
||
var didCallDidSelectRemote = 0 | ||
sut.didSelectRemote = { | ||
didCallDidSelectRemote += 1 | ||
} | ||
|
||
var didCallDidSelectLocal = 0 | ||
sut.didSelectLocal = { | ||
didCallDidSelectLocal += 1 | ||
} | ||
|
||
sut.didSelectSegment(index: 3) | ||
|
||
let datasourceCount = sut.tableDatasource.tableView(sut, numberOfRowsInSection: 0) | ||
|
||
XCTAssertEqual(didCallDidSelectRemote, 0) | ||
XCTAssertEqual(didCallDidSelectLocal, 0) | ||
XCTAssertEqual(datasourceCount, 1) | ||
} | ||
|
||
func testKeyboardWillShow() { | ||
let keyboardSize = CGSize(width: 320, height: 216) | ||
let userInfo: [AnyHashable: Any] = [ | ||
UIResponder.keyboardFrameEndUserInfoKey: NSValue(cgRect: CGRect(x: 0, y: 0, width: keyboardSize.width, height: keyboardSize.height)) | ||
] | ||
let notification = NSNotification(name: UIResponder.keyboardWillShowNotification, object: nil, userInfo: userInfo) | ||
|
||
sut.keyboardWillShow(notification: notification) | ||
|
||
XCTAssertEqual(sut.contentInset.bottom, keyboardSize.height) | ||
XCTAssertEqual(sut.verticalScrollIndicatorInsets.bottom, keyboardSize.height) | ||
} | ||
|
||
func testKeyboardWillHide() { | ||
let notification = NSNotification(name: UIResponder.keyboardWillHideNotification, object: nil) | ||
sut.keyboardWillHide(notification: notification) | ||
|
||
XCTAssertEqual(sut.contentInset, UIEdgeInsets.zero) | ||
XCTAssertEqual(sut.verticalScrollIndicatorInsets, UIEdgeInsets.zero) | ||
} | ||
} |