Skip to content

Commit 20d93ac

Browse files
committed
Add snapshot tests to existing screens
1 parent 5485a5b commit 20d93ac

29 files changed

+356
-101
lines changed

HeroDetailInteractor.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ enum DetailCellType {
1414
}
1515

1616
protocol HeroDetailOutput {
17+
var view: HeroDetailInput! { get set }
1718
var numberOfSections: Int { get }
1819
var hero: MarvelHero { get }
1920
func viewDidLoad()
@@ -77,7 +78,7 @@ class HeroDetailInteractor: HeroDetailOutput {
7778

7879
view.showLoading()
7980
HeroProductsRequest.Kind.allCases
80-
.forEach { fetchData(ofKind: $0, withUpdate: addSection(kind:products:)) }
81+
.forEach { fetchData(ofKind: $0, withUpdate: addSection(kind: products:)) }
8182

8283
dispatchGroup.notify(queue: DispatchQueue.main) { [weak self] in
8384
self?.view.reloadData()
@@ -96,7 +97,7 @@ class HeroDetailInteractor: HeroDetailOutput {
9697

9798
private func configureFavorite() {
9899
AppEnvironment.current.favorites.isFavorite(hero.id) ?
99-
view.favorite() :
100+
view.favorite():
100101
view.unfavorite()
101102
}
102103
}

HeroDetailViewController.swift

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ class HeroDetailViewController: UIViewController, StoryboardInstantiable {
1717

1818
private func setupBarButtonItem() {
1919
let image = UIImage(named: "star")?.withRenderingMode(.alwaysTemplate)
20-
navigationItem.rightBarButtonItem = .init(image: image,
21-
style: .plain,
22-
target: self,
23-
action: #selector(favoriteButtonTapped))
20+
navigationItem.rightBarButtonItem = .init(image: image,
21+
style: .plain,
22+
target: self,
23+
action: #selector(favoriteButtonTapped))
2424
}
2525

2626
private func setupCollectionView() {
@@ -51,7 +51,7 @@ extension HeroDetailViewController: HeroDetailInput {
5151
func reloadData() {
5252
collectionView.reloadData()
5353
}
54-
54+
5555
func showLoading() {
5656
guard loadingIndicator == nil else { return }
5757
let indicator = UIActivityIndicatorView(style: .gray)
@@ -71,26 +71,29 @@ extension HeroDetailViewController: UICollectionViewDataSource {
7171
return interactor.numberOfSections
7272
}
7373

74-
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection
75-
section: Int) -> Int {
74+
func collectionView(_ collectionView: UICollectionView,
75+
numberOfItemsInSection section: Int) -> Int {
7676
return interactor.numberOfItemsInSection(section)
7777
}
7878

79-
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
79+
func collectionView(_ collectionView: UICollectionView,
80+
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
8081
switch interactor.cellTypeForSection(indexPath.section) {
8182
case .poster: return posterCell(collectionView, cellForItemAt: indexPath)
8283
case .card: return cardCell(collectionView, cellForItemAt: indexPath)
8384
}
8485
}
8586

86-
private func posterCell(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> PosterCell {
87+
private func posterCell(_ collectionView: UICollectionView,
88+
cellForItemAt indexPath: IndexPath) -> PosterCell {
8789
let cell = collectionView.dequeue(PosterCell.self, for: indexPath)
8890
cell.configure(with: interactor.hero)
8991

9092
return cell
9193
}
9294

93-
private func cardCell(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> CardCell {
95+
private func cardCell(_ collectionView: UICollectionView,
96+
cellForItemAt indexPath: IndexPath) -> CardCell {
9497
let cell = collectionView.dequeue(CardCell.self, for: indexPath)
9598
cell.configure(for: interactor.product(at: indexPath))
9699

@@ -99,20 +102,26 @@ extension HeroDetailViewController: UICollectionViewDataSource {
99102
}
100103

101104
extension HeroDetailViewController: UICollectionViewDelegateFlowLayout {
102-
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
105+
func collectionView(_ collectionView: UICollectionView,
106+
layout collectionViewLayout: UICollectionViewLayout,
107+
referenceSizeForHeaderInSection section: Int) -> CGSize {
103108
return section > 0 ?
104-
.init(width: collectionView.frame.width, height: 50) :
109+
.init(width: collectionView.frame.width, height: 50):
105110
.zero
106111
}
107112

108-
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
113+
func collectionView(_ collectionView: UICollectionView,
114+
layout collectionViewLayout: UICollectionViewLayout,
115+
sizeForItemAt indexPath: IndexPath) -> CGSize {
109116

110117
return indexPath.section == 0 ?
111-
.init(width: collectionView.frame.width, height: 300) :
118+
.init(width: collectionView.frame.width, height: 300):
112119
.init(width: collectionView.frame.width, height: 272)
113120
}
114121

115-
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
122+
func collectionView(_ collectionView: UICollectionView,
123+
viewForSupplementaryElementOfKind kind: String,
124+
at indexPath: IndexPath) -> UICollectionReusableView {
116125
guard kind == UICollectionView.elementKindSectionHeader,
117126
indexPath.section != 0 else { return UICollectionReusableView() }
118127

HeroListInteractor.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ protocol HeroListInput {
55
}
66

77
protocol HeroListOutput {
8+
var view: HeroListInput! { get set }
89
var shouldShowFooter: Bool { get }
910
var numberOfHeroes: Int { get }
1011
func viewDidLoad()
@@ -91,6 +92,9 @@ class HeroListInteractor: HeroListOutput {
9192
}
9293

9394
private func shouldFetchNextPage(at index: Int) -> Bool {
94-
return index + 1 >= heroes.count && !nextPageFetchingInProgress && !allPagesLoaded && !isInSearchMode
95+
return index + 1 >= heroes.count &&
96+
!nextPageFetchingInProgress &&
97+
!allPagesLoaded &&
98+
!isInSearchMode
9599
}
96100
}

0 commit comments

Comments
 (0)