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
import XCTest
extension OldFellaUITests {
func testLikeViewUpdateCounts() {
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))
app.buttons["Notifications"].tap()
XCTAssertTrue(app.buttons["notificationPost-notification-1"].waitForExistence(timeout: 5))
app.tabBars.buttons["Timeline"].tap()
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 5))
func recordedViews() -> Set<String> {
let counts = app.staticTexts["viewUpdateCounts"].value as? String ?? ""
return Set(counts.split(separator: ";").compactMap { $0.split(separator: "=").first.map(String.init) })
}
let unrelatedViews = [
"RootView", "SignedInTabView", "FeedView", "NotificationsView", "PostRow-post-3",
"NotificationRow-notification-3"
]
app.buttons["Read view update counts"].tap()
let initialViews = recordedViews()
for name in unrelatedViews { XCTAssertTrue(initialViews.contains(name), "Missing initial view: \(name)") }
app.buttons["Reset view update counts"].tap()
app.buttons["Like"].firstMatch.tap()
XCTAssertTrue(app.buttons["Unlike"].firstMatch.waitForExistence(timeout: 5))
app.buttons["Read view update counts"].tap()
let counts = app.staticTexts["viewUpdateCounts"].value as? String ?? ""
let attachment = XCTAttachment(string: counts)
attachment.name = "Like action view updates"
attachment.lifetime = .keepAlways
add(attachment)
print("Like action view updates: \(counts)")
let updatedViews = recordedViews()
XCTAssertTrue(updatedViews.contains("PostRow-post-1"))
for name in unrelatedViews { XCTAssertFalse(updatedViews.contains(name), "Unrelated view updated: \(name)") }
}
func testPostShareActionsInFeedAndDetail() {
continueAfterFailure = false
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-share"]
app.launch()
let uri = "at://did:plc:sharetest/app.bsky.feed.post/abc123"
let controls = app.buttons["postControls-\(uri)"].firstMatch
XCTAssertTrue(controls.waitForExistence(timeout: 5))
controls.tap()
let share = app.buttons["Share post"].firstMatch
XCTAssertTrue(share.waitForExistence(timeout: 5))
share.tap()
let copy = app.otherElements["ActivityListView"].cells["Copy"].firstMatch
let showsCopy = copy.waitForExistence(timeout: 15)
let screenshot = XCTAttachment(screenshot: app.screenshot())
screenshot.name = "Post share sheet"
screenshot.lifetime = .keepAlways
add(screenshot)
XCTAssertTrue(showsCopy, app.debugDescription)
copy.tap()
XCTAssertTrue(copy.waitForNonExistence(timeout: 5))
app.buttons["postText-\(uri)"].firstMatch.tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
controls.tap()
let detailShare = app.buttons["Share post"].firstMatch
XCTAssertTrue(detailShare.waitForExistence(timeout: 5))
detailShare.tap()
XCTAssertTrue(
app.otherElements["ActivityListView"].waitForExistence(timeout: 5)
|| copy.waitForExistence(timeout: 5))
}
func testGeneratedAltTextOpensEditorAndCanBeEdited() {
let app = XCUIApplication()
app.launchArguments = [
"-ui-testing", "-ui-testing-signed-in", "-ui-testing-compose-images", "-ui-testing-alt-success"
]
app.launch()
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
app.tabBars.buttons["New post"].tap()
let attachment = app.buttons["editAltText-0"]
XCTAssertTrue(attachment.waitForExistence(timeout: 5))
attachment.tap()
XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
let editor = app.textViews["altTextEditor"]
XCTAssertTrue(editor.waitForExistence(timeout: 5))
let generate = app.buttons["generateAltText-0"]
XCTAssertTrue(generate.waitForExistence(timeout: 5))
generate.tap()
XCTAssertTrue(app.navigationBars["Alt text editor"].exists)
let generatedText = NSPredicate(format: "value CONTAINS %@", "A generated description")
expectation(for: generatedText, evaluatedWith: editor)
waitForExpectations(timeout: 5)
app.navigationBars["Alt text editor"].buttons["Cancel"].tap()
attachment.tap()
XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
let editableText = app.textViews["altTextEditor"]
XCTAssertTrue(editableText.waitForExistence(timeout: 5))
app.buttons["generateAltText-0"].tap()
let regeneratedText = NSPredicate(format: "value CONTAINS %@", "A generated description")
expectation(for: regeneratedText, evaluatedWith: editableText)
waitForExpectations(timeout: 5)
editableText.tap()
editableText.typeText(" edited")
app.buttons["Save"].tap()
attachment.tap()
XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
XCTAssertTrue((app.textViews["altTextEditor"].value as? String ?? "").contains("edited"))
app.navigationBars["Alt text editor"].buttons["Cancel"].tap()
}
func testManualAltTextCanBeCancelledOrSaved() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-compose-images"]
app.launch()
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
app.tabBars.buttons["New post"].tap()
let attachment = app.buttons["editAltText-0"]
XCTAssertTrue(attachment.waitForExistence(timeout: 5))
attachment.tap()
XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
let editor = app.textViews["altTextEditor"]
XCTAssertTrue(editor.waitForExistence(timeout: 5))
let originalText = editor.value as? String ?? ""
let counter = app.staticTexts["altTextCharacterCount"]
XCTAssertTrue(counter.waitForExistence(timeout: 5))
XCTAssertTrue(counter.label.hasPrefix("7 of "))
editor.tap()
editor.typeText(" changed")
app.navigationBars["Alt text editor"].buttons["Cancel"].tap()
attachment.tap()
XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
let cancelledEditor = app.textViews["altTextEditor"]
XCTAssertTrue(cancelledEditor.waitForExistence(timeout: 5))
XCTAssertEqual(cancelledEditor.value as? String, originalText)
cancelledEditor.tap()
cancelledEditor.typeText(" saved")
app.buttons["Save"].tap()
attachment.tap()
XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
XCTAssertTrue((app.textViews["altTextEditor"].value as? String ?? "").contains("saved"))
app.navigationBars["Alt text editor"].buttons["Cancel"].tap()
}
func testDelayedAltTextCanBeReviewed() {
let app = XCUIApplication()
app.launchArguments = [
"-ui-testing", "-ui-testing-signed-in", "-ui-testing-compose-images", "-ui-testing-alt-delayed"
]
app.launch()
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
app.tabBars.buttons["New post"].tap()
app.buttons["editAltText-0"].tap()
XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
let editor = app.textViews["altTextEditor"]
XCTAssertTrue(editor.waitForExistence(timeout: 5))
let generate = app.buttons["generateAltText-0"]
XCTAssertTrue(generate.waitForExistence(timeout: 5))
generate.tap()
XCTAssertTrue(app.buttons["stopGeneratingAltTextButton"].waitForExistence(timeout: 2))
XCTAssertFalse(app.buttons["publishButton"].isEnabled)
XCTAssertTrue(app.navigationBars["Alt text editor"].exists)
XCTAssertTrue(editor.waitForExistence(timeout: 5))
let generatedText = NSPredicate(format: "value == %@", "A delayed description")
expectation(for: generatedText, evaluatedWith: editor)
waitForExpectations(timeout: 10)
app.buttons["Save"].tap()
app.buttons["editAltText-0"].tap()
XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
XCTAssertEqual(app.textViews["altTextEditor"].value as? String, "A delayed description")
app.navigationBars["Alt text editor"].buttons["Cancel"].tap()
}
func testCancelDelayedAltTextKeepsComposerUsable() {
let app = XCUIApplication()
app.launchArguments = [
"-ui-testing", "-ui-testing-signed-in", "-ui-testing-compose-images", "-ui-testing-alt-delayed"
]
app.launch()
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
app.tabBars.buttons["New post"].tap()
let attachment = app.buttons["editAltText-0"]
XCTAssertTrue(attachment.waitForExistence(timeout: 5))
attachment.tap()
XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
let editor = app.textViews["altTextEditor"]
XCTAssertTrue(editor.waitForExistence(timeout: 5))
let generate = app.buttons["generateAltText-0"]
XCTAssertTrue(generate.waitForExistence(timeout: 5))
let stop = app.buttons["stopGeneratingAltTextButton"]
generate.tap()
XCTAssertTrue(stop.waitForExistence(timeout: 2))
XCTAssertFalse(generate.exists)
XCTAssertTrue(app.navigationBars["Alt text editor"].exists)
stop.tap()
XCTAssertTrue(generate.waitForExistence(timeout: 2))
XCTAssertFalse(stop.exists)
XCTAssertTrue(app.navigationBars["Alt text editor"].exists)
XCTAssertEqual(editor.value as? String, "A photo")
app.navigationBars["Alt text editor"].buttons["Cancel"].tap()
XCTAssertTrue(app.buttons["publishButton"].isEnabled)
XCTAssertTrue(app.textViews["composeTextField"].isEnabled)
attachment.tap()
XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
XCTAssertEqual(app.textViews["altTextEditor"].value as? String, "A photo")
app.buttons["generateAltText-0"].tap()
let generatedText = NSPredicate(format: "value == %@", "A delayed description")
expectation(for: generatedText, evaluatedWith: app.textViews["altTextEditor"])
waitForExpectations(timeout: 10)
XCTAssertFalse(app.alerts["Alt text unavailable"].exists)
app.buttons["Save"].tap()
attachment.tap()
XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
XCTAssertEqual(app.textViews["altTextEditor"].value as? String, "A delayed description")
app.navigationBars["Alt text editor"].buttons["Cancel"].tap()
}
}