Skip to content

Commit f544e90

Browse files
authored
Merge pull request #66 from mauriciodesm/main
ActivityListView - still missing some configuration
2 parents 3f35520 + 09624d0 commit f544e90

File tree

4 files changed

+132
-20
lines changed

4 files changed

+132
-20
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// ActivityListView.swift
3+
// FinanceApp
4+
//
5+
// Created by Mauricio on 18/10/22.
6+
//
7+
8+
import UIKit
9+
10+
class ActivityListView: UIView {
11+
private lazy var tableView: UITableView = {
12+
let tableView = UITableView(frame: .zero)
13+
tableView.translatesAutoresizingMaskIntoConstraints = false
14+
tableView.register(ActivityCellView.self, forCellReuseIdentifier: ActivityCellView.reuseIdentifier)
15+
tableView.separatorStyle = .none
16+
return tableView
17+
}()
18+
19+
override init(frame: CGRect) {
20+
super.init(frame: frame)
21+
self.configViews()
22+
self.buildHierarchy()
23+
self.setupConstraints()
24+
}
25+
26+
required init?(coder: NSCoder) {
27+
fatalError("init(coder:) has not been implemented")
28+
}
29+
30+
func reloadData() {
31+
tableView.reloadData()
32+
}
33+
34+
public func configTableViewProtocol(delegate: UITableViewDelegate,
35+
dataSource: UITableViewDataSource) {
36+
self.tableView.delegate = delegate
37+
self.tableView.dataSource = dataSource
38+
}
39+
}
40+
41+
extension ActivityListView: ViewCodable {
42+
func configViews (){
43+
backgroundColor = .white
44+
}
45+
46+
func buildHierarchy(){
47+
addSubview(tableView)
48+
}
49+
50+
func setupConstraints(){
51+
NSLayoutConstraint.activate([
52+
tableView.topAnchor.constraint(equalTo: self.topAnchor),
53+
tableView.leadingAnchor.constraint(equalTo: self.leadingAnchor),
54+
tableView.trailingAnchor.constraint(equalTo: self.trailingAnchor),
55+
tableView.bottomAnchor.constraint(equalTo: self.bottomAnchor)
56+
])
57+
}
58+
}

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,15 @@ final class HomeView: UIView {
2525
return element
2626
}()
2727

28-
private lazy var tableView: UITableView = {
29-
let tableView = UITableView(frame: .zero)
30-
tableView.translatesAutoresizingMaskIntoConstraints = false
31-
tableView.register(ActivityCellView.self, forCellReuseIdentifier: ActivityCellView.reuseIdentifier)
32-
tableView.register(UITableViewCell.self, forCellReuseIdentifier: UITableViewCell.reuseIdentifier)
33-
tableView.dataSource = self
34-
tableView.delegate = self
35-
return tableView
28+
private lazy var activityListView: ActivityListView = {
29+
let element = ActivityListView()
30+
element.translatesAutoresizingMaskIntoConstraints = false
31+
return element
3632
}()
37-
33+
3834
init() {
3935
super.init(frame: .zero)
36+
self.activityListView.configTableViewProtocol(delegate: self, dataSource: self)
4037
self.setupViews()
4138
}
4239

@@ -49,7 +46,7 @@ final class HomeView: UIView {
4946
accountSummaryView.updateValues(balance: configuration.homeData.balance,
5047
savings: configuration.homeData.savings,
5148
spending: configuration.homeData.spending)
52-
tableView.reloadData()
49+
activityListView.reloadData()
5350
}
5451
}
5552

@@ -63,7 +60,7 @@ private extension HomeView {
6360

6461
func configureSubviews() {
6562
addSubview(accountSummaryView)
66-
addSubview(tableView)
63+
addSubview(activityListView)
6764
}
6865

6966
func configureSubviewsConstraints() {
@@ -72,33 +69,34 @@ private extension HomeView {
7269
accountSummaryView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor, constant: 16),
7370
accountSummaryView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor, constant: -16),
7471

75-
tableView.topAnchor.constraint(equalTo: accountSummaryView.bottomAnchor, constant: 16),
76-
tableView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor),
77-
tableView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor),
78-
tableView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor)
72+
activityListView.topAnchor.constraint(equalTo: accountSummaryView.bottomAnchor, constant: 16),
73+
activityListView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor),
74+
activityListView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor),
75+
activityListView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor)
7976
])
8077
}
8178
}
8279

8380
extension HomeView: UITableViewDataSource, UITableViewDelegate {
81+
8482
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
85-
return activities.count
83+
activities.count
8684
}
8785

8886
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
8987
guard let cell: ActivityCellView = .createCell(for: tableView, at: indexPath),
9088
indexPath.row < activities.count else {
9189
return .init()
9290
}
93-
94-
9591
cell.updateValues(activity: activities[indexPath.row])
9692
return cell
9793
}
9894

99-
10095
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
10196
delegate?.didSelectActivity()
10297
}
98+
99+
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
100+
"Activity"
101+
}
103102
}
104-
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)