Skip to content

Commit 09624d0

Browse files
committed
Ajustes PR
1 parent 51bdc8f commit 09624d0

File tree

4 files changed

+68
-15
lines changed

4 files changed

+68
-15
lines changed

solutions/devsprint-caio-santos-7/FinanceApp/Screens/ActivityDetails/ActivityListView.swift

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@
88
import UIKit
99

1010
class ActivityListView: UIView {
11-
12-
private var activities: [Activity] = []
13-
1411
private lazy var tableView: UITableView = {
1512
let tableView = UITableView(frame: .zero)
1613
tableView.translatesAutoresizingMaskIntoConstraints = false
1714
tableView.register(ActivityCellView.self, forCellReuseIdentifier: ActivityCellView.reuseIdentifier)
18-
tableView.register(UITableViewCell.self, forCellReuseIdentifier: UITableViewCell.reuseIdentifier)
19-
15+
tableView.separatorStyle = .none
2016
return tableView
2117
}()
2218

@@ -31,16 +27,15 @@ class ActivityListView: UIView {
3127
fatalError("init(coder:) has not been implemented")
3228
}
3329

34-
func updateTableView(with configuration: HomeViewConfiguration) {
35-
activities = configuration.homeData.activity
30+
func reloadData() {
3631
tableView.reloadData()
3732
}
3833

39-
public func configTableViewProtocol(delegate: UITableViewDelegate, dataSource: UITableViewDataSource){
34+
public func configTableViewProtocol(delegate: UITableViewDelegate,
35+
dataSource: UITableViewDataSource) {
4036
self.tableView.delegate = delegate
4137
self.tableView.dataSource = dataSource
4238
}
43-
4439
}
4540

4641
extension ActivityListView: ViewCodable {
@@ -60,5 +55,4 @@ extension ActivityListView: ViewCodable {
6055
tableView.bottomAnchor.constraint(equalTo: self.bottomAnchor)
6156
])
6257
}
63-
6458
}

solutions/devsprint-caio-santos-7/FinanceApp/Screens/Home/HomeView.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ final class HomeView: UIView {
4242
}
4343

4444
func updateView(with configuration: HomeViewConfiguration) {
45+
activities = configuration.homeData.activity
4546
accountSummaryView.updateValues(balance: configuration.homeData.balance,
4647
savings: configuration.homeData.savings,
4748
spending: configuration.homeData.spending)
48-
activityListView.updateTableView(with: configuration)
49+
activityListView.reloadData()
4950
}
50-
5151
}
5252

5353
private extension HomeView {
@@ -79,8 +79,8 @@ private extension HomeView {
7979

8080
extension HomeView: UITableViewDataSource, UITableViewDelegate {
8181

82-
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
83-
return activities.count
82+
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
83+
activities.count
8484
}
8585

8686
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
@@ -95,5 +95,8 @@ public func tableView(_ tableView: UITableView, numberOfRowsInSection section: I
9595
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
9696
delegate?.didSelectActivity()
9797
}
98+
99+
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
100+
"Activity"
101+
}
98102
}
99-
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// ActivityListViewTests.swift
3+
// FinanceAppTests
4+
//
5+
// Created by Caio Santos on 18/10/22.
6+
//
7+
8+
import UIKit
9+
import SnapshotTesting
10+
import XCTest
11+
12+
@testable import FinanceApp
13+
14+
final class ActivityListViewTests: XCTestCase {
15+
16+
private var sut: ActivityListView?
17+
private var activities: [Activity] = [
18+
.init(name: "Test", price: 99, time: "Test"),
19+
.init(name: "Test", price: 99, time: "Test"),
20+
.init(name: "Test", price: 99, time: "Test"),
21+
.init(name: "Test", price: 99, time: "Test"),
22+
]
23+
24+
override func setUp() {
25+
// SnapshotTesting.isRecording = true
26+
sut = ActivityListView()
27+
}
28+
29+
func testRenderView() throws {
30+
let unwrappedSut = try XCTUnwrap(sut)
31+
unwrappedSut.configTableViewProtocol(delegate: self, dataSource: self)
32+
assertSnapshot(matching: unwrappedSut, as: .image(size: .init(width: UIScreen.main.bounds.width,
33+
height: 527)))
34+
}
35+
}
36+
37+
extension ActivityListViewTests: UITableViewDataSource, UITableViewDelegate {
38+
39+
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
40+
return activities.count
41+
}
42+
43+
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
44+
guard let cell: ActivityCellView = .createCell(for: tableView, at: indexPath),
45+
indexPath.row < activities.count else {
46+
return .init()
47+
}
48+
cell.updateValues(activity: activities[indexPath.row])
49+
return cell
50+
}
51+
52+
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
53+
"Activity"
54+
}
55+
}
56+
50.9 KB
Loading

0 commit comments

Comments
 (0)