Skip to content

Commit 8810736

Browse files
committed
implementando testes
1 parent e3b7b55 commit 8810736

File tree

8 files changed

+146
-15
lines changed

8 files changed

+146
-15
lines changed

solutions/devsprint-caio-santos-7/FinanceApp.xcodeproj/project.pbxproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
25C8175528F772FD003127C0 /* AccountSummaryViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25C8175428F772FD003127C0 /* AccountSummaryViewTests.swift */; };
1414
65424F8C28F8CF8A00F7E8D4 /* ActivityDetailsViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65424F8B28F8CF8A00F7E8D4 /* ActivityDetailsViewTests.swift */; };
1515
65424F9428F99E8700F7E8D4 /* ContactListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65424F9328F99E8700F7E8D4 /* ContactListView.swift */; };
16+
65424F9828F9D85000F7E8D4 /* ContactListViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65424F9728F9D85000F7E8D4 /* ContactListViewTests.swift */; };
17+
65424F9B28F9D97800F7E8D4 /* ContactListTableViewCellTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65424F9A28F9D97800F7E8D4 /* ContactListTableViewCellTests.swift */; };
1618
98584A6D277E32C30028DBEA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98584A6C277E32C30028DBEA /* AppDelegate.swift */; };
1719
98584A6F277E32C30028DBEA /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98584A6E277E32C30028DBEA /* SceneDelegate.swift */; };
1820
98584A76277E32C50028DBEA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 98584A75277E32C50028DBEA /* Assets.xcassets */; };
@@ -63,6 +65,8 @@
6365
61A71CDF7B0095F152A3CD4E /* Pods-FinanceApp-FinanceAppUITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FinanceApp-FinanceAppUITests.debug.xcconfig"; path = "Target Support Files/Pods-FinanceApp-FinanceAppUITests/Pods-FinanceApp-FinanceAppUITests.debug.xcconfig"; sourceTree = "<group>"; };
6466
65424F8B28F8CF8A00F7E8D4 /* ActivityDetailsViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityDetailsViewTests.swift; sourceTree = "<group>"; };
6567
65424F9328F99E8700F7E8D4 /* ContactListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactListView.swift; sourceTree = "<group>"; };
68+
65424F9728F9D85000F7E8D4 /* ContactListViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactListViewTests.swift; sourceTree = "<group>"; };
69+
65424F9A28F9D97800F7E8D4 /* ContactListTableViewCellTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactListTableViewCellTests.swift; sourceTree = "<group>"; };
6670
6989344458FFDBA154C3EC32 /* Pods-FinanceApp-FinanceAppUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FinanceApp-FinanceAppUITests.release.xcconfig"; path = "Target Support Files/Pods-FinanceApp-FinanceAppUITests/Pods-FinanceApp-FinanceAppUITests.release.xcconfig"; sourceTree = "<group>"; };
6771
98584A69277E32C30028DBEA /* FinanceApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FinanceApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
6872
98584A6C277E32C30028DBEA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -128,6 +132,7 @@
128132
25C8175228F772BE003127C0 /* Screens */ = {
129133
isa = PBXGroup;
130134
children = (
135+
65424F9628F9D82900F7E8D4 /* ContactList */,
131136
65424F8A28F8CF6300F7E8D4 /* ActivityDetails */,
132137
25C8175328F772C5003127C0 /* Components */,
133138
);
@@ -171,6 +176,23 @@
171176
path = Cells;
172177
sourceTree = "<group>";
173178
};
179+
65424F9628F9D82900F7E8D4 /* ContactList */ = {
180+
isa = PBXGroup;
181+
children = (
182+
65424F9728F9D85000F7E8D4 /* ContactListViewTests.swift */,
183+
65424F9928F9D96100F7E8D4 /* Cells */,
184+
);
185+
path = ContactList;
186+
sourceTree = "<group>";
187+
};
188+
65424F9928F9D96100F7E8D4 /* Cells */ = {
189+
isa = PBXGroup;
190+
children = (
191+
65424F9A28F9D97800F7E8D4 /* ContactListTableViewCellTests.swift */,
192+
);
193+
path = Cells;
194+
sourceTree = "<group>";
195+
};
174196
820E387591A4D6261F2D6AF5 /* Frameworks */ = {
175197
isa = PBXGroup;
176198
children = (
@@ -548,8 +570,10 @@
548570
isa = PBXSourcesBuildPhase;
549571
buildActionMask = 2147483647;
550572
files = (
573+
65424F9B28F9D97800F7E8D4 /* ContactListTableViewCellTests.swift in Sources */,
551574
65424F8C28F8CF8A00F7E8D4 /* ActivityDetailsViewTests.swift in Sources */,
552575
25C8175528F772FD003127C0 /* AccountSummaryViewTests.swift in Sources */,
576+
65424F9828F9D85000F7E8D4 /* ContactListViewTests.swift in Sources */,
553577
);
554578
runOnlyForDeploymentPostprocessing = 0;
555579
};

solutions/devsprint-caio-santos-7/FinanceApp/Screens/ContactList/Cells/ContactListTableViewCell.swift

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import UIKit
99

10-
final class ContactCellView: UITableViewCell {
10+
final class ContactListTableViewCell: UITableViewCell {
1111
static let identifier = "ContactCellIdentifier"
1212

1313
//MARK: - Init
@@ -22,29 +22,82 @@ final class ContactCellView: UITableViewCell {
2222
}
2323

2424
//MARK: - Visual Components
25-
lazy var container: UIStackView = {
26-
let element = UIStackView()
25+
private lazy var container: UIStackView = {
26+
let element = UIStackView(frame: .zero)
2727
element.translatesAutoresizingMaskIntoConstraints = false
2828
element.axis = .horizontal
2929
element.alignment = .center
30+
element.distribution = .fill
31+
element.spacing = 16
32+
33+
return element
34+
}()
35+
36+
private lazy var userImage: UIImageView = {
37+
let element = UIImageView()
38+
element.translatesAutoresizingMaskIntoConstraints = false
39+
element.image = UIImage(named: "avatar-placeholder")
40+
element.tintColor = .blue
41+
element.layer.cornerRadius = 25
42+
element.layer.masksToBounds = true
43+
44+
return element
45+
}()
46+
47+
private lazy var labelStackView: UIStackView = {
48+
let element = UIStackView()
49+
element.translatesAutoresizingMaskIntoConstraints = false
50+
element.axis = .vertical
51+
element.alignment = .leading
52+
element.distribution = .fill
53+
element.spacing = 4
54+
55+
return element
56+
}()
57+
58+
private lazy var nameLabel: UILabel = {
59+
let element = UILabel()
60+
element.translatesAutoresizingMaskIntoConstraints = false
61+
element.text = "Name"
62+
element.font = UIFont.boldSystemFont(ofSize: 16)
63+
64+
return element
65+
}()
66+
67+
private lazy var phoneNumberLabel: UILabel = {
68+
let element = UILabel()
69+
element.translatesAutoresizingMaskIntoConstraints = false
70+
element.text = "+55 11 99999-9999"
71+
element.textColor = .lightGray
3072

3173
return element
3274
}()
3375
}
3476

3577
//MARK: - ViewCodable
36-
extension ContactCellView: ViewCodable {
78+
extension ContactListTableViewCell: ViewCodable {
3779

3880
func buildHierarchy() {
3981
addSubview(container)
82+
container.addArrangedSubview(userImage)
83+
container.addArrangedSubview(labelStackView)
84+
labelStackView.addArrangedSubview(nameLabel)
85+
labelStackView.addArrangedSubview(phoneNumberLabel)
86+
4087
}
4188

4289
func setupConstraints() {
90+
91+
let userImageSize: CGFloat = 50
92+
4393
NSLayoutConstraint.activate([
4494
container.topAnchor.constraint(equalTo: topAnchor),
4595
container.trailingAnchor.constraint(equalTo: trailingAnchor),
4696
container.bottomAnchor.constraint(equalTo: bottomAnchor),
47-
container.leadingAnchor.constraint(equalTo: leadingAnchor),
97+
container.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16),
98+
99+
userImage.heightAnchor.constraint(equalToConstant: userImageSize),
100+
userImage.widthAnchor.constraint(equalToConstant: userImageSize)
48101
])
49102
}
50103
}

solutions/devsprint-caio-santos-7/FinanceApp/Screens/ContactList/ContactListView.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ final class ContactListView: UIView {
1212
static let cellSize = CGFloat(80)
1313

1414
// MARK: - Viusal Components
15-
lazy var tableView: UITableView = {
15+
private lazy var tableView: UITableView = {
1616
let tableView = UITableView(frame: .zero)
1717
tableView.translatesAutoresizingMaskIntoConstraints = false
18-
tableView.register(ContactCellView.self, forCellReuseIdentifier: ContactCellView.identifier)
18+
tableView.register(ContactListTableViewCell.self, forCellReuseIdentifier: ContactListTableViewCell.identifier)
1919
tableView.dataSource = self
2020
tableView.delegate = self
21+
2122
return tableView
2223
}()
2324

@@ -35,7 +36,7 @@ final class ContactListView: UIView {
3536

3637
}
3738

38-
// MARK: - ViewCodable
39+
// MARK: - ViewCodable
3940
extension ContactListView: ViewCodable {
4041

4142
func buildHierarchy() {
@@ -53,18 +54,16 @@ extension ContactListView: ViewCodable {
5354

5455
}
5556

56-
// MARK: - TableView
57+
// MARK: - TableView
5758
extension ContactListView: UITableViewDataSource, UITableViewDelegate {
5859

5960
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
60-
61-
return 8
61+
return 20
6262
}
6363

6464
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
6565

66-
guard let cell = tableView.dequeueReusableCell(withIdentifier: ContactCellView.identifier, for: indexPath) as? ContactCellView else { return UITableViewCell() }
67-
66+
guard let cell = tableView.dequeueReusableCell(withIdentifier: ContactListTableViewCell.identifier, for: indexPath) as? ContactListTableViewCell else { return UITableViewCell() }
6867
return cell
6968
}
7069

solutions/devsprint-caio-santos-7/FinanceApp/Screens/ContactList/ContactListViewController.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
import UIKit
99

10-
class ContactListViewController: UIViewController {
11-
let container = ContactListView()
10+
final class ContactListViewController: UIViewController {
11+
12+
private let container = ContactListView()
1213

1314
override func loadView() {
1415
self.view = container
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// ContactListTableViewCellTests.swift
3+
// FinanceAppTests
4+
//
5+
// Created by Gabriel de Castro Chaves on 14/10/22.
6+
//
7+
8+
@testable import FinanceApp
9+
import SnapshotTesting
10+
import XCTest
11+
12+
final class ContactListTableViewCellTests: XCTestCase {
13+
14+
override class func setUp() {
15+
// SnapshotTesting.isRecording = true
16+
}
17+
18+
func testLoadingComponent() {
19+
let component = ContactListTableViewCell()
20+
assertSnapshot(matching: component, as: .image(on: .iPhoneX))
21+
}
22+
23+
func testRenderView() {
24+
let component = ContactListTableViewCell()
25+
assertSnapshot(matching: component, as: .image(on: .iPhoneX))
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// ContactListViewTests.swift
3+
// FinanceAppTests
4+
//
5+
// Created by Gabriel de Castro Chaves on 14/10/22.
6+
//
7+
8+
@testable import FinanceApp
9+
import SnapshotTesting
10+
import XCTest
11+
12+
final class ContactListViewTests: XCTestCase {
13+
14+
override class func setUp() {
15+
// SnapshotTesting.isRecording = true
16+
}
17+
18+
func testLoadingComponent() {
19+
let component = ContactListViewController()
20+
assertSnapshot(matching: component, as: .image(on: .iPhoneX))
21+
}
22+
23+
func testRenderView() {
24+
let component = ContactListViewController()
25+
assertSnapshot(matching: component, as: .image(on: .iPhoneX))
26+
}
27+
}
Loading
89.6 KB
Loading

0 commit comments

Comments
 (0)