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
223
224
225
226
import XCTest
extension OldFellaUITests {
func testComposerInsertsMentionAndKeepsTyping() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
app.buttons["New post"].tap()
let editor = app.textViews["composeTextField"]
XCTAssertTrue(editor.waitForExistence(timeout: 5))
editor.tap()
editor.typeText("Hello @ma")
let suggestion = app.buttons["mentionSuggestion-mae"]
XCTAssertTrue(suggestion.waitForExistence(timeout: 5))
let initialFrame = suggestion.frame
XCTAssertEqual(initialFrame.maxX, app.frame.maxX - 16, accuracy: 1)
editor.typeText("\n@ma")
XCTAssertTrue(suggestion.waitForExistence(timeout: 5))
XCTAssertEqual(suggestion.frame.minX, initialFrame.minX, accuracy: 1)
XCTAssertGreaterThan(suggestion.frame.minY, initialFrame.minY + 10)
XCTAssertLessThan(suggestion.frame.minY, editor.frame.minY + 100)
XCTAssertLessThan(suggestion.frame.maxY, app.keyboards.firstMatch.frame.minY)
let dropdownScreenshot = XCTAttachment(screenshot: app.screenshot())
dropdownScreenshot.name = "Mention dropdown"
dropdownScreenshot.lifetime = .keepAlways
add(dropdownScreenshot)
suggestion.tap()
XCTAssertEqual(editor.value as? String, "Hello @ma\n@mae.example ")
editor.typeText("#sky https://example.com")
XCTAssertEqual(editor.value as? String, "Hello @ma\n@mae.example #sky https://example.com")
XCTAssertFalse(app.buttons["mentionSuggestion-mae"].exists)
app.dismissComposer()
app.buttons["New post"].tap()
XCTAssertTrue(editor.waitForExistence(timeout: 5))
XCTAssertEqual(editor.value as? String, "")
}
func testComposerRetriesMentionLookupInDropdown() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-mention-failure"]
app.launch()
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
app.buttons["New post"].tap()
let editor = app.textViews["composeTextField"]
XCTAssertTrue(editor.waitForExistence(timeout: 5))
editor.tap()
editor.typeText("@ma")
let retry = app.buttons["Retry"]
XCTAssertTrue(retry.waitForExistence(timeout: 5))
XCTAssertTrue(
app.staticTexts["You are not connected to the internet. Check your connection and try again."].exists)
retry.tap()
let suggestion = app.buttons["mentionSuggestion-mae"]
XCTAssertTrue(suggestion.waitForExistence(timeout: 5))
suggestion.tap()
XCTAssertEqual(editor.value as? String, "@mae.example ")
}
func testComposerAccessibilityLabels() {
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 editor = app.textViews["composeTextField"]
XCTAssertTrue(editor.waitForExistence(timeout: 5))
XCTAssertEqual(editor.label, "Post text")
XCTAssertTrue(app.buttons["editAltText-0"].exists)
XCTAssertTrue(app.buttons["editAltText-1"].exists)
XCTAssertTrue(app.buttons["Remove image 1"].exists)
XCTAssertTrue(app.buttons["Remove image 2"].exists)
}
func testComposerEditorKeepsItsHeightWithImages() {
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.buttons["New post"].tap()
let editor = app.textViews["composeTextField"]
XCTAssertTrue(editor.waitForExistence(timeout: 5))
editor.tap()
editor.typeText("A draft with photos")
let heightWithImages = editor.frame.height
XCTAssertGreaterThanOrEqual(heightWithImages, 199)
let photo = app.buttons["editAltText-0"]
let toolbar = app.buttons["addPhotosButton"]
XCTAssertGreaterThanOrEqual(photo.frame.minY, editor.frame.maxY)
let composer = app.scrollViews["composerScrollView"]
let remove = app.buttons["Remove image 1"]
if !remove.isHittable { composer.swipeUp() }
remove.tap()
app.buttons["Remove image 1"].tap()
XCTAssertEqual(editor.frame.height, heightWithImages, accuracy: 1)
XCTAssertTrue(app.buttons["addPhotosButton"].isHittable)
XCTAssertTrue(editor.value as? String == "A draft with photos")
}
func testReplyComposerScrollsWithImagesAndKeyboardOnIPad() 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-compose-images"]
app.launch()
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
app.buttons["replyButton"].firstMatch.tap()
let editor = app.textViews["composeTextField"]
XCTAssertTrue(editor.waitForExistence(timeout: 5))
editor.tap()
editor.typeText("A reply with photos")
XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 5))
let photo = app.buttons["editAltText-0"]
XCTAssertGreaterThanOrEqual(photo.frame.minY, editor.frame.maxY)
let composer = app.scrollViews["composerScrollView"]
composer.swipeUp()
XCTAssertTrue(photo.isHittable)
XCTAssertTrue(app.buttons["addPhotosButton"].isHittable)
composer.swipeDown()
XCTAssertTrue(editor.isHittable)
XCTAssertEqual(editor.value as? String, "A reply with photos")
}
func testComposerSupportsTenPhotos() {
let app = XCUIApplication()
app.launchArguments = [
"-ui-testing", "-ui-testing-signed-in", "-ui-testing-compose-images", "-ui-testing-compose-ten-images"
]
app.launch()
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
app.buttons["New post"].tap()
XCTAssertTrue(app.textViews["composeTextField"].waitForExistence(timeout: 5))
XCTAssertEqual(app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH %@", "editAltText-")).count, 10)
XCTAssertFalse(app.buttons["addPhotosButton"].isEnabled)
app.buttons["Remove image 1"].tap()
XCTAssertTrue(app.buttons["addPhotosButton"].isEnabled)
}
func testComposerPostsVideoWithoutAltText() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-compose-video"]
app.launch()
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
app.buttons["New post"].tap()
XCTAssertTrue(app.buttons["Remove video"].waitForExistence(timeout: 5))
XCTAssertFalse(app.buttons["addPhotosButton"].isEnabled)
XCTAssertFalse(app.buttons["editAltText-0"].exists)
let post = app.buttons["publishButton"]
XCTAssertTrue(post.isEnabled)
post.tap()
XCTAssertFalse(app.alerts["Add alt text?"].exists)
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 5))
}
func testComposerShowsReplyAndQuoteText() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
let postText = app.buttons["postText-post-1"].label
app.buttons["replyButton"].firstMatch.tap()
XCTAssertTrue(app.navigationBars["Reply"].waitForExistence(timeout: 5))
let context = app.staticTexts["composeContextText-post-1"]
XCTAssertTrue(context.waitForExistence(timeout: 5))
XCTAssertFalse(context.label.isEmpty)
let replyText = context.label
XCTAssertTrue(postText.contains(replyText))
app.dismissComposer()
app.buttons["quoteButton"].firstMatch.tap()
XCTAssertTrue(app.navigationBars["Quote post"].waitForExistence(timeout: 5))
XCTAssertTrue(context.waitForExistence(timeout: 5))
XCTAssertEqual(app.staticTexts.matching(identifier: "composeContextText-post-1").count, 1)
XCTAssertEqual(context.label, replyText)
}
func testPostDetailQuoteDoesNotAddReplyContext() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-own-post"]
app.launch()
let ownID = "at://demo/app.bsky.feed.post/own123"
let ownPost = app.buttons["postText-\(ownID)"].firstMatch
XCTAssertTrue(ownPost.waitForExistence(timeout: 10))
ownPost.tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
app.buttons["quoteButton"].firstMatch.tap()
XCTAssertTrue(app.navigationBars["Quote post"].waitForExistence(timeout: 5))
XCTAssertEqual(app.staticTexts.matching(identifier: "composeContextText-\(ownID)").count, 1)
app.dismissComposer()
app.buttons["replyButton"].firstMatch.tap()
XCTAssertTrue(app.navigationBars["Reply"].waitForExistence(timeout: 5))
XCTAssertEqual(app.staticTexts.matching(identifier: "composeContextText-\(ownID)").count, 1)
app.dismissComposer()
app.navigationBars["Post"].buttons.element(boundBy: 0).tap()
let otherPost = app.buttons["postText-post-1"].firstMatch
XCTAssertTrue(otherPost.waitForExistence(timeout: 5))
otherPost.tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
app.buttons["quoteButton"].firstMatch.tap()
XCTAssertTrue(app.navigationBars["Quote post"].waitForExistence(timeout: 5))
XCTAssertEqual(app.staticTexts.matching(identifier: "composeContextText-post-1").count, 1)
}
func testPublishedPostShowsAccountAndSelectedImages() {
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 editor = app.textViews["composeTextField"]
XCTAssertTrue(editor.waitForExistence(timeout: 5))
editor.tap()
editor.typeText("A new photo")
app.buttons["publishButton"].tap()
let withoutAlt = app.buttons["Post without alt text"]
if withoutAlt.waitForExistence(timeout: 2) { withoutAlt.tap() }
XCTAssertTrue(app.staticTexts["Demo Account"].firstMatch.waitForExistence(timeout: 5))
let image = app.buttons["postImageTile-1"].firstMatch
XCTAssertTrue(image.waitForExistence(timeout: 5))
image.tap()
XCTAssertTrue(app.buttons["imageViewerClose"].waitForExistence(timeout: 5))
}
}