Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// ActivityListView.swift
// FinanceApp
//
// Created by Mauricio on 18/10/22.
//

import UIKit

class ActivityListView: UIView {
private lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero)
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.register(ActivityCellView.self, forCellReuseIdentifier: ActivityCellView.reuseIdentifier)
tableView.separatorStyle = .none
return tableView
}()

override init(frame: CGRect) {
super.init(frame: frame)
self.configViews()
self.buildHierarchy()
self.setupConstraints()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

func reloadData() {
tableView.reloadData()
}

public func configTableViewProtocol(delegate: UITableViewDelegate,
dataSource: UITableViewDataSource) {
self.tableView.delegate = delegate
self.tableView.dataSource = dataSource
}
}

extension ActivityListView: ViewCodable {
func configViews (){
backgroundColor = .white
}

func buildHierarchy(){
addSubview(tableView)
}

func setupConstraints(){
NSLayoutConstraint.activate([
tableView.topAnchor.constraint(equalTo: self.topAnchor),
tableView.leadingAnchor.constraint(equalTo: self.leadingAnchor),
tableView.trailingAnchor.constraint(equalTo: self.trailingAnchor),
tableView.bottomAnchor.constraint(equalTo: self.bottomAnchor)
])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,15 @@ final class HomeView: UIView {
return element
}()

private lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero)
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.register(ActivityCellView.self, forCellReuseIdentifier: ActivityCellView.reuseIdentifier)
tableView.register(UITableViewCell.self, forCellReuseIdentifier: UITableViewCell.reuseIdentifier)
tableView.dataSource = self
tableView.delegate = self
return tableView
private lazy var activityListView: ActivityListView = {
let element = ActivityListView()
element.translatesAutoresizingMaskIntoConstraints = false
return element
}()

init() {
super.init(frame: .zero)
self.activityListView.configTableViewProtocol(delegate: self, dataSource: self)
self.setupViews()
}

Expand All @@ -49,7 +46,7 @@ final class HomeView: UIView {
accountSummaryView.updateValues(balance: configuration.homeData.balance,
savings: configuration.homeData.savings,
spending: configuration.homeData.spending)
tableView.reloadData()
activityListView.reloadData()
}
}

Expand All @@ -63,7 +60,7 @@ private extension HomeView {

func configureSubviews() {
addSubview(accountSummaryView)
addSubview(tableView)
addSubview(activityListView)
}

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

tableView.topAnchor.constraint(equalTo: accountSummaryView.bottomAnchor, constant: 16),
tableView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor),
tableView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor),
tableView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor)
activityListView.topAnchor.constraint(equalTo: accountSummaryView.bottomAnchor, constant: 16),
activityListView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor),
activityListView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor),
activityListView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor)
])
}
}

extension HomeView: UITableViewDataSource, UITableViewDelegate {

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

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell: ActivityCellView = .createCell(for: tableView, at: indexPath),
indexPath.row < activities.count else {
return .init()
}


cell.updateValues(activity: activities[indexPath.row])
return cell
}


func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
delegate?.didSelectActivity()
}

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
"Activity"
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// ActivityListViewTests.swift
// FinanceAppTests
//
// Created by Caio Santos on 18/10/22.
//

import UIKit
import SnapshotTesting
import XCTest

@testable import FinanceApp

final class ActivityListViewTests: XCTestCase {

private var sut: ActivityListView?
private var activities: [Activity] = [
.init(name: "Test", price: 99, time: "Test"),
.init(name: "Test", price: 99, time: "Test"),
.init(name: "Test", price: 99, time: "Test"),
.init(name: "Test", price: 99, time: "Test"),
]

override func setUp() {
// SnapshotTesting.isRecording = true
sut = ActivityListView()
}

func testRenderView() throws {
let unwrappedSut = try XCTUnwrap(sut)
unwrappedSut.configTableViewProtocol(delegate: self, dataSource: self)
assertSnapshot(matching: unwrappedSut, as: .image(size: .init(width: UIScreen.main.bounds.width,
height: 527)))
}
}

extension ActivityListViewTests: UITableViewDataSource, UITableViewDelegate {

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

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell: ActivityCellView = .createCell(for: tableView, at: indexPath),
indexPath.row < activities.count else {
return .init()
}
cell.updateValues(activity: activities[indexPath.row])
return cell
}

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
"Activity"
}
}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.