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
import XCTest
final class ShareExtensionTests: XCTestCase {
private func openShareComposer(modes: [String] = []) -> XCUIApplication {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-share-target"]
app.launchArguments.append(contentsOf: modes)
app.launch()
let launch = app.buttons["shareTestLaunch"]
XCTAssertTrue(launch.waitForExistence(timeout: 10))
launch.tap()
let target = app.cells.matching(NSPredicate(format: "label == %@", "Old Fella")).firstMatch
if !target.waitForExistence(timeout: 5) {
let more = app.cells.matching(NSPredicate(format: "label == %@", "More")).firstMatch
if !more.isHittable, app.scrollViews.firstMatch.exists {
app.scrollViews.firstMatch.swipeLeft()
}
if more.waitForExistence(timeout: 3), more.isHittable { more.tap() }
}
XCTAssertTrue(target.waitForExistence(timeout: 10))
target.tap()
XCTAssertTrue(app.textViews["composeTextField"].firstMatch.waitForExistence(timeout: 10))
XCTAssertTrue(app.buttons["addPhotosButton"].exists)
return app
}
func testPostsSharedLinkFromShareSheet() {
let app = openShareComposer()
let editor = app.textViews["composeTextField"].firstMatch
XCTAssertEqual(editor.value as? String, "https://example.com/shared-article")
editor.coordinate(withNormalizedOffset: CGVector(dx: 0.98, dy: 0.05)).tap()
editor.typeText(" An example")
let post = app.buttons["publishButton"].firstMatch
XCTAssertTrue(post.isEnabled)
post.tap()
let result = app.staticTexts["shareTestResult"]
let posted = NSPredicate(format: "label CONTAINS %@", "https://example.com/shared-article An example")
expectation(for: posted, evaluatedWith: result)
waitForExpectations(timeout: 10)
}
func testPostsSharedPhotoWithAltText() {
let app = openShareComposer(modes: ["-ui-testing-share-photo"])
let photo = app.buttons["Edit alt text for image 1"].firstMatch
XCTAssertTrue(photo.waitForExistence(timeout: 5))
photo.tap()
let editor = app.textViews["altTextEditor"].firstMatch
XCTAssertTrue(editor.waitForExistence(timeout: 5))
XCTAssertTrue(app.images["Photo"].exists)
XCTAssertTrue(editor.isHittable)
editor.tap()
editor.typeText("A mountain at sunrise")
app.buttons["Save"].tap()
XCTAssertTrue(photo.waitForExistence(timeout: 5))
photo.tap()
XCTAssertTrue(editor.waitForExistence(timeout: 5))
XCTAssertEqual(editor.value as? String, "A mountain at sunrise")
app.buttons["Save"].tap()
let post = app.buttons["publishButton"].firstMatch
XCTAssertTrue(post.waitForExistence(timeout: 5))
XCTAssertTrue(post.isEnabled)
post.tap()
let result = app.staticTexts["shareTestResult"]
let posted = NSPredicate(format: "label == %@", "Photos: 1. Alt text: A mountain at sunrise")
expectation(for: posted, evaluatedWith: result)
waitForExpectations(timeout: 10)
}
func testSharedComposerGeneratesAndReviewsAltText() {
let app = openShareComposer(modes: ["-ui-testing-share-photo", "-ui-testing-share-alt-success"])
let photo = app.buttons["editAltText-0"]
XCTAssertTrue(photo.waitForExistence(timeout: 5))
XCTAssertFalse(app.staticTexts["Add alt text"].exists)
photo.tap()
let editor = app.textViews["altTextEditor"].firstMatch
XCTAssertTrue(editor.waitForExistence(timeout: 5))
let generate = app.buttons["generateAltText-0"]
XCTAssertTrue(generate.waitForExistence(timeout: 5))
generate.tap()
expectation(for: NSPredicate(format: "value == %@", "A generated description"), evaluatedWith: editor)
waitForExpectations(timeout: 5)
app.navigationBars["Alt text editor"].buttons["Cancel"].tap()
photo.tap()
XCTAssertTrue(editor.waitForExistence(timeout: 5))
XCTAssertNotEqual(editor.value as? String, "A generated description")
generate.tap()
expectation(for: NSPredicate(format: "value == %@", "A generated description"), evaluatedWith: editor)
waitForExpectations(timeout: 5)
app.buttons["Save"].tap()
photo.tap()
XCTAssertTrue(editor.waitForExistence(timeout: 5))
XCTAssertEqual(editor.value as? String, "A generated description")
app.buttons["Save"].tap()
app.buttons["publishButton"].tap()
let result = app.staticTexts["shareTestResult"]
let posted = NSPredicate(format: "label == %@", "Photos: 1. Alt text: A generated description")
expectation(for: posted, evaluatedWith: result)
waitForExpectations(timeout: 10)
}
func testSharedComposerCanStopGeneratingAltText() {
let app = openShareComposer(modes: ["-ui-testing-share-photo", "-ui-testing-share-alt-delayed"])
app.buttons["editAltText-0"].tap()
let editor = app.textViews["altTextEditor"].firstMatch
XCTAssertTrue(editor.waitForExistence(timeout: 5))
let generate = app.buttons["generateAltText-0"]
XCTAssertTrue(generate.waitForExistence(timeout: 5))
generate.tap()
let stop = app.buttons["stopGeneratingAltTextButton"]
XCTAssertTrue(stop.waitForExistence(timeout: 2))
stop.tap()
XCTAssertTrue(generate.waitForExistence(timeout: 2))
XCTAssertNotEqual(editor.value as? String, "A delayed description")
app.navigationBars["Alt text editor"].buttons["Cancel"].tap()
XCTAssertTrue(app.buttons["publishButton"].isEnabled)
}
func testPostsSharedVideoWithoutAltText() {
let app = openShareComposer(modes: ["-ui-testing-share-video"])
XCTAssertTrue(app.buttons["Remove video"].firstMatch.waitForExistence(timeout: 5))
XCTAssertFalse(app.buttons["Edit alt text for image 1"].exists)
let post = app.buttons["publishButton"].firstMatch
XCTAssertTrue(post.isEnabled)
post.tap()
XCTAssertFalse(app.alerts["Add alt text?"].exists)
let result = app.staticTexts["shareTestResult"]
expectation(for: NSPredicate(format: "label == %@", "Video posted"), evaluatedWith: result)
waitForExpectations(timeout: 15)
}
func testKnownFailureKeepsShareComposerReadyToRetry() {
let app = openShareComposer(modes: ["-ui-testing-share-failure"])
let post = app.buttons["publishButton"].firstMatch
XCTAssertTrue(post.isEnabled)
post.tap()
let alert = app.alerts["Post not sent"]
XCTAssertTrue(alert.waitForExistence(timeout: 5))
XCTAssertTrue(alert.staticTexts["The post was not sent. Try again."].exists)
alert.buttons["OK"].tap()
XCTAssertTrue(post.isEnabled)
XCTAssertTrue(app.textViews["composeTextField"].exists)
}
func testUnknownOutcomePreventsRetry() {
let app = openShareComposer(modes: ["-ui-testing-share-unknown"])
let post = app.buttons["publishButton"].firstMatch
XCTAssertTrue(post.isEnabled)
post.tap()
let alert = app.alerts["Post status unknown"]
XCTAssertTrue(alert.waitForExistence(timeout: 5))
XCTAssertTrue(
alert.staticTexts.matching(NSPredicate(format: "label CONTAINS %@", "Bluesky may have received this post"))
.firstMatch.exists)
alert.buttons["OK"].tap()
XCTAssertFalse(post.isEnabled)
}
}