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
import XCTest
final class PostTouchTargetTests: XCTestCase {
private let postID = "at://mae.example/app.bsky.feed.post/tap-target"
func testCardSpacesOpenShortPostExactlyOnce() {
let app = launch()
let text = app.buttons["postText-\(postID)"].firstMatch
XCTAssertTrue(text.waitForExistence(timeout: 10))
attachScreenshot(app, name: "Post card tap targets")
let row = app.cells.containing(.button, identifier: "postText-\(postID)").firstMatch
let profile = row.buttons["profileLink-mae"]
let like = row.buttons["Like"]
let repost = row.buttons["Repost"]
let reply = row.buttons["replyButton"]
let quote = row.buttons["quoteButton"]
let controls = row.buttons["postControls-\(postID)"]
let timestamp = row.staticTexts["postTimestamp-\(postID)"]
let points = [
CGPoint(x: text.frame.maxX - 8, y: text.frame.midY),
CGPoint(x: text.frame.minX + 5, y: text.frame.midY),
CGPoint(x: (profile.frame.maxX + timestamp.frame.minX) / 2, y: profile.frame.midY),
CGPoint(x: text.frame.minX + 12, y: (profile.frame.maxY + text.frame.minY) / 2),
CGPoint(x: text.frame.minX + 12, y: (text.frame.maxY + like.frame.minY) / 2),
CGPoint(x: (like.frame.maxX + repost.frame.minX) / 2, y: like.frame.midY),
CGPoint(x: (repost.frame.maxX + reply.frame.minX) / 2, y: like.frame.midY),
CGPoint(x: (reply.frame.maxX + quote.frame.minX) / 2, y: like.frame.midY),
CGPoint(x: (quote.frame.maxX + controls.frame.minX) / 2, y: like.frame.midY),
CGPoint(x: row.frame.minX + 5, y: text.frame.midY),
CGPoint(x: row.frame.midX, y: row.frame.minY + 5),
CGPoint(x: row.frame.midX, y: like.frame.maxY + 8)
]
for point in points {
assertOpensPost(in: app, at: point)
}
}
func testSpaceBesideMultilineTextOpensPost() {
let app = launch(kind: "multiline")
let text = app.buttons["postText-\(postID)"].firstMatch
XCTAssertTrue(text.waitForExistence(timeout: 10))
for offset in [0.15, 0.5, 0.85] {
let point = CGPoint(x: text.frame.maxX - 8, y: text.frame.minY + text.frame.height * offset)
assertOpensPost(in: app, at: point)
}
}
func testImageOnlyPostHasAccessibleNavigationAndMediaKeepsItsAction() {
let app = launch(kind: "image")
let image = app.buttons["Attached image"].firstMatch
XCTAssertTrue(image.waitForExistence(timeout: 10), app.debugDescription)
attachScreenshot(app, name: "Image-only post tap targets")
XCTAssertTrue(app.buttons["openPost-\(postID)"].firstMatch.exists)
let row = app.cells.containing(.button, identifier: "openPost-\(postID)").firstMatch
assertOpensPost(in: app, at: CGPoint(x: row.frame.minX + 5, y: image.frame.midY))
let like = row.buttons["Like"]
assertOpensPost(in: app, at: CGPoint(x: row.frame.midX, y: (image.frame.maxY + like.frame.minY) / 2))
image.tap()
let close = app.buttons["imageViewerClose"]
XCTAssertTrue(close.waitForExistence(timeout: 5))
close.tap()
XCTAssertTrue(app.navigationBars["Following"].exists)
XCTAssertFalse(app.navigationBars["Post"].exists)
}
func testAvatarNameAndHandleKeepProfileTargets() {
let app = launch()
let profile = app.buttons["profileLink-mae"].firstMatch
XCTAssertTrue(profile.waitForExistence(timeout: 10))
for offset in [CGVector(dx: 0.1, dy: 0.5), CGVector(dx: 0.7, dy: 0.2), CGVector(dx: 0.7, dy: 0.8)] {
profile.coordinate(withNormalizedOffset: offset).tap()
XCTAssertTrue(app.staticTexts["profileDisplayName"].waitForExistence(timeout: 5))
XCTAssertEqual(app.staticTexts["profileDisplayName"].label, "Mae Rivers")
XCTAssertTrue(app.navigationBars.buttons["Following"].exists)
app.navigationBars.buttons["Following"].tap()
XCTAssertTrue(app.navigationBars["Following"].exists)
}
}
func testActionsKeepTheirOwnTargets() {
let app = launch()
let row = app.cells.containing(.button, identifier: "postText-\(postID)").firstMatch
XCTAssertTrue(row.waitForExistence(timeout: 10))
row.buttons["Like"].coordinate(withNormalizedOffset: CGVector(dx: 0.9, dy: 0.5)).tap()
XCTAssertTrue(row.buttons["Unlike"].waitForExistence(timeout: 5))
row.buttons["Repost"].coordinate(withNormalizedOffset: CGVector(dx: 0.1, dy: 0.5)).tap()
XCTAssertTrue(row.buttons["Undo repost"].waitForExistence(timeout: 5))
for identifier in ["replyButton", "quoteButton"] {
row.buttons[identifier].tap()
app.dismissComposer()
XCTAssertTrue(app.navigationBars["Following"].exists)
}
row.buttons["postControls-\(postID)"].tap()
app.buttons["Share post"].tap()
let copy = app.otherElements["ActivityListView"].cells["Copy"].firstMatch
XCTAssertTrue(copy.waitForExistence(timeout: 5))
copy.tap()
XCTAssertTrue(copy.waitForNonExistence(timeout: 5))
row.buttons["postControls-\(postID)"].tap()
app.buttons["Moderation"].tap()
XCTAssertTrue(app.buttons["Mute account"].waitForExistence(timeout: 5))
XCTAssertFalse(app.navigationBars["Post"].exists)
}
func testMentionsLinksAndQuotesKeepTheirDestinations() {
let app = launch(kind: "links")
let text = app.buttons["postText-\(postID)"].firstMatch
XCTAssertTrue(text.waitForExistence(timeout: 10))
let mention = text.links.matching(NSPredicate(format: "label CONTAINS %@", "@alex.example")).firstMatch
mention.tap()
XCTAssertTrue(app.staticTexts["profileDisplayName"].waitForExistence(timeout: 5))
XCTAssertEqual(app.staticTexts["profileDisplayName"].label, "Alex Kim")
XCTAssertTrue(app.navigationBars.buttons["Following"].exists)
app.navigationBars.buttons["Following"].tap()
let link = text.links.matching(NSPredicate(format: "label CONTAINS %@", "https://example.invalid/article"))
.firstMatch
link.tap()
XCTAssertTrue(app.buttons["Close"].waitForExistence(timeout: 5))
app.buttons["Close"].tap()
XCTAssertTrue(app.navigationBars["Following"].exists)
app.buttons["quotedPostLink"].firstMatch.tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
XCTAssertTrue(app.buttons["postText-post-2"].firstMatch.exists)
XCTAssertTrue(app.navigationBars.buttons["Following"].exists)
}
func testSelectedDetailPostDoesNotOpenItselfAgain() {
let app = launch()
let text = app.buttons["postText-\(postID)"].firstMatch
XCTAssertTrue(text.waitForExistence(timeout: 10))
text.coordinate(withNormalizedOffset: CGVector(dx: 0.1, dy: 0.5)).tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
text.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap()
text.coordinate(withNormalizedOffset: CGVector(dx: 0.1, dy: 0.5)).tap()
XCTAssertTrue(app.navigationBars.buttons["Following"].exists)
app.navigationBars.buttons["Following"].tap()
XCTAssertTrue(app.navigationBars["Following"].exists)
}
func testLargeTextKeepsThePostTarget() {
let app = launch(kind: "multiline", contentSize: "UICTContentSizeCategoryAccessibilityXXXL")
let text = app.buttons["postText-\(postID)"].firstMatch
XCTAssertTrue(text.waitForExistence(timeout: 10))
XCTAssertGreaterThan(text.frame.height, 90)
attachScreenshot(app, name: "Post targets with large text")
assertOpensPost(in: app, at: CGPoint(x: text.frame.maxX - 8, y: text.frame.midY))
}
func testThreadReplyPaddingOpensTheReply() {
continueAfterFailure = false
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
let root = app.buttons["postText-post-1"].firstMatch
XCTAssertTrue(root.waitForExistence(timeout: 10))
root.coordinate(withNormalizedOffset: CGVector(dx: 0.1, dy: 0.2)).tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
let reply = app.buttons["postText-post-2"].firstMatch
XCTAssertTrue(reply.waitForExistence(timeout: 5))
let point = CGPoint(x: reply.frame.minX - 8, y: reply.frame.midY)
app.coordinate(withNormalizedOffset: .zero).withOffset(CGVector(dx: point.x, dy: point.y)).tap()
XCTAssertTrue(app.navigationBars.buttons["Post"].waitForExistence(timeout: 5))
XCTAssertFalse(app.buttons["openPost-post-2"].exists)
XCTAssertTrue(app.buttons["openPost-post-1"].exists)
app.navigationBars.buttons["Post"].tap()
XCTAssertTrue(app.navigationBars.buttons["Following"].exists)
}
func testScrollingAcrossMediaDoesNotOpenPost() {
let app = launch(kind: "image")
let image = app.buttons["Attached image"].firstMatch
XCTAssertTrue(image.waitForExistence(timeout: 10))
let start = image.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.8))
start.press(forDuration: 0.01, thenDragTo: start.withOffset(CGVector(dx: 0, dy: -180)))
XCTAssertTrue(app.navigationBars["Following"].exists)
XCTAssertFalse(app.navigationBars["Post"].exists)
XCTAssertFalse(app.buttons["imageViewerClose"].exists)
}
private func assertOpensPost(in app: XCUIApplication, at point: CGPoint) {
app.coordinate(withNormalizedOffset: .zero).withOffset(CGVector(dx: point.x, dy: point.y)).tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
XCTAssertTrue(
app.buttons["postText-\(postID)"].firstMatch.exists || app.buttons["Attached image"].firstMatch.exists)
XCTAssertTrue(app.navigationBars.buttons["Following"].exists)
app.navigationBars.buttons["Following"].tap()
XCTAssertTrue(app.navigationBars["Following"].exists)
}
private func attachScreenshot(_ app: XCUIApplication, name: String) {
let attachment = XCTAttachment(screenshot: app.screenshot())
attachment.name = name
attachment.lifetime = .keepAlways
add(attachment)
}
private func launch(kind: String = "short", contentSize: String? = nil) -> XCUIApplication {
continueAfterFailure = false
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-post-targets"]
if let contentSize {
app.launchArguments += ["-UIPreferredContentSizeCategoryName", contentSize]
}
app.launchEnvironment["OLDFELLA_UI_TEST_POST_KIND"] = kind
app.launchEnvironment["OLDFELLA_UI_TEST_LINK_HOST"] = "example.invalid"
app.launch()
return app
}
}