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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import XCTest
extension OldFellaUITests {
func testProfileLinksShowTitlesAndOpenPostsInsideApp() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
let profile = app.buttons["profileLink-mae"].firstMatch
XCTAssertTrue(profile.waitForExistence(timeout: 5))
profile.tap()
let photos = app.descendants(matching: .any)["profileLink-photos"].firstMatch
XCTAssertTrue(photos.waitForExistence(timeout: 5))
XCTAssertTrue(photos.label.contains("My Photos!"))
let github = app.descendants(matching: .any)["profileLink-github"].firstMatch
XCTAssertTrue(github.exists)
XCTAssertTrue(github.label.contains("GitHub"))
let screenshot = XCTAttachment(screenshot: app.screenshot())
screenshot.lifetime = .keepAlways
add(screenshot)
XCTAssertEqual(photos.frame.midY, github.frame.midY, accuracy: 2)
XCTAssertLessThan(photos.frame.maxX, github.frame.minX)
let website = app.descendants(matching: .any)["profileWebsiteLink"].firstMatch
XCTAssertTrue(website.exists)
XCTAssertGreaterThan(website.frame.minY, photos.frame.maxY)
let post = app.descendants(matching: .any)["profileLink-post"].firstMatch
post.tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
}
func testOwnProfileOpens() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-info-label"]
app.launch()
app.openOwnProfile()
XCTAssertTrue(app.staticTexts["profileDisplayName"].waitForExistence(timeout: 5))
XCTAssertEqual(app.staticTexts["profileDisplayName"].label, "Demo Account")
let photos = app.descendants(matching: .any)["profileLink-photos"].firstMatch
XCTAssertTrue(photos.waitForExistence(timeout: 5))
XCTAssertTrue(photos.label.contains("My Photos!"))
let github = app.descendants(matching: .any)["profileLink-github"].firstMatch
XCTAssertTrue(github.exists)
XCTAssertEqual(photos.frame.midY, github.frame.midY, accuracy: 2)
let counts = app.descendants(matching: .any)["profileCounts"].firstMatch
XCTAssertTrue(counts.exists)
XCTAssertLessThan(photos.frame.maxY, counts.frame.minY)
XCTAssertFalse(app.descendants(matching: .any)["profileLink-hidden"].firstMatch.exists)
let screenshot = XCTAttachment(screenshot: app.screenshot())
screenshot.lifetime = .keepAlways
add(screenshot)
}
func testEarlierPostsCueAppearsInThread() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
let post = app.buttons["postText-post-2"]
XCTAssertTrue(post.waitForExistence(timeout: 5))
post.tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
XCTAssertTrue(app.descendants(matching: .any)["earlierPostsCue"].waitForExistence(timeout: 5))
}
func testFollowingBarRemainsVisibleWhenScrolling() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
let headerControl = app.buttons[UIDevice.current.userInterfaceIdiom == .pad
? "yourProfileButton" : "feedPickerButton"]
XCTAssertTrue(headerControl.waitForExistence(timeout: 5))
app.swipeUp()
app.swipeUp()
XCTAssertTrue(headerControl.isHittable)
}
func testGIFSettingControlsPostAndQuotedGIFs() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-gif"]
app.launch()
app.buttons["demoSignInButton"].tap()
XCTAssertTrue(app.descendants(matching: .any)["inlineGIF"].firstMatch.waitForExistence(timeout: 5))
let gif = app.buttons["A moving square."].firstMatch
XCTAssertTrue(gif.waitForExistence(timeout: 5))
app.swipeUp()
gif.tap()
XCTAssertTrue(app.buttons["imageViewerClose"].waitForExistence(timeout: 5))
app.buttons["imageDescriptionButton"].tap()
XCTAssertTrue(app.staticTexts["A moving square."].waitForExistence(timeout: 5))
app.buttons["imageViewerClose"].tap()
XCTAssertEqual(app.buttons.matching(identifier: "showGIFButton").count, 0)
let quote = app.cells.containing(.button, identifier: "postText-post-1").firstMatch
XCTAssertTrue(quote.buttons["showReplyGIFButton"].firstMatch.waitForExistence(timeout: 5))
XCTAssertFalse(app.descendants(matching: .any)["replyPostContext-post-1"].exists)
app.openSettings()
let setting = app.switches["showGIFsInline"]
XCTAssertTrue(setting.waitForExistence(timeout: 5))
setting.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap()
XCTAssertEqual(String(describing: setting.value ?? ""), "0")
app.closeSettings()
let buttons = app.buttons.matching(identifier: "showGIFButton")
XCTAssertTrue(app.buttons["showReplyGIFButton"].firstMatch.waitForExistence(timeout: 5))
XCTAssertTrue(buttons.firstMatch.waitForExistence(timeout: 5))
buttons.firstMatch.tap()
XCTAssertTrue(app.buttons["A moving square."].firstMatch.waitForExistence(timeout: 5))
XCTAssertFalse(quote.buttons["showGIFButton"].exists)
}
func testQuotedGIFNeedsOnlyOneRevealWhenSettingIsOff() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-gif", "-ui-testing-signed-in"]
app.launch()
app.openSettings()
let setting = app.switches["showGIFsInline"]
XCTAssertTrue(setting.waitForExistence(timeout: 5))
setting.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap()
XCTAssertEqual(String(describing: setting.value ?? ""), "0")
app.closeSettings()
let post = app.cells.containing(.button, identifier: "postText-post-1").firstMatch
let reveal = post.buttons["showReplyGIFButton"].firstMatch
XCTAssertTrue(reveal.waitForExistence(timeout: 5))
reveal.tap()
XCTAssertTrue(post.buttons["GIF"].firstMatch.waitForExistence(timeout: 5))
XCTAssertFalse(post.buttons["showReplyGIFButton"].exists)
XCTAssertTrue(post.buttons["showGIFButton"].exists)
}
func testDirectReplyGIFFollowsSetting() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-gif", "-ui-testing-signed-in"]
app.launch()
let reply = app.cells.containing(.button, identifier: "postText-post-2").firstMatch
for _ in 0..<5 {
if reply.exists { break }
app.swipeUp()
}
XCTAssertTrue(reply.waitForExistence(timeout: 5))
XCTAssertTrue(reply.descendants(matching: .any)["inlineGIF"].firstMatch.waitForExistence(timeout: 5))
XCTAssertFalse(reply.buttons["showGIFButton"].exists)
app.openSettings()
let setting = app.switches["showGIFsInline"]
XCTAssertTrue(setting.waitForExistence(timeout: 5))
setting.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap()
XCTAssertEqual(String(describing: setting.value ?? ""), "0")
app.closeSettings()
for _ in 0..<5 {
if reply.buttons["showGIFButton"].exists { break }
app.swipeUp()
}
XCTAssertTrue(reply.buttons["showGIFButton"].firstMatch.waitForExistence(timeout: 5))
}
func testVideoViewerUsesNativeDismissal() throws {
try XCTSkipIf(UIDevice.current.userInterfaceIdiom == .pad, "Requires the iPhone player layout")
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-video"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
let video = app.buttons["Tap here to play the video"].firstMatch
XCTAssertTrue(video.waitForExistence(timeout: 5))
for _ in 0..<2 {
video.tap()
let failure = app.alerts["Video could not be played"]
XCTAssertTrue(failure.waitForExistence(timeout: 10))
failure.buttons["OK"].tap()
app.coordinate(withNormalizedOffset: CGVector(dx: 0.11, dy: 0.096)).tap()
XCTAssertTrue(video.waitForExistence(timeout: 5))
XCTAssertTrue(video.isHittable)
}
}
func testPostTimestampIsRelativeInFeedAndDetail() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
let timestamp = app.staticTexts["postTimestamp-post-1"]
XCTAssertTrue(timestamp.waitForExistence(timeout: 5))
XCTAssertLessThanOrEqual(timestamp.label.count, 4)
let author = app.buttons["profileLink-mae"].firstMatch
XCTAssertTrue(author.waitForExistence(timeout: 5))
XCTAssertEqual(timestamp.frame.midY, author.frame.midY, accuracy: 2)
app.buttons["postText-post-1"].tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
let detailTimestamp = app.staticTexts["postTimestamp-post-1"].firstMatch
XCTAssertTrue(detailTimestamp.waitForExistence(timeout: 5))
XCTAssertLessThanOrEqual(detailTimestamp.label.count, 4)
app.navigationBars.buttons["Following"].tap()
app.openSettings()
XCTAssertFalse(app.buttons["postTimestampSetting"].exists)
}
func testQuoteShowsOriginalAndOpensPost() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
let quote = app.buttons["quotedPostLink"]
for _ in 0..<5 {
if quote.exists && quote.isHittable { break }
app.swipeUp()
}
XCTAssertTrue(quote.exists)
XCTAssertTrue(quote.label.contains("Quoted Alex Kim"))
XCTAssertFalse(quote.label.contains("@alex.example"))
quote.tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
}
}