-
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 SearchView unit tests
- Loading branch information
Showing
6 changed files
with
147 additions
and
10 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
20 changes: 20 additions & 0 deletions
20
SWDestinyTrades/Classes/Search/Protocol/SearchViewType.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,20 @@ | ||
// | ||
// SearchViewType.swift | ||
// SWDestinyTrades | ||
// | ||
// Created by Diogo Autilio on 17/03/24. | ||
// Copyright © 2024 Diogo Autilio. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
protocol SearchViewType where Self: UIView { | ||
|
||
var didSelectCard: ((CardDTO) -> Void)? { get set } | ||
var doingSearch: ((String) -> Void)? { get set } | ||
|
||
func startLoading() | ||
func stopLoading() | ||
func updateSearchList(_ cards: [CardDTO]) | ||
} |
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
Binary file added
BIN
+61.4 KB
SWDestinyTradesTests/ReferenceImages/SearchViewTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions
27
SWDestinyTradesTests/Screens/Search/Mirror/SearchView+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 @@ | ||
// | ||
// SearchView+Mirror.swift | ||
// SWDestinyTradesTests | ||
// | ||
// Created by Diogo Autilio on 17/03/24. | ||
// Copyright © 2024 Diogo Autilio. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
@testable import SWDestinyTrades | ||
|
||
extension SearchView { | ||
|
||
var activityIndicator: UIActivityIndicatorView { | ||
Mirror.extract(variable: "activityIndicator", from: self)! | ||
} | ||
|
||
var searchTableView: SearchTableView { | ||
Mirror.extract(variable: "searchTableView", from: self)! | ||
} | ||
|
||
var searchBar: SearchBar { | ||
Mirror.extract(variable: "searchBar", from: self)! | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
SWDestinyTradesTests/Screens/Search/View/SearchViewTests.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,64 @@ | ||
// | ||
// SearchViewTests.swift | ||
// SWDestinyTradesTests | ||
// | ||
// Created by Diogo Autilio on 17/03/24. | ||
// Copyright © 2024 Diogo Autilio. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import XCTest | ||
|
||
@testable import SWDestinyTrades | ||
|
||
final class SearchViewTests: XCSnapshotableTestCase { | ||
|
||
private var sut: SearchView! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
sut = SearchView(frame: .testDevice) | ||
} | ||
|
||
override func tearDown() { | ||
sut = nil | ||
super.tearDown() | ||
} | ||
|
||
func test_searchView_layout() { | ||
XCTAssertTrue(snapshot(sut, named: "Search View layout")) | ||
} | ||
|
||
func test_startLoading() { | ||
sut.startLoading() | ||
|
||
XCTAssertTrue(sut.activityIndicator.isAnimating) | ||
} | ||
|
||
func test_stopLoading() { | ||
sut.stopLoading() | ||
|
||
XCTAssertFalse(sut.activityIndicator.isAnimating) | ||
} | ||
|
||
func test_updateSearchList() { | ||
sut.updateSearchList([.stub()]) | ||
|
||
let datasourceCount = sut.searchTableView.searchDatasource?.tableView(sut.searchTableView, | ||
numberOfRowsInSection: 0) | ||
|
||
XCTAssertEqual(datasourceCount, 1) | ||
} | ||
|
||
func test_didSelectCard_is_set() { | ||
sut.didSelectCard = { _ in } | ||
|
||
XCTAssertNotNil(sut.searchTableView.didSelectCard) | ||
} | ||
|
||
func test_doingSearch_is_set() { | ||
sut.doingSearch = { _ in } | ||
|
||
XCTAssertNotNil(sut.searchBar.doingSearch) | ||
} | ||
} |