Skip to content

Commit 589f56f

Browse files
committed
Add tests for SummaryTableViewCell
Test styles as well
1 parent ca5fdb5 commit 589f56f

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed

WooCommerce/Classes/ViewRelated/Orders/Cells/SummaryTableViewCell.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class SummaryTableViewCell: UITableViewCell {
1919
///
2020
@IBOutlet private weak var paymentStatusLabel: PaddedLabel!
2121

22-
/// Button: Update Order Status
22+
/// Button: Manually Update Order Status
2323
///
2424
@IBOutlet private var updateStatusButton: UIButton!
2525

@@ -136,3 +136,23 @@ private extension SummaryTableViewCell {
136136
comment: "Accessibility hint for the button that allows updating the order status in Order Details View")
137137
}
138138
}
139+
140+
141+
/// MARK: - Testability
142+
extension SummaryTableViewCell {
143+
func getTitle() -> UILabel {
144+
return titleLabel
145+
}
146+
147+
func getCreatedLabel() -> UILabel {
148+
return createdLabel
149+
}
150+
151+
func getStatusLabel() -> UILabel {
152+
return paymentStatusLabel
153+
}
154+
155+
func getEditButton() -> UIButton {
156+
return updateStatusButton
157+
}
158+
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@
293293
D85B8333222FABD1002168F3 /* StatusListTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D85B8331222FABD1002168F3 /* StatusListTableViewCell.swift */; };
294294
D85B8334222FABD1002168F3 /* StatusListTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D85B8332222FABD1002168F3 /* StatusListTableViewCell.xib */; };
295295
D85B8336222FCDA1002168F3 /* StatusListTableViewCellTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D85B8335222FCDA1002168F3 /* StatusListTableViewCellTests.swift */; };
296+
D85B833F2230F268002168F3 /* SummaryTableViewCellTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D85B833E2230F268002168F3 /* SummaryTableViewCellTests.swift */; };
296297
/* End PBXBuildFile section */
297298

298299
/* Begin PBXContainerItemProxy section */
@@ -632,6 +633,7 @@
632633
D85B8331222FABD1002168F3 /* StatusListTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusListTableViewCell.swift; sourceTree = "<group>"; };
633634
D85B8332222FABD1002168F3 /* StatusListTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = StatusListTableViewCell.xib; sourceTree = "<group>"; };
634635
D85B8335222FCDA1002168F3 /* StatusListTableViewCellTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = StatusListTableViewCellTests.swift; path = WooCommerceTests/Views/StatusListTableViewCellTests.swift; sourceTree = SOURCE_ROOT; };
636+
D85B833E2230F268002168F3 /* SummaryTableViewCellTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SummaryTableViewCellTests.swift; path = WooCommerceTests/Views/SummaryTableViewCellTests.swift; sourceTree = SOURCE_ROOT; };
635637
/* End PBXFileReference section */
636638

637639
/* Begin PBXFrameworksBuildPhase section */
@@ -767,6 +769,7 @@
767769
B53A569521123D27000776C9 /* Tools */ = {
768770
isa = PBXGroup;
769771
children = (
772+
D85B833E2230F268002168F3 /* SummaryTableViewCellTests.swift */,
770773
D85B8335222FCDA1002168F3 /* StatusListTableViewCellTests.swift */,
771774
93FA787121CD2A1A00B663E5 /* CurrencySettingsTests.swift */,
772775
B53A569621123D3B000776C9 /* ResultsControllerUIKitTests.swift */,
@@ -1956,6 +1959,7 @@
19561959
B53A569D21123EEB000776C9 /* MockupStorage.swift in Sources */,
19571960
B57C5C9E21B80E8300FF82B2 /* SessionManager+Internal.swift in Sources */,
19581961
B55BC1F321A8790F0011A0C0 /* StringHTMLTests.swift in Sources */,
1962+
D85B833F2230F268002168F3 /* SummaryTableViewCellTests.swift in Sources */,
19591963
B5980A6721AC91AA00EBF596 /* BundleWooTests.swift in Sources */,
19601964
CEEC9B6021E79CAA0055EEF0 /* FeatureFlagTests.swift in Sources */,
19611965
B53A569B21123E8E000776C9 /* MockupTableView.swift in Sources */,
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import XCTest
2+
@testable import WooCommerce
3+
@testable import Yosemite
4+
5+
final class SummaryTableViewCellTests: XCTestCase {
6+
private var cell: SummaryTableViewCell?
7+
8+
override func setUp() {
9+
super.setUp()
10+
let nib = Bundle.main.loadNibNamed("SummaryTableViewCell", owner: self, options: nil)
11+
cell = nib?.first as? SummaryTableViewCell
12+
}
13+
14+
override func tearDown() {
15+
cell = nil
16+
super.tearDown()
17+
}
18+
19+
func testTitleSetsTitleLabelText() {
20+
let mockTitle = "Automattic"
21+
cell?.title = mockTitle
22+
23+
XCTAssertEqual(cell?.getTitle().text, mockTitle)
24+
}
25+
26+
func testDateCreatedSetsDateLabelText() {
27+
let mockDate = Date().toString(dateStyle: .medium, timeStyle: .short)
28+
cell?.dateCreated = mockDate
29+
30+
XCTAssertEqual(cell?.getCreatedLabel().text, mockDate)
31+
}
32+
33+
func testDisplayStatusSetsPaymentDateLabel() {
34+
let mockStatus = OrderStatus(name: "Automattic", siteID: 0, slug: "automattic", total: 0)
35+
cell?.display(orderStatus: mockStatus)
36+
37+
XCTAssertEqual(cell?.getStatusLabel().text, mockStatus.name)
38+
}
39+
40+
func testTappingButtonExecutesCallback() {
41+
let expect = expectation(description: "The action assigned gets called")
42+
cell?.onPencilTouchUp = {
43+
expect.fulfill()
44+
}
45+
46+
cell?.getEditButton().sendActions(for: .touchUpInside)
47+
48+
waitForExpectations(timeout: 1, handler: nil)
49+
}
50+
51+
func testTitleLabelIsAppliedHeadStyle() {
52+
let mockLabel = UILabel()
53+
mockLabel.applyHeadlineStyle()
54+
55+
let cellTitleLabel = cell?.getTitle()
56+
57+
XCTAssertEqual(cellTitleLabel?.font, mockLabel.font)
58+
XCTAssertEqual(cellTitleLabel?.textColor, mockLabel.textColor)
59+
}
60+
61+
func testCreatedLabelIsAppliedHeadStyle() {
62+
let mockLabel = UILabel()
63+
mockLabel.applyFootnoteStyle()
64+
65+
let cellCreatedLabel = cell?.getCreatedLabel()
66+
67+
XCTAssertEqual(cellCreatedLabel?.font, mockLabel.font)
68+
XCTAssertEqual(cellCreatedLabel?.textColor, mockLabel.textColor)
69+
}
70+
71+
func testStatusLabelIsAppliedPaddedLabelStyle() {
72+
let mockLabel = UILabel()
73+
mockLabel.applyPaddedLabelDefaultStyles()
74+
75+
let cellStatusLabel = cell?.getStatusLabel()
76+
77+
XCTAssertEqual(cellStatusLabel?.font, mockLabel.font)
78+
XCTAssertEqual(cellStatusLabel?.layer.borderWidth, mockLabel.layer.borderWidth)
79+
XCTAssertEqual(cellStatusLabel?.layer.cornerRadius, mockLabel.layer.cornerRadius)
80+
}
81+
}

0 commit comments

Comments
 (0)