-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathPostCompactCellTests.swift
129 lines (89 loc) · 3.52 KB
/
PostCompactCellTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import UIKit
import XCTest
@testable import WordPress
class PostCompactCellTests: XCTestCase {
var postCell: PostCompactCell!
override func setUp() {
postCell = postCellFromNib()
}
func testShowImageWhenAvailable() {
let post = PostBuilder().withImage().build()
postCell.configure(with: post)
XCTAssertFalse(postCell.featuredImageView.isHidden)
}
func testHideImageWhenNotAvailable() {
let post = PostBuilder().build()
postCell.configure(with: post)
XCTAssertTrue(postCell.featuredImageView.isHidden)
}
func testShowPostTitle() {
let post = PostBuilder().with(title: "Foo bar").build()
postCell.configure(with: post)
XCTAssertEqual(postCell.titleLabel.text, "Foo bar")
}
func testShowDate() {
let post = PostBuilder().with(remoteStatus: .sync)
.with(dateCreated: Date()).build()
postCell.configure(with: post)
XCTAssertEqual(postCell.timestampLabel.text, "just now")
}
func testMoreAction() {
let postActionSheetDelegateMock = PostActionSheetDelegateMock()
let post = PostBuilder().published().build()
postCell.configure(with: post)
postCell.setActionSheetDelegate(postActionSheetDelegateMock)
postCell.menuButton.sendActions(for: .touchUpInside)
XCTAssertEqual(postActionSheetDelegateMock.calledWithPost, post)
XCTAssertEqual(postActionSheetDelegateMock.calledWithView, postCell.menuButton)
}
func testStatusAndBadgeLabels() {
let post = PostBuilder().with(remoteStatus: .sync)
.with(dateCreated: Date()).is(sticked: true).build()
postCell.configure(with: post)
XCTAssertEqual(postCell.badgesLabel.text, "Sticky")
}
func testHideBadgesWhenEmpty() {
let post = PostBuilder().build()
postCell.configure(with: post)
XCTAssertEqual(postCell.badgesLabel.text, "Uploading post...")
XCTAssertFalse(postCell.badgesLabel.isHidden)
}
func testShowBadgesWhenNotEmpty() {
let post = PostBuilder()
.with(remoteStatus: .sync)
.build()
postCell.configure(with: post)
XCTAssertEqual(postCell.badgesLabel.text, "")
XCTAssertTrue(postCell.badgesLabel.isHidden)
}
func testShowProgressView() {
let post = PostBuilder()
.with(remoteStatus: .pushing)
.published().build()
postCell.configure(with: post)
XCTAssertFalse(postCell.progressView.isHidden)
}
func testHideProgressView() {
let post = PostBuilder()
.with(remoteStatus: .sync)
.published().build()
postCell.configure(with: post)
XCTAssertTrue(postCell.progressView.isHidden)
}
func testShowsWarningMessageForFailedPublishedPosts() {
// Given
let post = PostBuilder().published().with(remoteStatus: .failed).confirmedAutoUpload().build()
// When
postCell.configure(with: post)
// Then
XCTAssertEqual(postCell.badgesLabel.text, i18n("We'll publish the post when your device is back online."))
XCTAssertEqual(postCell.badgesLabel.textColor, UIColor.warning)
}
private func postCellFromNib() -> PostCompactCell {
let bundle = Bundle(for: PostCompactCell.self)
guard let postCell = bundle.loadNibNamed("PostCompactCell", owner: nil)?.first as? PostCompactCell else {
fatalError("PostCompactCell does not exist")
}
return postCell
}
}