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
211
212
213
214
215
216
217
218
219
220
221
222
import XCTest
extension OldFellaUITests {
func testCustomFeedShowsLoadingCardsAndRefreshSpinner() {
let app = XCUIApplication()
app.launchArguments = [
"-ui-testing", "-ui-testing-signed-in", "-ui-testing-start-custom-feed", "-ui-testing-feed-delay"
]
app.launch()
XCTAssertTrue(app.navigationBars["Nature"].waitForExistence(timeout: 5))
XCTAssertTrue(app.otherElements["initialFeedLoadingCards"].exists)
let spinner = app.descendants(matching: .any)["initialFeedRefreshControl"].firstMatch
XCTAssertTrue(spinner.waitForExistence(timeout: 2))
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 20))
XCTAssertTrue(spinner.waitForNonExistence(timeout: 2))
}
func testProfileLoadingWithFastDetails() {
let app = XCUIApplication()
app.launchArguments = [
"-ui-testing", "-ui-testing-signed-in", "-ui-testing-profile-fast-load", "-ui-testing-dark"
]
app.launch()
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
app.buttons["profileLink-mae"].firstMatch.tap()
let spinner = app.descendants(matching: .any)["initialProfileRefreshControl"].firstMatch
XCTAssertTrue(spinner.exists)
let header = app.staticTexts["profileDisplayName"]
XCTAssertTrue(header.waitForExistence(timeout: 2))
XCTAssertFalse(app.staticTexts["Loading profile"].exists)
let before = XCTAttachment(screenshot: app.screenshot())
before.name = "Fast profile loading"
before.lifetime = .keepAlways
add(before)
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 8))
XCTAssertTrue(spinner.waitForNonExistence(timeout: 2))
XCTAssertTrue(header.exists)
let after = XCTAttachment(screenshot: app.screenshot())
after.name = "Fast profile loaded"
after.lifetime = .keepAlways
add(after)
let refreshedPost = app.buttons["postText-profile-post-refreshed"]
XCTAssertFalse(refreshedPost.exists)
pullProfileToRefresh(in: app)
XCTAssertTrue(refreshedPost.waitForExistence(timeout: 10))
XCTAssertTrue(spinner.waitForNonExistence(timeout: 2))
XCTAssertTrue(header.exists)
}
func testProfileFeedShowsLoadingCardsAndRefreshSpinner() {
let app = XCUIApplication()
app.launchArguments = [
"-ui-testing", "-ui-testing-signed-in", "-ui-testing-profile-details-delay",
"-ui-testing-profile-feed-delay"
]
app.launch()
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
app.buttons["profileLink-mae"].firstMatch.tap()
let spinner = app.descendants(matching: .any)["initialProfileRefreshControl"].firstMatch
XCTAssertTrue(spinner.waitForExistence(timeout: 2))
XCTAssertFalse(app.staticTexts["Loading profile"].exists)
XCTAssertTrue(app.staticTexts["profileDisplayName"].waitForExistence(timeout: 5))
XCTAssertTrue(app.otherElements["profilePostsLoading"].exists)
XCTAssertTrue(spinner.waitForExistence(timeout: 2))
pullProfileToRefresh(in: app)
XCTAssertTrue(spinner.exists)
let screenshot = XCTAttachment(screenshot: app.screenshot())
screenshot.name = "Initial profile refresh spinner"
screenshot.lifetime = .keepAlways
add(screenshot)
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 20))
XCTAssertTrue(spinner.waitForNonExistence(timeout: 2))
XCTAssertFalse(app.otherElements["profilePostsLoading"].exists)
XCTAssertTrue(app.staticTexts["profileDisplayName"].exists)
}
private func pullProfileToRefresh(in app: XCUIApplication) {
let list = app.collectionViews["profilePostList"]
let start = list.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.4))
let end = list.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.85))
start.press(forDuration: 0.05, thenDragTo: end, withVelocity: .slow, thenHoldForDuration: 0.2)
}
func testPreferenceFailureStaysBlockedAfterForeground() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-preferences-fail"]
app.launch()
let error = app.staticTexts["Could not load content preferences"]
XCTAssertTrue(error.waitForExistence(timeout: 10))
XCUIDevice.shared.press(.home)
app.activate()
XCTAssertTrue(error.waitForExistence(timeout: 5))
XCTAssertFalse(app.otherElements["Loading content preferences"].exists)
XCTAssertFalse(app.buttons["postText-post-1"].exists)
XCTAssertFalse(app.tables.firstMatch.exists)
}
func testCachedPreferenceRefreshFailureShowsContentWithoutNotice() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-preferences-refresh-fail"]
app.launch()
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 15))
XCUIDevice.shared.press(.home)
app.activate()
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
XCTAssertFalse(
app.staticTexts.containing(NSPredicate(format: "label CONTAINS 'Could not refresh content preferences'"))
.firstMatch.exists)
XCTAssertFalse(app.buttons["Retry"].exists)
}
func testIPadShowsHandlesDuringSessionRestoration() throws {
try XCTSkipUnless(UIDevice.current.userInterfaceIdiom == .pad, "Requires iPad")
XCUIDevice.shared.orientation = .landscapeLeft
defer { XCUIDevice.shared.orientation = .portrait }
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-restore-delay"]
app.launch()
XCTAssertTrue(app.images["moveColumn-following"].waitForExistence(timeout: 2))
XCTAssertTrue(app.images["moveColumn-notifications"].exists)
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
XCTAssertTrue(app.images["moveColumn-following"].exists)
XCTAssertTrue(app.images["moveColumn-notifications"].exists)
}
func testIPadDraggingKeepsFeedViewUpdatesBounded() throws {
try XCTSkipUnless(UIDevice.current.userInterfaceIdiom == .pad, "Requires iPad")
XCUIDevice.shared.orientation = .landscapeLeft
defer { XCUIDevice.shared.orientation = .portrait }
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-profile-view-updates"]
app.launch()
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
let handle = app.images["moveColumn-notifications"]
XCTAssertTrue(handle.waitForExistence(timeout: 5))
app.buttons["Reset view update counts"].tap()
let start = handle.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
start.press(forDuration: 0.2, thenDragTo: start.withOffset(CGVector(dx: -(app.frame.width - 12) / 2, dy: 0)))
app.buttons["Read view update counts"].tap()
let snapshot = app.staticTexts["viewUpdateCounts"].value as? String ?? ""
let counts = Dictionary(
uniqueKeysWithValues: snapshot.split(separator: ";").compactMap { entry -> (String, Int)? in
let pair = entry.split(separator: "=")
guard pair.count == 2, let count = Int(pair[1]) else { return nil }
return (String(pair[0]), count)
})
for name in ["FeedView", "NotificationsView"] {
XCTAssertLessThanOrEqual(
counts[name, default: 0], 4, "Dragging must not rebuild \(name) on each update: \(snapshot)")
}
}
func testIPadShowsFollowingAndNotifications() throws {
try XCTSkipUnless(UIDevice.current.userInterfaceIdiom == .pad, "Requires iPad")
XCUIDevice.shared.orientation = .landscapeLeft
defer { XCUIDevice.shared.orientation = .portrait }
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
XCTAssertEqual(app.staticTexts.matching(identifier: "Following").count, 1)
XCTAssertEqual(app.staticTexts.matching(identifier: "Notifications").count, 1)
XCTAssertTrue(app.navigationBars["Following"].exists)
XCTAssertTrue(app.navigationBars["Notifications"].exists)
app.buttons["postText-post-1"].tap()
XCTAssertTrue(app.navigationBars.buttons.element(boundBy: 0).waitForExistence(timeout: 5))
app.navigationBars.buttons.element(boundBy: 0).tap()
openPadActions(app)
XCTAssertTrue(app.buttons["yourProfileButton"].exists)
app.buttons["Settings"].tap()
XCTAssertTrue(app.navigationBars["Settings"].waitForExistence(timeout: 5))
app.buttons["Done"].tap()
app.buttons["New post"].tap()
XCTAssertTrue(app.textViews["composeTextField"].waitForExistence(timeout: 5))
}
func testIPadLandscapeShowsIndependentLoadingSpinnersInEveryColumn() throws {
try XCTSkipUnless(UIDevice.current.userInterfaceIdiom == .pad, "Requires iPad")
XCUIDevice.shared.orientation = .landscapeLeft
defer { XCUIDevice.shared.orientation = .portrait }
let app = XCUIApplication()
app.launchArguments = [
"-ui-testing", "-ui-testing-signed-in", "-ui-testing-three-loading-columns",
"-ui-testing-restore-delay", "-ui-testing-feed-delay", "-ui-testing-notification-delay"
]
app.launch()
XCTAssertTrue(app.navigationBars["Nature"].waitForExistence(timeout: 5))
let feeds = app.descendants(matching: .any).matching(identifier: "initialFeedRefreshControl")
XCTAssertTrue(feeds.firstMatch.waitForExistence(timeout: 2))
XCTAssertEqual(feeds.count, 2)
let notifications = app.descendants(matching: .any)["initialNotificationsRefreshControl"].firstMatch
XCTAssertTrue(notifications.exists)
for spinner in feeds.allElementsBoundByIndex + [notifications] {
XCTAssertFalse(spinner.frame.isEmpty)
XCTAssertTrue(app.frame.contains(spinner.frame))
}
let screenshot = XCTAttachment(screenshot: app.screenshot())
screenshot.name = "Three independent column spinners"
screenshot.lifetime = .keepAlways
add(screenshot)
XCTAssertTrue(app.buttons["postText-post-1"].firstMatch.waitForExistence(timeout: 20))
XCTAssertTrue(feeds.firstMatch.waitForNonExistence(timeout: 3))
XCTAssertTrue(notifications.exists)
XCTAssertTrue(app.buttons["notificationPost-notification-1"].waitForExistence(timeout: 25))
XCTAssertTrue(notifications.waitForNonExistence(timeout: 3))
}
func testPostActionAccessibilityCounts() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
let like = app.buttons["Like"].firstMatch
XCTAssertTrue(like.waitForExistence(timeout: 10))
XCTAssertEqual(like.value as? String, "18 likes")
XCTAssertEqual(app.buttons["Repost"].firstMatch.value as? String, "3 reposts")
like.tap()
let unlike = app.buttons["Unlike"].firstMatch
XCTAssertTrue(unlike.waitForExistence(timeout: 5))
XCTAssertEqual(unlike.value as? String, "19 likes")
}
}